{"id":13732538,"url":"https://github.com/spatie/pest-plugin-test-time","last_synced_at":"2025-04-09T18:19:15.120Z","repository":{"id":57056547,"uuid":"386927703","full_name":"spatie/pest-plugin-test-time","owner":"spatie","description":"A Pest plugin to control the flow of time","archived":false,"fork":false,"pushed_at":"2024-09-20T13:42:40.000Z","size":41,"stargazers_count":46,"open_issues_count":0,"forks_count":7,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-09T18:19:11.215Z","etag":null,"topics":["carbon","pest","php","testing","time"],"latest_commit_sha":null,"homepage":"https://spatie.be/open-source","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spatie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"spatie"}},"created_at":"2021-07-17T12:07:48.000Z","updated_at":"2025-04-04T04:41:07.000Z","dependencies_parsed_at":"2024-06-18T15:26:30.003Z","dependency_job_id":"f0c05f99-618f-433d-a944-17e594d7faed","html_url":"https://github.com/spatie/pest-plugin-test-time","commit_stats":{"total_commits":41,"total_committers":5,"mean_commits":8.2,"dds":"0.19512195121951215","last_synced_commit":"1d51ee107dc3d8679da26d67a2c123c710a459c4"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":"spatie/package-skeleton-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fpest-plugin-test-time","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fpest-plugin-test-time/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fpest-plugin-test-time/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fpest-plugin-test-time/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spatie","download_url":"https://codeload.github.com/spatie/pest-plugin-test-time/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248085325,"owners_count":21045139,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["carbon","pest","php","testing","time"],"created_at":"2024-08-03T03:00:25.391Z","updated_at":"2025-04-09T18:19:15.101Z","avatar_url":"https://github.com/spatie.png","language":"PHP","funding_links":["https://github.com/sponsors/spatie"],"categories":["Plugins"],"sub_categories":["Unofficial"],"readme":"# A Pest plugin to control the flow of time\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/pest-plugin-test-time.svg?style=flat-square)](https://packagist.org/packages/spatie/pest-plugin-test-time)\n[![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)\n[![Total Downloads](https://img.shields.io/packagist/dt/spatie/pest-plugin-test-time.svg?style=flat-square)](https://packagist.org/packages/spatie/pest-plugin-test-time)\n\nThis [Pest](https://pestphp.com) plugin offers a function `testTime` that allows you to freeze and manipulate the current time in your tests.\n\n```php\nuse function Spatie\\PestPluginTestTime\\testTime;\n\ntestTime()-\u003efreeze(); // time will not change anymore\n\ntestTime()-\u003eaddMinute(); // move time forward one minute\n```\n\nIt also contains a custom expectation called `toBeCarbon` to easily check the values of `Carbon` instances.\n\n```php\n$carbon = Carbon::createFromFormat('Y-m-d H:i:s', '2022-05-31 01:02:03');\n\n// make an expectation on the whole date, including time\nexpect($carbon)-\u003etoBeCarbon('2022-05-31 01:02:03');\n\n// make an expectation on only the date part\nexpect($carbon)-\u003etoBeCarbon('2022-05-31');\n\n// explicitly pass in a format\nexpect($carbon)-\u003etoBeCarbon('2022', 'Y');\n```\n\n## Support us\n\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/pest-plugin-test-time.jpg?t=1\" width=\"419px\" /\u003e](https://spatie.be/github-ad-click/pest-plugin-test-time)\n\nWe 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).\n\nWe 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).\n\n## Requirements\n\nThis 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.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require spatie/pest-plugin-test-time --dev\n```\n\n## Usage\n\nYou can call `freeze` on the `testTime` function to freeze the current time.\n\n```php\nuse Carbon\\Carbon;\nuse function Spatie\\PestPluginTestTime\\testTime;\n\ntestTime()-\u003efreeze(); // the current time will not change anymore\n\nCarbon::now(); // returns the time\n\nsleep(2);\n\nCarbon::now(); // will return the same time as above\n```\n\n### Freezing at a specific point in time\n\nYou can also freeze the time at a specific point by passing the time in format `Y-m-d H:i:s`.\n\n```php\ntestTime()-\u003efreeze('2021-01-02 12:34:56');\n\n\\Carbon\\Carbon::now()-\u003eformat('Y-m-d H:i:s') // returns '2021-01-02 12:34:56';\n```\n\n### Changing the time\n\nYou can change the time, by calling any of the `add` and `sub` functions that are available on `Carbon`.\n\n```php\ntestTime()-\u003efreeze('2021-01-02 12:34:56');\n\ntestTime()-\u003eaddHour(); // time is now at '2021-01-02 13:34:56'\n\n// you can even chain method calls\ntestTime()-\u003esubMinute()-\u003eaddSeconds(2); // time is now at '2021-01-02 13:33:58'\n```\n\n### Expecting a Carbon value\n\nThis package offers a custom expectation called `toBeCarbon` to easily check the value of a `Carbon` instance.\n\n```php\n$carbon = Carbon::createFromFormat('Y-m-d H:i:s', '2022-05-31 01:02:03');\n\n// make an expectation on the whole date, including time\nexpect($carbon)-\u003etoBeCarbon('2022-05-31 01:02:03');\n\n// make an expectation on only the date part\nexpect($carbon)-\u003etoBeCarbon('2022-05-31');\n\n// explicitly pass in a format\nexpect($carbon)-\u003etoBeCarbon('2022', 'Y');\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [Freek Van der Herten](https://github.com/freekmurze)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Fpest-plugin-test-time","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspatie%2Fpest-plugin-test-time","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Fpest-plugin-test-time/lists"}