All Projects → spatie → pest-plugin-test-time

spatie / pest-plugin-test-time

Licence: MIT license
A Pest plugin to control the flow of time

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to pest-plugin-test-time

Carbon
A simple, semantic and developer-friendly golang package for datetime
Stars: ✭ 565 (+1722.58%)
Mutual labels:  time, carbon
Test Time
A helper to control the flow of time
Stars: ✭ 169 (+445.16%)
Mutual labels:  time, carbon
Travel
Framework agnostic PHP package to control the time.
Stars: ✭ 251 (+709.68%)
Mutual labels:  time, carbon
tir
Have time.ir in shell!
Stars: ✭ 114 (+267.74%)
Mutual labels:  time
silverware-calendar
SilverWare Calendar Module
Stars: ✭ 15 (-51.61%)
Mutual labels:  time
qrono
🕥 Just right date time library
Stars: ✭ 111 (+258.06%)
Mutual labels:  time
dt
Go's missing DateTime package
Stars: ✭ 34 (+9.68%)
Mutual labels:  time
FM-JSON-Types
FileMaker Data Types in JSON
Stars: ✭ 14 (-54.84%)
Mutual labels:  time
hs-hourglass
efficient and simpler time API for haskell
Stars: ✭ 43 (+38.71%)
Mutual labels:  time
ElevenClock
ElevenClock: Customize Windows 11 taskbar clock
Stars: ✭ 1,494 (+4719.35%)
Mutual labels:  time
Sorting-Algorithms
sorting algorithms in python
Stars: ✭ 15 (-51.61%)
Mutual labels:  time
cas
Cellular Automata Simulator
Stars: ✭ 22 (-29.03%)
Mutual labels:  time
rutimeparser
Recognize date and time in russian text and return datetime.datetime.
Stars: ✭ 17 (-45.16%)
Mutual labels:  time
chronoman
Utility class to simplify use of timers created by setTimeout
Stars: ✭ 15 (-51.61%)
Mutual labels:  time
duration-humanizer
361000 becomes "6 minutes, 1 second"
Stars: ✭ 61 (+96.77%)
Mutual labels:  time
timeleft
⏳ Don't waste your time or time will waste you! ☠️ One tends to consume time on low-return stuff, superficial entertainment. 📺 Things they don't actually want to do. One should make the most of his time. ⏱ Get busy living.
Stars: ✭ 18 (-41.94%)
Mutual labels:  time
time-aware-template
Time Aware is a configurable application template that enables you to display time enabled layers in an ArcGIS web map using a time slider.
Stars: ✭ 20 (-35.48%)
Mutual labels:  time
website
This repository contains Pest's website and documentation
Stars: ✭ 15 (-51.61%)
Mutual labels:  pest
carbon-business-days
A simple class for business days counting
Stars: ✭ 37 (+19.35%)
Mutual labels:  carbon
faketime
Fake currentTimeMillis() without class loader hacks
Stars: ✭ 100 (+222.58%)
Mutual labels:  time

A Pest plugin to control the flow of time

Latest Version on Packagist Tests GitHub Code Style Action Status Total Downloads

This Pest plugin offers a function testTime that allows you to freeze and manipulate the current time in your tests.

use function Spatie\PestPluginTestTime\testTime;

testTime()->freeze(); // time will not change anymore

testTime()->addMinute(); // move time forward one minute

It also contains a custom expectation called toBeCarbon to easily check the values of Carbon instances.

$carbon = Carbon::createFromFormat('Y-m-d H:i:s', '2022-05-31 01:02:03');

// make an expectation on the whole date, including time
expect($carbon)->toBeCarbon('2022-05-31 01:02:03');

// make an expectation on only the date part
expect($carbon)->toBeCarbon('2022-05-31');

// explicitly pass in a format
expect($carbon)->toBeCarbon('2022', 'Y');

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.

Requirements

This package is a wrapper around Carbon's setTestNow() function. Therefore, you can only use this Pest plugin only in projects that use Carbon.

Installation

You can install the package via composer:

composer require spatie/pest-plugin-test-time

Usage

You can call freeze on the testTime function to freeze the current time.

use Carbon\Carbon;
use function Spatie\PestPluginTestTime\testTime;

testTime()->freeze(); // the current time will not change anymore

Carbon::now(); // returns the time

sleep(2);

Carbon::now(); // will return the same time as above

Freezing at a specific point in time

You can also freeze the time at a specific point by passing the time in format Y-m-d H:i:s.

testTime()->freeze('2021-01-02 12:34:56');

\Carbon\Carbon::now()->format('Y-m-d H:i:s') // returns '2021-01-02 12:34:56';

Changing the time

You can change the time, by calling any of the add and sub functions that are available on Carbon.

testTime()->freeze('2021-01-02 12:34:56');

testTime()->addHour(); // time is now at '2021-01-02 13:34:56'

// you can even chain method calls
testTime()->subMinute()->addSeconds(2); // time is now at '2021-01-02 13:33:58'

Expecting a Carbon value

This package offers a custom expectation called toBeCarbon to easily check the value of a Carbon instance.

$carbon = Carbon::createFromFormat('Y-m-d H:i:s', '2022-05-31 01:02:03');

// make an expectation on the whole date, including time
expect($carbon)->toBeCarbon('2022-05-31 01:02:03');

// make an expectation on only the date part
expect($carbon)->toBeCarbon('2022-05-31');

// explicitly pass in a format
expect($carbon)->toBeCarbon('2022', 'Y');

Testing

composer test

Changelog

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

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].