Download the PHP package mcustiel/mockable-datetime without Composer

On this page you can find all versions of the php package mcustiel/mockable-datetime. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package mockable-datetime

Mockable DateTime

What is it

Mockable DateTime is a library written in PHP that allows developers to mock the dates for unit tests. There are sometimes in which you need to verify that an action was executed with certain parameters, and one of them is a date or a time (generally obtained with date() or time() built-in functions) and is very difficult to ensure it will have a certain value at the time of the verification. Mockable DateTime solves this problem by giving the developer a way to obtain PHP's built-in DateTime class in a way, that the value it returns can be mocked from unit tests without the need of injecting DateTime as a dependency.

Build Status Scrutinizer Code Quality Code Coverage

Installation

Composer:

How to use it?

In your code

Everytime you need to get system's date just use Mockable DateTime:

Also arguments can be passed to create the DateTime object:

As you can see in the example, I'm not using PHP's \DateTime directly. Instead I use Mockable DateTime to create instances of PHP's \DateTime.

Then you have to test this, and assert that insert method was called with some specific date as an argument. For the example I'll use PHPUnit.

That's it. For it to work the code and tests should be executed in the same environment (it won't work if you execute tests again a running instance of your webservice), but it should be enough for unit and some low level functional tests.

DateTime methods:

void setFixed(\DateTime $dateTime)

This method makes all instances of Mockable DateTime to always return the date and time specified by the $dateTime parameter.

void setOffset(\DateTime $dateTime)

This method makes all instances of Mockable DateTime to always return a date and time with offset equal to the specified by the $dateTime parameter. The time starts to run from the moment of the call to this method. So if you set an offset equal to '2005-05-05 01:00:00' and sleep for 5 seconds, a new call to create a \DateTime will return one with '2005-05-05 01:00:05' set.

void setSystem()

This method makes all instances of Mockable DateTime to always return current system time (default behaviour).

\DateTime newPhpDateTime($time = 'now', \DateTimeZone $timeZone = null)

Creates a new instance of PHP's \DateTime class based in the config of Mockable DateTime.

\DateTimeImmutable newImmutablePhpDateTime($time = 'now', \DateTimeZone $timeZone = null)

Creates a new instance of PHP's \DateTimeImmutable class based in the config of Mockable DateTime.


All versions of mockable-datetime with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mcustiel/mockable-datetime contains the following files

Loading the files please wait ....