How Do You Test Code That Uses now()? cover image

How Do You Test Code That Uses now()?

Scott Keck-Warren • November 6, 2026

Hook / opening beat

Why now() Breaks Tests

public function isExpired(): bool
{
    return $this->expires_at < now();
}

Freezing the Clock in Laravel

Injecting a Clock Instead

The Bugs Freezing Time Lets You Catch

Closing beat

Notes

AI notice:

The outline for this post was generated via AI, then I wrote the prose and ran it through Grammarly