FAQ
-
What clocks does this package provide?
FastForward Clock provides two PSR-20 compliant implementations:
SystemClock: Returns the current system time (ideal for production)FrozenClock: Returns a fixed time (ideal for testing)
-
Which clock should I use in production?
Use
SystemClockor requestPsr\Clock\ClockInterfacefrom the container. -
Which interface should application services depend on?
Prefer
Psr\Clock\ClockInterfaceso the service contract remains portable across different clock implementations. -
How do I freeze time in tests?
Use
FrozenClockdirectly, or register it via anArrayServiceProviderbeforeClockServiceProvider. -
Can I use this package without Fast Forward Container?
Yes! Both
SystemClockandFrozenClockare standalone classes that can be instantiated directly:$clock = new FastForward\Clock\FrozenClock('2026-04-07 10:00:00'); -
Does this package require Fast Forward Container?
No. The clocks work independently. The service provider is optional for container integration.
-
How do I set a specific timezone?
Pass a timezone string or
DateTimeZoneinstance to theSystemClockconstructor:$clock = new SystemClock('America/Sao_Paulo'); -
Can I create my own clock implementation?
Yes. Both clocks implement
Psr\Clock\ClockInterface, so you can create any implementation that satisfies this interface. -
What's the difference between FrozenClock and MockClock?
FrozenClockis a simple, standalone class that always returns the same time. It's perfect for most testing scenarios. If you need more advanced features like mockingsleep()calls, consider using Symfony'sMockClockdirectly. -
Why use this package instead of creating my own clock?
This package provides well-tested, PSR-20 compliant implementations that work seamlessly with Fast Forward Container and any PSR-11 compatible container. It also provides the service provider for easy integration.