Provides a simple abstraction of a clock, following the suggestion by Martin Fowler.
Run
$ composer require ergebnis/clockCreate a new system clock and use it to determine the current time:
<?php
use Ergebnis\Clock;
$timeZone = new \DateTimeZone('Europe/Berlin');
$clock = new Clock\SystemClock($timeZone);
$now = $clock->now();Create a new frozen clock and use it in tests:
<?php
use Ergebnis\Clock;
$now = new \DateTimeImmutable();
$clock = new Clock\FrozenClock($now);
sleep(5);
$stillNow = $clock->now();Alternatively, create a new frozen clock by freezing a system clock:
<?php
use Ergebnis\Clock;
$timeZone = new \DateTimeZone('Europe/Berlin');
$clock = new Clock\SystemClock($timeZone);
$frozenClock = $clock->freeze();
$now = $clock->now();
sleep(5);
$stillNow = $clock->now();Please have a look at CHANGELOG.md.
Please have a look at CONTRIBUTING.md.
Please have a look at CODE_OF_CONDUCT.md.
This package is licensed using the MIT License.
Please have a look at LICENSE.md.
This project is inspired by lcobucci/clock (originally licensed under MIT by Luís Cobucci).
📬 Subscribe to my list, and I will occasionally send you an email to let you know what I am working on.