MDL-85563 phpunit: Clock API should always use Moodle system time

When using `clock::now()` the frozen cloxk and incrementing clock will now
always return a `DateTimeImmutable` that uses the configured Moodle system
time. In unit tests this will be Australia/Perth.

Before this change, it would sometimes be UCT.
This commit is contained in:
Neill Magill
2025-06-30 11:43:46 +01:00
parent c36274a15a
commit 76275dadf5
3 changed files with 10 additions and 2 deletions
+5 -1
View File
@@ -26,6 +26,9 @@ class incrementing_clock implements \core\clock {
/** @var int The next time of the clock */
public int $time;
/** @var DateTimeZone The system timezone. */
protected DateTimeZone $timezone;
/**
* Create a new instance of the incrementing clock.
*
@@ -35,10 +38,11 @@ class incrementing_clock implements \core\clock {
?int $starttime = null,
) {
$this->time = $starttime ?? time();
$this->timezone = \core_date::get_server_timezone_object();
}
public function now(): \DateTimeImmutable {
return new \DateTimeImmutable('@' . $this->time++);
return (new \DateTimeImmutable('@' . $this->time++))->setTimezone($this->timezone);
}
public function time(): int {