A Pest plugin to control the flow of time

Overview

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

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'

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.

You might also like...
Control Chrome or Chromium easily.

Laravel Chromedriver Control Chrome or Chromium easily. Requirements PHP 7.4 or latest Laravel 8.x Chrome or Chromium latest version Installation You

Mock built-in PHP functions (e.g. time(), exec() or rand())

PHP-Mock: mocking built-in PHP functions PHP-Mock is a testing library which mocks non deterministic built-in PHP functions like time() or rand(). Thi

A PHP library for mocking date and time in tests

ClockMock Slope s.r.l. ClockMock provides a way for mocking the current timestamp used by PHP for \DateTime(Immutable) objects and date/time related f

To run time/IO related unit tests (e.g., sleep function calls, database queries, API calls, etc) faster using Swoole.

To run time/IO related unit tests (e.g., sleep function calls, database queries, API calls, etc) faster using Swoole.

Railway Flow Based Programming
Railway Flow Based Programming

Why ? Railway Flow Based Programming concept aims to solve Adopt asynchronous as native implementation Build your code with functional programming and

Flow Framework Task Scheduler

This package provides a simple to use task scheduler for Neos Flow. Tasks are configured via settings, recurring tasks can be configured using cron syntax. Detailed options configure the first and last executions as well as options for the class handling the task.

Flow package to synchronize metadata and binary data of imported Neos.Media assets

Wwwision.AssetSync Flow package to synchronize metadata and resources of imported Neos.Media assets Installation Install this package via: composer re

(Experimental) Neos / Flow via Roadrunner

Roadrunner distribution This is an experimental distribution to run Neos / Flow via Roadrunner. Note: The Neos / Flow code currently needs patches to

↪️🔔 Send notification action for Nextcloud Flow
↪️🔔 Send notification action for Nextcloud Flow

Nextcloud Flow Notifications 📝 Notification action for Nextcloud Flow 🔩 Configure your flow 🔔 Receive notifications 🏗 Development setup ☁ Clone th

With dadjokes every time you load your control panel you'll be greeted by an epic dad joke on the dashboard.

Filament Dad Jokes Widget With DadJokes every time you load your control panel you'll be greeted by an epic dad joke on the dashboard. Installation Yo

⛽ Pest plugin to test Laravel applications powered by Octane.

⛽ Laravel Octane (Pest Plugin) Pest plugin to test Laravel applications powered by Octane. Install Via Composer composer require --dev cerbero/pest-pl

A plugin for working with popular money libraries in Pest

This package is a plugin for Pest PHP. It allows you to write tests against monetary values provided by either brick/money or moneyphp/money using the same declarative syntax you're used to with Pest's expectation syntax.

The Pest Parallel Plugin

This repository contains the Pest Plugin Parallel. If you want to start testing your application with Pest, visit the main Pest Repository. Explore th

The Pest Laravel Expectations Plugin
The Pest Laravel Expectations Plugin

This Pest plugin adds Laravel specific expectations to the testing ecosystem it('can check model exists', function(){ $user = User::factory()-creat

A Pest plugin for WordPress
A Pest plugin for WordPress

WordPress Pest Plugin Supports integrating Pest with your WordPress code base through the Mantle Framework. Read about the Mantle Testing Framework he

This plugin adds basic HTTP requests functionality to Pest tests, using minicli/curly

Curly Pest Plugin This plugin adds basic HTTP requests functionality to Pest tests, using minicli/curly. Installation composer require minicli/pest-pl

Given When Then (GWT) Plugin for Pest

Given When Then (GWT) Plugin for Pest A simple API allows you to structure your tests focused on the behaviour. Given-When-Then separation makes the t

Laravel Angular Time Tracker is a simple time tracking application built on Laravel 5.2, Angular 2, and Bootstrap 3.

Laravel 5.2, Angular 2, and Bootstrap 3.3.* Time Tracker Laravel Angular Time Tracker is a simple time tracking application built on Laravel 5.2, Angu

Quickly and easily preview and test your Magento 2 order confirmation page, without hacks or spending time placing new order each time
Quickly and easily preview and test your Magento 2 order confirmation page, without hacks or spending time placing new order each time

Preview Order Confirmation Page for Magento 2 For Magento 2.0.x, 2.1.x, 2.2.x and 2.3.x Styling and testing Magento's order confirmation page can be a

Releases(1.1.1)
Owner
Spatie
We create products and courses for the developer community
Spatie
The Pest Parallel Plugin

This repository contains the Pest Plugin Parallel. If you want to start testing your application with Pest, visit the main Pest Repository. Explore th

PEST 28 Dec 5, 2022
This plugin adds basic HTTP requests functionality to Pest tests, using minicli/curly

Curly Pest Plugin This plugin adds basic HTTP requests functionality to Pest tests, using minicli/curly. Installation composer require minicli/pest-pl

minicli 16 Mar 24, 2022
Given When Then (GWT) Plugin for Pest

Given When Then (GWT) Plugin for Pest A simple API allows you to structure your tests focused on the behaviour. Given-When-Then separation makes the t

Milroy Fraser 85 Dec 22, 2022
Add mocking capabilities to Pest or PHPUnit

This repository contains the Pest Plugin Mock. The Mocking API can be used in regular PHPUnit projects. For that, you just have to run the following c

PEST 16 Dec 3, 2022
Integrates Pest with PHP-VCR using plugins.

Pest plugin for PHP-VCR Integrates Pest with PHP-VCR using plugins. Installation You can install the package via composer: composer require phpjuice/p

PHPJuice 4 Sep 1, 2021
Wraps your Pest suite in a Laravel application instance, allowing global use of the framework in tests.

Pest Larastrap Plugin This is currently a highly experimental project and is subject to large pre-release changes. Pest PHP is an awesome PHP testing

Luke Downing 3 Jan 6, 2022
PHPUnit to Pest Converter

PestConverter PestConverter is a PHP library for converting PHPUnit tests to Pest tests. Before use Before using this converter, make sure your files

null 10 Nov 21, 2022
Pest is an elegant PHP Testing Framework with a focus on simplicity

Pest is an elegant PHP Testing Framework with a focus on simplicity. It was carefully crafted to bring the joy of testing to PHP. Explore the docs: pe

PEST 5.9k Dec 27, 2022
Enforce consistent styling for your Pest PHP tests

A set of PHP CS rules for formatting Pest PHP tests.

Worksome 2 Mar 15, 2022
Prevent none-test output in your Pest tests.

Pest Plugin Silence Often, when writing tests, we echo and dump test code to debug and check everything is working correctly. It can be easy to forget

Worksome 5 Feb 23, 2022