PHPackages                             spatie/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. spatie/test-time

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

spatie/test-time
================

A small package to control the flow time

1.3.3(2y ago)2084.7M—2.4%1020MITPHPPHP ^7.3|^8.0CI passing

Since Jun 12Pushed 8mo ago4 watchersCompare

[ Source](https://github.com/spatie/test-time)[ Packagist](https://packagist.org/packages/spatie/test-time)[ Docs](https://github.com/spatie/test-time)[ Fund](https://spatie.be/open-source/support-us)[ GitHub Sponsors](https://github.com/spatie)[ RSS](/packages/spatie-test-time/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (15)Used By (20)

A helper to control the flow of time
====================================

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

[![Latest Version on Packagist](https://camo.githubusercontent.com/ac61c16c67a2b3ede244451f72ffe261160b34883753f691ac3731fd30f891f8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f746573742d74696d652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/test-time)[![run-tests](https://github.com/spatie/test-time/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/test-time/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/348115cea5c8464ebf2cb943c8e734e36f9b5b69368c72998509409d04c2d032/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f746573742d74696d652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/test-time)

[Carbon](https://github.com/briannesbitt/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?
-------------------------

[](#are-you-a-visual-learner)

[In this video](https://www.youtube.com/watch?v=1dJphbcWRxI), you'll learn how we use this package to test time sensitive functionality in [Mailcoach](https://mailcoach.app).

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/d5556f7b044bf19b176b4fdf30e1a76ff52ac96833129c24e8893ca4577e80cf/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f746573742d74696d652e6a70673f743d31)](https://spatie.be/github-ad-click/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).

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

[](#installation)

You can install the package via composer. Probably you'll only need it when developing.

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

Usage
-----

[](#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');
```

### Progressing time

[](#progressing-time)

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();
```

### Unfreezing time

[](#unfreezing-time)

To let time flow naturally again, call `unfreeze`.

```
TestTime::unfreeze();
```

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

[](#security)

If you've found a bug regarding security please mail  instead of using the issue tracker.

Postcardware
------------

[](#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](https://spatie.be/en/opensource/postcards).

Credits
-------

[](#credits)

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

License
-------

[](#license)

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

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance43

Moderate activity, may be stable

Popularity60

Solid adoption and visibility

Community38

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 63.6% 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

Every ~141 days

Recently: every ~297 days

Total

13

Last Release

833d ago

Major Versions

0.0.1 → 1.0.02019-06-12

PHP version history (4 changes)0.0.1PHP ^7.1

1.0.0PHP ^7.2

1.2.2PHP ^7.2|^8.0

1.3.0PHP ^7.3|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (56 commits)")[![patinthehat](https://avatars.githubusercontent.com/u/5508707?v=4)](https://github.com/patinthehat "patinthehat (10 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (8 commits)")[![veneliniliev](https://avatars.githubusercontent.com/u/5311085?v=4)](https://github.com/veneliniliev "veneliniliev (4 commits)")[![MatanYadaev](https://avatars.githubusercontent.com/u/13586343?v=4)](https://github.com/MatanYadaev "MatanYadaev (3 commits)")[![pascalbaljet](https://avatars.githubusercontent.com/u/8403149?v=4)](https://github.com/pascalbaljet "pascalbaljet (2 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (2 commits)")[![brendt](https://avatars.githubusercontent.com/u/6905297?v=4)](https://github.com/brendt "brendt (1 commits)")[![aryehraber](https://avatars.githubusercontent.com/u/5065331?v=4)](https://github.com/aryehraber "aryehraber (1 commits)")[![svenluijten](https://avatars.githubusercontent.com/u/11269635?v=4)](https://github.com/svenluijten "svenluijten (1 commits)")

---

Tags

carbonphptestingteststimespatietest-time

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/spatie-test-time/health.svg)

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

###  Alternatives

[spatie/temporary-directory

Easily create, use and destroy temporary directories

96889.9M206](/packages/spatie-temporary-directory)[spatie/laravel-sitemap

Create and generate sitemaps with ease

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

Snapshot testing with PHPUnit

69617.9M510](/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.2M475](/packages/spatie-phpunit-watcher)[spatie/laravel-honeypot

Preventing spam submitted through forms

1.6k6.0M60](/packages/spatie-laravel-honeypot)

PHPackages © 2026

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