File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,9 +15,13 @@ public function __construct(\DateTimeInterface $now)
1515 $ this ->wrapped = new MockClock (\DateTimeImmutable::createFromInterface ($ now ));
1616 }
1717
18- public function advance (int $ seconds ): void
18+ public function advance (int | \ DateInterval $ secondsOrInterval ): void
1919 {
20- $ now = $ this ->now ()->add (new \DateInterval ("PT {$ seconds }S " ));
20+ if (!$ secondsOrInterval instanceof \DateInterval) {
21+ $ secondsOrInterval = new \DateInterval ("PT {$ secondsOrInterval }S " );
22+ }
23+
24+ $ now = $ this ->now ()->add ($ secondsOrInterval );
2125 $ this ->wrapped = new MockClock ($ now );
2226 }
2327
Original file line number Diff line number Diff line change @@ -37,6 +37,20 @@ public function testItAdvancesTimeBySeconds(): void
3737 );
3838 }
3939
40+ public function testItAdvancesTimeByDateInterval (): void
41+ {
42+ $ initialTime = new \DateTime ('2023-10-01 12:00:00 ' );
43+ $ clock = new SettableClock ($ initialTime );
44+
45+ $ clock ->advance (new \DateInterval ('PT1H ' )); // 1 hour
46+
47+ $ this ->assertEquals (
48+ new \DateTimeImmutable ('2023-10-01 13:00:00 ' ),
49+ $ clock ->now (),
50+ 'Clock should advance by the specified seconds ' ,
51+ );
52+ }
53+
4054 public function testItCanAdvanceMultipleTimes (): void
4155 {
4256 $ initialTime = new \DateTime ('2023-10-01 12:00:00 ' );
You can’t perform that action at this time.
0 commit comments