|
4 | 4 |
|
5 | 5 | namespace Clock; |
6 | 6 |
|
| 7 | +use Recruiter\DateTime\UTCDateTime; |
7 | 8 | use PHPUnit\Framework\Attributes\CoversClass; |
| 9 | +use PHPUnit\Framework\Attributes\UsesClass; |
8 | 10 | use PHPUnit\Framework\TestCase; |
9 | 11 | use Recruiter\Clock\FixedClock; |
| 12 | +use Recruiter\Clock\PsrMicrotimeClock; |
| 13 | +use Recruiter\Clock\PsrUTCClock; |
10 | 14 |
|
11 | 15 | #[CoversClass(FixedClock::class)] |
| 16 | +#[UsesClass(PsrMicrotimeClock::class)] |
| 17 | +#[UsesClass(PsrUTCClock::class)] |
| 18 | +#[UsesClass(UTCDateTime::class)] |
12 | 19 | class FixedClockTest extends TestCase |
13 | 20 | { |
14 | 21 | public function testItReturnsFixedTime(): void |
@@ -57,4 +64,28 @@ public function testFromIso8601(): void |
57 | 64 | 'Clock should return the fixed time from ISO 8601 string', |
58 | 65 | ); |
59 | 66 | } |
| 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 | + } |
60 | 91 | } |
0 commit comments