Skip to content

Commit 91d0979

Browse files
committed
Cover trait in FixedClockTest
1 parent a621af1 commit 91d0979

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

tests/Clock/FixedClockTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@
44

55
namespace Clock;
66

7+
use Recruiter\DateTime\UTCDateTime;
78
use PHPUnit\Framework\Attributes\CoversClass;
9+
use PHPUnit\Framework\Attributes\UsesClass;
810
use PHPUnit\Framework\TestCase;
911
use Recruiter\Clock\FixedClock;
12+
use Recruiter\Clock\PsrMicrotimeClock;
13+
use Recruiter\Clock\PsrUTCClock;
1014

1115
#[CoversClass(FixedClock::class)]
16+
#[UsesClass(PsrMicrotimeClock::class)]
17+
#[UsesClass(PsrUTCClock::class)]
18+
#[UsesClass(UTCDateTime::class)]
1219
class FixedClockTest extends TestCase
1320
{
1421
public function testItReturnsFixedTime(): void
@@ -57,4 +64,28 @@ public function testFromIso8601(): void
5764
'Clock should return the fixed time from ISO 8601 string',
5865
);
5966
}
67+
68+
public function testConversionToMicrotime(): void
69+
{
70+
$fixedTime = new \DateTimeImmutable('2023-10-01 12:00:00.123456');
71+
$clock = new FixedClock($fixedTime)->asMicrotime();
72+
73+
$this->assertEquals(
74+
1696161600.123456,
75+
$clock->current(),
76+
'Clock should convert fixed time to microtime correctly',
77+
);
78+
}
79+
80+
public function testConversionToUTC(): void
81+
{
82+
$fixedTime = new \DateTimeImmutable('2023-10-01 12:00:00', new \DateTimeZone('Europe/Berlin'));
83+
$clock = new FixedClock($fixedTime)->asUTC();
84+
85+
$this->assertEquals(
86+
UTCDateTime::fromString('2023-10-01 10:00:00'),
87+
$clock->current(),
88+
'Clock should convert fixed time to UTC correctly',
89+
);
90+
}
6091
}

0 commit comments

Comments
 (0)