Home > PHP Framework > Laravel > body text

Laravel 8's new feature 'Time Travel”

藏色散人
Release: 2020-09-07 09:09:33
forward
3016 people have browsed it

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.

Laravel 8's new feature 'Time Travel”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');
Copy after login

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-traveling

The 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!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template