Freek has created
spatie/test-time, a package to easily freeze/rewind/advance time in PHP.
Imagine you’re building that your app can notify your user, but you don’t want to send more than one notification in a timeframe of five seconds. How are you going to test the time aspect? Do you have to create a test that takes five minutes?
Luckily the answer is “no”. If you’re using the popular Carbon library, you can set the value that the library considers “now”
The package provides a few convenience methods around Carbon’s
// time will not progress anymore TestTime::freeze(); // Advance one minute TestTime::addMinute(); // Rewind 5 hours TestTime::subHours(5);