Watch the clock
summary
Argues that exporting time behind a Clock interface (PSR/FIG) and using DateTimeImmutable fixes flaky time tests by replacing calls to time() with injection of a SystemClock and, in tests, a FrozenClock (often via an anonymous class). Shows building a current-datetime factory, swapping it for a clock interface, and using Symfony and other existing implementations so tests become deterministic, interop increases, and multiple conflicting clock libs disappear from projects.
AI-written summary · about
chapters (15)
- 0:00Clock interfaces
- 1:32Clock interfaces in PHP
- 2:35Testing time-dependent code
- 5:07Injecting time for testability
- 9:26Moving time dependency up
- 10:09Datetime factory
- 11:56Abstracting with clock interface
- 14:27Frozen clock for tests
- 15:31What is the PHP-FIG and why it matters
- 18:00Birth of the clock PSR
- 20:52Challenges in PSR finalization
- 24:05Time zones and immutable objects
- 26:15Using clock interface in practice
- 28:25Benefits of clock implementations
- 29:34Q&A on clock testing








