PHPackages                             pristavu/pest-plugin-test-time - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. pristavu/pest-plugin-test-time

ActiveLibrary[Testing &amp; Quality](/categories/testing)

pristavu/pest-plugin-test-time
==============================

A Pest plugin to control the flow of time

3.0(1y ago)0568MITPHPPHP ^8.1

Since Sep 13Pushed 1y agoCompare

[ Source](https://github.com/pristavu/pest-plugin-test-time)[ Packagist](https://packagist.org/packages/pristavu/pest-plugin-test-time)[ Docs](https://github.com/pristavu/pest-plugin-test-time)[ GitHub Sponsors](https://github.com/spatie)[ RSS](/packages/pristavu-pest-plugin-test-time/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

A Pest plugin to control the flow of time
=========================================

[](#a-pest-plugin-to-control-the-flow-of-time)

[![Latest Version on Packagist](https://camo.githubusercontent.com/9eddcfcef3269d9748418c7e29d133f0c8e84bc6ef068b86d015760f43adb182/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f706573742d706c7567696e2d746573742d74696d652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/pest-plugin-test-time)[![Tests](https://github.com/spatie/pest-plugin-test-time/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/pest-plugin-test-time/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/57d86e7135abc02266fc51e2b8f373b9aa140bca46b35c45a039e886b28de639/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f706573742d706c7567696e2d746573742d74696d652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/pest-plugin-test-time)

This [Pest](https://pestphp.com) 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
----------

[](#support-us)

[![](https://camo.githubusercontent.com/fd76ce505d2a5894d5a9ef213b2887c29f364e51d37dc69df7aa8c28de1514e2/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f706573742d706c7567696e2d746573742d74696d652e6a70673f743d31)](https://spatie.be/github-ad-click/pest-plugin-test-time)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

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](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Requirements
------------

[](#requirements)

This package is a wrapper around [Carbon](https://carbon.nesbot.com/docs/)'s `setTestNow()` function. Therefore, you can only use this Pest plugin only in projects that use Carbon.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require spatie/pest-plugin-test-time --dev
```

Usage
-----

[](#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

[](#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

[](#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

[](#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
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

603d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2875b9ef72b09212f72a878c4eb30c237ad1adf460ddd1a1f376ef7d4090f83e?d=identicon)[pristavu](/maintainers/pristavu)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (40 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (5 commits)")[![gpibarra](https://avatars.githubusercontent.com/u/21188012?v=4)](https://github.com/gpibarra "gpibarra (2 commits)")[![pristavu](https://avatars.githubusercontent.com/u/4123729?v=4)](https://github.com/pristavu "pristavu (2 commits)")[![chengkangzai](https://avatars.githubusercontent.com/u/43839286?v=4)](https://github.com/chengkangzai "chengkangzai (1 commits)")

---

Tags

spatiepest-plugin-test-time

### Embed Badge

![Health badge](/badges/pristavu-pest-plugin-test-time/health.svg)

```
[![Health](https://phpackages.com/badges/pristavu-pest-plugin-test-time/health.svg)](https://phpackages.com/packages/pristavu-pest-plugin-test-time)
```

###  Alternatives

[spatie/temporary-directory

Easily create, use and destroy temporary directories

96789.9M206](/packages/spatie-temporary-directory)[spatie/pest-plugin-test-time

A Pest plugin to control the flow of time

491.5M94](/packages/spatie-pest-plugin-test-time)[spatie/laravel-sitemap

Create and generate sitemaps with ease

2.6k14.6M107](/packages/spatie-laravel-sitemap)[spatie/phpunit-snapshot-assertions

Snapshot testing with PHPUnit

69417.9M511](/packages/spatie-phpunit-snapshot-assertions)[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.2M51](/packages/spatie-laravel-responsecache)[spatie/phpunit-watcher

Automatically rerun PHPUnit tests when source code changes

8839.2M473](/packages/spatie-phpunit-watcher)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
