MDL-80838 core: Add PSR-20/Clock support 298c13ac3b25823a71b9f48e74ac187fbe06be41
authorAndrew Nicols <andrew@nicols.co.uk>
Tue, 6 Feb 2024 05:05:49 +0000 (13:05 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Tue, 2 Apr 2024 02:24:54 +0000 (10:24 +0800)
commit298c13ac3b25823a71b9f48e74ac187fbe06be41
tree2316ee37d65f54757f4612639f33183b2417b197
parentc895def59b1ba0dba8b0306059cd4f314358b78a
MDL-80838 core: Add PSR-20/Clock support

This commit adds the PSR-20 ClockInterface to core, with a
moodle-specific extension to the Interface at `\core\clock`, and a
standard clock at `\core\system_clock`.

Further clocks are provided as `\incrementing_clock` and `\frozen_clock`
which are available to unit tests using:

- `$this->mock_clock_with_incrementing(?int $starttime = null);`
- `$this->mock_clock_with_frozen(?int $time = null);`

For the incrementing clock, every call to fetch the time will bump the
current time by one second.

For the frozen clock the time will not change, but can be modified with:
- `$clock->set_to(int $time);`; and
- `$clock->bump(int $seconds = 1);`
15 files changed:
lib/classes/clock.php [new file with mode: 0644]
lib/classes/component.php
lib/classes/di.php
lib/classes/system_clock.php [new file with mode: 0644]
lib/phpunit/classes/advanced_testcase.php
lib/phpunit/tests/advanced_test.php
lib/psr/clock/LICENSE [new file with mode: 0644]
lib/psr/clock/README.md [new file with mode: 0644]
lib/psr/clock/readme_moodle.txt [new file with mode: 0644]
lib/psr/clock/src/ClockInterface.php [new file with mode: 0644]
lib/testing/classes/frozen_clock.php [new file with mode: 0644]
lib/testing/classes/incrementing_clock.php [new file with mode: 0644]
lib/testing/tests/clock_test.php [new file with mode: 0644]
lib/tests/system_clock_test.php [new file with mode: 0644]
lib/thirdpartylibs.xml