Skip to content

Commit 3af59fc

Browse files
committed
Turn DelayedUTCClock into DelayedClock
1 parent 420fb5b commit 3af59fc

3 files changed

Lines changed: 32 additions & 34 deletions

File tree

src/Clock/DelayedClock.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
}

src/Clock/DelayedUTCClock.php

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,28 @@
55
namespace Recruiter\Clock;
66

77
use PHPUnit\Framework\Attributes\CoversClass;
8-
use PHPUnit\Framework\Attributes\UsesClass;
98
use PHPUnit\Framework\MockObject\Exception;
109
use 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
}

0 commit comments

Comments
 (0)