tumblr / chorus-timekeeper
A super simple class for DI with timekeeping
Installs: 2 871
Dependents: 2
Suggesters: 0
Security: 0
Stars: 1
Watchers: 6
Forks: 1
Open Issues: 0
Requires
- php: ^7.4 || ^8.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.8
- friendsofphp/php-cs-fixer: ^3.17
- infection/infection: >=0.10.5
- phan/phan: >=1.1
- phpstan/phpstan: >=0.10
- phpunit/phpunit: ^9.4
- symfony/phpunit-bridge: ^6.3
- vimeo/psalm: >=2
This package is not auto-updated.
Last update: 2024-12-10 10:43:09 UTC
README
The Chorus TimeKeeper is an elegant utility for Dependency Injection (DI) with timekeeping. At its core, it offers a straightforward approach to time management in applications, allowing for consistent time retrieval and even time manipulation for testing purposes. This can be exceptionally helpful when writing tests or simulating various time conditions in your code.
It provides two primary components:
TimeKeeper
: Fetches real-time data.FakeTimeKeeper
: Helps in mocking or manipulating time during testing.
For example, when testing time-sensitive components, you can utilize FakeTimeKeeper
to preset time scenarios, avoiding the hassle of waiting in real-time or simulating date changes on your system.
Requirements
- PHP ^7.4 or ^8.0
Installation
You can install the package via Composer:
composer require tumblr/chorus-timekeeper
Basic Usage
// Using the real TimeKeeper $timekeeper = new Tumblr\Chorus\TimeKeeper(); echo $timekeeper->getCurrentUnixTime(); // Outputs the current unix epoch time. // Using the FakeTimeKeeper $fakeTimeKeeper = new Tumblr\Chorus\FakeTimeKeeper(1628700000); // Set a specific unix time. echo $fakeTimeKeeper->getCurrentUnixTime(); // Outputs 1628700000.
Development Workflow
The project has a Makefile to simplify development processes. You can use various make commands to run tests, validate code standards, and more. Here's a quick overview:
1. Prerequisites Setup
Ensure your environment is set up correctly:
- Install required packages:
make prerequisites
- Report PHP location:
make report-php-location
2. Testing
Run all tests:
make test
Run only PHPUnit tests:
make phpunit
Generate PHPUnit test coverage:
make phpunit-coverage
3. Static Analysis
Use psalm for static analysis:
make sa
4. Code Standards
Fix coding standards using PHP CS Fixer:
make cs
5. Mutation Testing
Run mutation tests to ensure code quality:
make mt
6. Composer
Validate composer files:
make composer-validate
7. YAML Linting
Lint YAML files to ensure correctness:
make yamllint
Contributing
If you wish to contribute to the Chorus TimeKeeper, please follow these steps:
- Raise an Issue: Before making any changes, create an issue describing your idea or the desired change.
- Submit a PR: Once your idea is approved, create a Pull Request. Make sure to include or update unit tests.
- Testing & Code Style: Ensure all tests pass (
make test
) and fix any code style issues (make cs
). - Describe Your Changes: Clearly describe what you've changed and include testing instructions.
- Breaking Changes Alert: If your contribution introduces breaking changes, please highlight them. Any modification that disrupts the current workflow, like changing a namespace or functionality, is a breaking change.
Remember, if you're planning a significant refactor or introducing breaking changes, your PR might not be approved.
Once your PR is approved, it will be merged, and a new version will be released.
License
This project is licensed under the GNU General Public License v2.0.