set('clock', * function() use ($clock) { return $clock; }); */ final class ABJ_404_Solution_FrozenClock implements ABJ_404_Solution_Clock { /** @var float Virtual epoch seconds (microsecond precision). */ private $t; /** @param float $startEpoch */ public function __construct(float $startEpoch = 1700000000.0) { $this->t = $startEpoch; } public function now(): int { return (int)$this->t; } public function nowFloat(): float { return $this->t; } public function wpNow(): int { return (int)$this->t; } public function wpNowMysql(): string { return gmdate('Y-m-d H:i:s', (int)$this->t); } /** * Advance virtual time by `$seconds`. Negative values rewind — useful * for tests that need to verify behavior at a known point in the past * (e.g. an expired cooldown that was set before the test "started"). * * @param float $seconds * @return void */ public function advance(float $seconds): void { $this->t += $seconds; } /** * Set virtual time to an absolute epoch. Use for tests that need to * pin time to a specific calendar date (e.g. boundary-of-month cron * tests). * * @param float $epoch * @return void */ public function set(float $epoch): void { $this->t = $epoch; } }