File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Recruiter \Clock ;
6+
7+ use Symfony \Component \Clock \ClockInterface ;
8+
9+ class DelayedClock extends AbstractClock
10+ {
11+ use SymfonySupport;
12+
13+ private readonly \DateInterval $ delay ;
14+
15+ public function __construct (ClockInterface $ wrapped , int $ delayInSeconds )
16+ {
17+ $ this ->wrapped = $ wrapped ;
18+ $ this ->delay = new \DateInterval ("PT {$ delayInSeconds }S " );
19+ }
20+
21+ public function now (): \DateTimeImmutable
22+ {
23+ return $ this ->wrapped ->now ()->sub ($ this ->delay );
24+ }
25+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 55namespace Recruiter \Clock ;
66
77use PHPUnit \Framework \Attributes \CoversClass ;
8- use PHPUnit \Framework \Attributes \UsesClass ;
98use PHPUnit \Framework \MockObject \Exception ;
109use PHPUnit \Framework \TestCase ;
11- use Recruiter \DateTime \UTCDateTime ;
12- use Recruiter \UTCClock ;
10+ use Symfony \Component \Clock \ClockInterface ;
1311
14- #[CoversClass(DelayedUTCClock::class)]
15- #[UsesClass(UTCDateTime::class)]
16- class DelayedUTCClockTest extends TestCase
12+ #[CoversClass(DelayedClock::class)]
13+ class DelayedClockTest extends TestCase
1714{
1815 /**
1916 * @throws Exception
2017 */
2118 public function testGivesATimeAFewSecondsInThePast (): void
2219 {
23- $ original = $ this ->createMock (UTCClock ::class);
24- $ clock = new DelayedUTCClock ($ original , 10 );
20+ $ original = $ this ->createMock (ClockInterface ::class);
21+ $ clock = new DelayedClock ($ original , 10 );
2522
2623 $ original ->expects ($ this ->once ())
2724 ->method ('now ' )
28- ->willReturn (UTCDateTime:: fromTimestamp ( 10000018 ))
25+ ->willReturn (\DateTimeImmutable:: createFromFormat ( ' U ' , ' 10000018 ' ))
2926 ;
3027
3128 $ this ->assertEquals (
32- UTCDateTime:: fromTimestamp ( 10000008 ),
29+ \DateTimeImmutable:: createFromFormat ( ' U ' , ' 10000008 ' ),
3330 $ clock ->now (),
3431 );
3532 }
You can’t perform that action at this time.
0 commit comments