Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
FixedClock
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
4 / 4
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 now
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 advance
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 set
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace LambdaTwelve\OneRecord\Testing;
6
7use DateTimeImmutable;
8use Psr\Clock\ClockInterface;
9
10final class FixedClock implements ClockInterface
11{
12    private DateTimeImmutable $now;
13
14    public function __construct(string|DateTimeImmutable $now = '2026-10-02T12:00:00Z')
15    {
16        $this->now = $now instanceof DateTimeImmutable ? $now : new DateTimeImmutable($now);
17    }
18
19    public function now(): DateTimeImmutable
20    {
21        return $this->now;
22    }
23
24    public function advance(string $interval): void
25    {
26        $this->now = $this->now->modify($interval);
27    }
28
29    /**
30     * Jumps to an absolute instant: expiry boundaries, "a year later".
31     */
32    public function set(string|DateTimeImmutable $now): void
33    {
34        $this->now = $now instanceof DateTimeImmutable ? $now : new DateTimeImmutable($now);
35    }
36}