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
Join 31,000+ others and never miss out on new tips, tutorials, and more.
Early Access to the Laravel 8 Upgrade Guide
The Laravel 8 upgrade guide is available early if you want to start planning your upgrades from Laravel 7.
Laracon Online videos are now out
Now that Laracon Online is over, we’ve processed all the videos and they are now available for all the ticket holders…