Skip to content
PHP Clock abstraction
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.editorconfig
.gitignore
.phpcs.xml
.travis.yml
README.md
composer.json
composer.lock
phpstan.neon
phpunit.xml

README.md

Clock

Latest Stable Version Total Downloads Build Status codecov FOSSA Status

A clock abstraction library for PHP which allow to mock system clock when testing

Usage

In your code, always use the ClockInterface in your services when you need to access the current time. After that, you just had to define which implementation to use according to your environement (real or fake for tests).

In some framework, It can be easier to use the factory to handle the switch and inject the require configuration.

Symfony 4

With SF4 we use the internal DI system with the factory. The factory will get different parameters according to the current environment.

Configure DI with a factory in config/services.yaml:

# config/services.yaml
    Jeckel\Clock\ClockInterface:
        factory: ['Jeckel\Clock\ClockFactory', getClock]
        arguments: ['%fake_clock%', '%fake_clock_file%']

Configure default parameters in config/packages/parameters.yaml:

# config/packages/parameters.yaml
parameters:
    fake_clock: false
    fake_clock_file: '%kernel.project_dir%/var/clock'

And then configure parameters for tests environment in config/packages/test/parameters.yaml:

# config/packages/test/parameters.yaml
parameters:
    fake_clock: true

License

FOSSA Status

You can’t perform that action at this time.