lcobucci/clock
Clock abstraction for PHP to decouple your code from DateTimeImmutable instantiation. Depend on the Clock interface and use SystemClock for real time (with timezone support) or FrozenClock for deterministic, test-friendly time in unit tests.
DateTimeImmutable with a mockable Clock interface. Critical for CI/CD pipelines and regression testing.SystemClock::fromUTC()).new DateTime() calls in monoliths.Adopt if:
DateTimeImmutable for business logic (e.g., deadlines, retries, caching).Time::now() in tests).Look elsewhere if:
jest.useFakeTimers() or luxon.DateTime is faster.lcobucci/clock-adjust or implement custom logic.For Executives: *"This is a 10-minute fix to eliminate a major source of test flakiness. By abstracting time behind an interface, we can:
date('Y-m-d') calls with a single, testable source of truth.DateTimeImmutable with zero runtime impact in production."*For Engineers: *"This is the gold standard for time mocking in PHP. Key wins:
Time::now() with FrozenClock for reproducible tests.ClockInterface).composer require lcobucci/clock.new DateTimeImmutable() with SystemClock::fromUTC() in services.Clock into classes and use FrozenClock in tests.
Example:// Before (flaky)
if ($user->expiresAt > new DateTimeImmutable()) { ... }
// After (testable)
if ($user->expiresAt > $clock->now()) { ... }
Tradeoff: Minimal boilerplate for 100% test reliability."*
How can I help you explore Laravel packages today?