Need help with test-time?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

spatie
184 Stars 6 Forks MIT License 54 Commits 0 Opened issues

Description

A helper to control the flow of time

Services available

!
?

Need anything else?

Contributors list

A helper to control the flow of time

Latest Version on Packagist GitHub Workflow Status StyleCI Quality Score Total Downloads

Carbon is an excellent library to work with time in PHP projects. The

Spatie\TestTime\TestTime
class contains a few functions that under the hood manipulate the time that's considered the current time by Carbon.
// the flow of time is frozen
TestTime::freeze();

// we're now one year in the future TestTime::addYear();

// will report the real current year + 1 $year = (new Carbon())->format('Y');

Are you a visual learner?

In this video, you'll learn how we use this package to test time sensitive functionality in Mailcoach.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

composer require spatie/test-time

Usage

You can freeze the time with:

TestTime::freeze();

Alternatively you can pass in a carbon instance that will be used as the current time.

TestTime::freeze($carbonInstance);

You can also pass a format and time.

TestTime::freeze('Y-m-d', '2019-06-12');

You can progress the time with any of the carbon functions starting with

add
or
sub
.
TestTime::addMinute();

TestTime::subHours(5);

// you can also chain calls TestTime::addMonth(3)->addYear();

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Postcardware

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

We publish all received postcards on our company website.

Credits

License

The MIT License (MIT). Please see License File for more information.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.