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->travel(5)->minutes;
$this->get($route)->assertSee('Created 5 mins ago');

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

// Travel to the given date time
$this->travelTo($user->trial_ends_at);
$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

Newsletter

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

Laravel News Partners

Laravel Jobs

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