Time traveling is coming to Laravel 8

Time traveling is coming to Laravel 8

Another small helper feature coming to Laravel 8 is the ability to fluently time travel in your tests. This will allow you to easily test for things like what happens when a free trial ends, or a next billing date, etc. Here is a quick example that @enunomaduro shared on Twitter showing how you can use this new feature:

// Travel forward five minutes
$this->get($route)->assertSee('Created 5 mins ago');

// Travel forward one year
$this->get($route)->assertSee('Created 1 year ago');

// Travel to the given date time
$this->get($route)->assertSee('Your free trial is expired');

Under the hood, this is a wrapper to Carbon’s setTestNow and is designed to be a little more fluent than the default. Of course, usage is optional but it’s one of those little things that aim to make your development life a little easier.

Filed in: News


Join 31,000+ others and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Senior Laravel Developer
FPV Exchange
Senior Full-Stack Developer
Remote, USA Only
Senior PHP Developer
Cary, NC
Backend PHP Developer
Engineering Director
Vancouver or remote (EST/PST preferred)
Engine Digital