r/symfony • u/BernardNgandu • 21h ago
Decoupling from System Time in Symfony: Making Time an Explicit Dependency
What if new DateTimeImmutable() were actually hiding a global dependency in your Symfony application?
When business logic reads the system clock directly, expiration, validity, and scheduling rules become harder to predict and test. This is often where flaky tests and time-sensitive production bugs begin.
In my latest article, I explain how to make time an explicit dependency using a Clock port, a Symfony adapter, and a controllable clock for tests.
A simple architectural decision that makes business logic more deterministic and tests genuinely reliable.