{"id":36680188,"url":"https://github.com/raigu/psr20-clock-testdoubles","last_synced_at":"2026-01-12T10:57:39.953Z","repository":{"id":47335517,"uuid":"401107216","full_name":"raigu/psr20-clock-testdoubles","owner":"raigu","description":"Test Doubles for PSR-20 clock","archived":false,"fork":false,"pushed_at":"2021-09-02T18:26:10.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-22T07:21:12.277Z","etag":null,"topics":["clock","double","php","psr-20","stub","test","time"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"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/raigu.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-29T17:54:40.000Z","updated_at":"2021-09-02T18:26:13.000Z","dependencies_parsed_at":"2022-08-27T20:51:02.784Z","dependency_job_id":null,"html_url":"https://github.com/raigu/psr20-clock-testdoubles","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/raigu/psr20-clock-testdoubles","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raigu%2Fpsr20-clock-testdoubles","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raigu%2Fpsr20-clock-testdoubles/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raigu%2Fpsr20-clock-testdoubles/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raigu%2Fpsr20-clock-testdoubles/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/raigu","download_url":"https://codeload.github.com/raigu/psr20-clock-testdoubles/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raigu%2Fpsr20-clock-testdoubles/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28338887,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T10:40:25.642Z","status":"ssl_error","status_checked_at":"2026-01-12T10:39:27.820Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["clock","double","php","psr-20","stub","test","time"],"created_at":"2026-01-12T10:57:39.259Z","updated_at":"2026-01-12T10:57:39.948Z","avatar_url":"https://github.com/raigu.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Latest Stable Version](http://poser.pugx.org/raigu/psr20-clock-testdoubles/v)](https://packagist.org/packages/raigu/psr20-clock-testdoubles)\n[![Latest Unstable Version](http://poser.pugx.org/raigu/psr20-clock-testdoubles/v/unstable)](https://packagist.org/packages/raigu/psr20-clock-testdoubles)\n[![Fallows SemVer](https://img.shields.io/badge/SemVer-2.0.0-green)](https://semver.org/spec/v2.0.0.html)\n[![build](https://github.com/raigu/psr20-clock-testdoubles/workflows/build/badge.svg)](https://github.com/raigu/psr20-clock-testdoubles/actions)\n[![codecov](https://codecov.io/gh/raigu/psr20-clock-testdoubles/branch/main/graph/badge.svg?token=9DD044TN72)](https://codecov.io/gh/raigu/psr20-clock-testdoubles)\n[![Mutation testing badge](https://img.shields.io/endpoint?style=flat\u0026url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fraigu%2Fpsr20-clock-testdoubles%2Fmain)](https://dashboard.stryker-mutator.io/reports/github.com/raigu/psr20-clock-testdoubles/main)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)\n\n\nTest Doubles for PSR-20 clock\n\nUnstable because the PSR-20 is not officially released yet.\n\n# Compatibility\n\n* PHP 7.4, ^8.0\n* psr/clock==@dev\n\n# Changes\n\n[./CHANGELOG.md](./CHANGELOG.md)\n\n# Install\n\n```shell\n$ composer require --dev raigu/psr20-clock-testdoubles\n```\n\n# Test Doubles\n\n## FrozenClock\n\nClock frozen in time. It always returns the same time now matter how many times the `now` is called.\n\n```php\n// creating with current system date and time\n$clock = new \\Raigu\\TestDouble\\Psr20\\FrozenClock;\n\n// creating with predefined date and time at\n$clock = new \\Raigu\\TestDouble\\Psr20\\FrozenClock(\n    new DateTimeImmutable('2020-01-02')\n);\n```\n\n## TimeTravelClock\n\nClock that acts like normal clock but has a shift in time if given.\n\n```php\n// By default, acts like normal clock. \n$clock = new \\Raigu\\TestDouble\\Psr20\\TimeTravelClock();\n$moment = $clock-\u003enow();\nsleep(2);\n// after two seconds the TimeTravelClock is also moved forward.\nassert($moment-\u003eadd(new DateInterval('PT2S'))-\u003egetTimestamp() === $clock-\u003enow()-\u003egetTimestamp());\n\n// Moving to the specific date and time in the future or past:\n$clock-\u003etravelInTime(new DateTimeImmutable('2020-01-02'));\nassert($clock-\u003enow()-\u003eformat('Y-m-d') === '2020-01-02');\n\n// Move by the specific interval to the future\n$clock-\u003etravelInTimeByInterval(new DateInterval('P10D'));\nassert($clock-\u003enow()-\u003eformat('Y-m-d') === '2020-01-12');\n\n// Move by the specific interval to the past\n$clock-\u003etravelInTimeByInterval(DateInterval::createFromDateString('-1 day'));\nassert($clock-\u003enow()-\u003eformat('Y-m-d') === '2020-01-11');\n```\n\nThe `TimeTravelClock` implements the Decorator pattern by wrapping \na clock implementation. By default, it uses a system clock implementation, \nbut it can be replaced in constructor.\n\nFor example, it is possible to create TimeTravelClock that is frozen by using `FrozenClock`:\n\n```php\n$clock = new \\Raigu\\TestDouble\\Psr20\\TimeTravelClock(\n    new Raigu\\TestDouble\\Psr20\\FrozenClock()\n);\n$moment = $clock-\u003enow();\nsleep(2);\nassert($moment-\u003egetTimestamp() === $clock-\u003egetTimestamp(), 'Does not tick because base clock is frozen.');\n```\n\n# Testing\n\n```shell\n$ composer test\n$ composer specification \n$ composer coverage\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraigu%2Fpsr20-clock-testdoubles","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraigu%2Fpsr20-clock-testdoubles","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraigu%2Fpsr20-clock-testdoubles/lists"}