https://github.com/wmde/clock
🕓 Simple interface to get the current time without binding to global system resources
https://github.com/wmde/clock
Last synced: 13 days ago
JSON representation
🕓 Simple interface to get the current time without binding to global system resources
- Host: GitHub
- URL: https://github.com/wmde/clock
- Owner: wmde
- License: bsd-3-clause
- Created: 2018-09-24T01:44:51.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2025-03-21T08:50:40.000Z (about 1 month ago)
- Last Synced: 2025-03-27T22:22:53.707Z (about 1 month ago)
- Language: PHP
- Homepage:
- Size: 146 KB
- Stars: 3
- Watchers: 24
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: COPYING.txt
Awesome Lists containing this project
README
# Clock
[](https://travis-ci.com/wmde/Clock)
[](https://scrutinizer-ci.com/g/wmde/Clock/?branch=master)
[](https://scrutinizer-ci.com/g/wmde/Clock/?branch=master)
[](https://packagist.org/packages/wmde/clock)
[](https://packagist.org/packages/wmde/clock)A simple interface to get the current time without binding to global system resources plus trivial implementations that facilitate testing.
## Clock Usage
```php
function yourCode(Clock $clock) {
$time = $clock->now(); // Returns DateTimeImmutable. No global access and easily testable
}
```Clock interface:
```php
interface Clock {
public function now(): \DateTimeImmutable;
}
```Provided implementations:
* `SystemClock`: Uses global system resources
* `StubClock`: Returns value provided in the constructor. Useful in tests
* `CollectionClock`: Returns specified values sequentially. Useful in tests
* `IncrementingClock`: Returns an incremented starting time infinitely. Useful in tests## Installation
To use the Clock library in your project, simply add a dependency on wmde/clock
to your project's `composer.json` file. Here is a minimal example of a `composer.json`
file that just defines a dependency on Clock 1.x:```json
{
"require": {
"wmde/clock": "~1.0"
}
}
```## Development
For development you need to have Docker and Docker-compose installed. Local PHP and Composer are not needed.
sudo apt-get install docker docker-compose
### Running Composer
To pull in the project dependencies via Composer, run:
make composer install
You can run other Composer commands via `make run`, but at present this does not support argument flags.
If you need to execute such a command, you can do so in this format:docker run --rm --interactive --tty --volume $PWD:/app -w /app\
--volume ~/.composer:/composer --user $(id -u):$(id -g) composer composer install --no-scriptsWhere `composer install --no-scripts` is the command being run.
### Running the CI checks
To run all CI checks, which includes PHPUnit tests, PHPCS style checks and coverage tag validation, run:
make
### Running the testsTo run just the PHPUnit tests run
make test
To run only a subset of PHPUnit tests or otherwise pass flags to PHPUnit, run
docker-compose run --rm app ./vendor/bin/phpunit --filter SomeClassNameOrFilter
## Release notes
### 1.0.0 (2018-09-26)
Initial release with `Clock`, `SystemClock`, `StubClock`, `CollectionClock` and `IncrementingClock`