Watch the clock
summary
Explains a concrete design and the code pattern that makes time testable: a PSR-20 clock interface with a production SystemClock and a test FrozenClock, returning DateTimeImmutable from now(), injected as an interface and created by a small factory. Shows the exact constructor and test setup, how to avoid repeated time() calls, why time zones belong to values not the interface, and that the PSR is published and interoperable in real projects.
AI-written summary · about
chapters (23)
- 0:00Introduction
- 0:57Why clocks matter
- 1:40Code quality best practices
- 2:23Filtering future items
- 3:49Testing pure functions
- 5:36Constructor injection
- 7:01First test case
- 8:05Fixing non-deterministic time
- 8:48Type safety with DateTimeImmutable
- 10:36Testing real time challenges
- 11:41Factory pattern for time
- 13:48Testing with fixed dates
- 15:15Clock interface
- 16:40System and test clocks
- 18:05Clock interface summary
- 19:11Why PHP-FIG matters
- 21:23Journey to PSR-20
- 23:29Interface design debate
- 24:11Time zones and Now
- 26:18Time zone value objects
- 27:22Clock implementations
- 28:47PSR-20 approval delays
- 29:30Q&A
related talks
42mStrategies for Dealing with Date and Time in Test and Production Code
45mUnit testing patterns for Concurrent code
31mTesting Time (and other asynchronous code)
43mLimits of testing
44mTesting the untestable - patterns and use cases analysis
01h 19mYou Can't Test This? Hammertime!
38mTesting and Time and Concurrency With Rx.NET Schedulers
21mTesting against time in JavaScript applications
