scyzoryck / clock
dev-master
2018-04-06 06:00 UTC
Requires
- php: ~7.0
Requires (Dev)
- phpunit/phpunit: ^7.0
This package is not auto-updated.
Last update: 2025-04-20 05:59:23 UTC
README
Did you ever wonder how to control your time? This library is created for you!
It provides a Clock
interface that allows you to create current datetime in a controlled way!
Installing
composer require scyzoryck/clock
Clock types
The provided implementations of Clock
are:
RealTimeClock
- always returns the real time.StoppedClock
- it always returns times that you have provided in constructor! Useful for tests.RunningClock
- as the previous one it use the time from constructor, but this time is running.TransactionalClock
- wrapper, that allows you to stop the time for some long running operations.
Adapters
The method Clock::now()
returns an instance of \DateTimeImmutable
. You can use adapters if you need some others DateTime objects.
MutableDateTimeClock
- creates an instance of\DateTime
Running Unit Tests
composer install php vendor/bin/phpunit