The following tutorial column will introduce you to the new feature of Laravel 8 "Time Travel", I hope it will be helpful to friends in need!
# Another helpful little feature that Laravel 8 brings is that you can smoothly time travel during the testing session.This feature makes it easier to test scenarios: like what happens when the free trial ends, or what happens on the next billing date, etc... enunomaduro shared a simple one on Twitter The example demonstrates the usage of this new feature:
// 穿越到 5 分钟后 $this->travel(5)->minutes; $this->get($route)->assertSee('Created 5 mins ago'); // 穿越到 1 年后 $this->travel(1)->year; $this->get($route)->assertSee('Created 1 year ago'); // 穿越到制定日期 $this->travelTo($user->trial_ends_at); $this->get($route)->assertSee('Your free trial is expired');
This feature is actually an encapsulation of Carbon's setTestNow method, but it will be more fluid in design. Of course, you can use this feature or not, it's one of those little things to do to make your development life better.
Original address: https://laravel-news.com/laravel-time-travelingThe above is the detailed content of Laravel 8's new feature 'Time Travel”. For more information, please follow other related articles on the PHP Chinese website!