Skip to content

Commit

Permalink
Fix flaky TickingMockClock tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marmichalski committed Nov 18, 2023
1 parent 553b9ff commit 46bfdfd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 0 additions & 2 deletions tests/support/TickingTimeAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public static function assertDateTimeLessThanOneSecondAfter(
\DateTimeInterface $expected,
\DateTimeInterface $actual
): void {
Assert::assertNotSame($expected->format('Y-m-d\TH:i:s.u'), $actual->format('Y-m-d\TH:i:s.u'));
Assert::assertGreaterThan($expected, $actual);
Assert::assertLessThan(1, $actual->format('U.u') - $expected->format('U.u'));
}
}
4 changes: 4 additions & 0 deletions tests/unit/TickingMockClockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public function it_returns_time_that_has_ticked(): void
// Immutable variant.

$sample1 = $clock->now();
\usleep(0);
$sample2 = $clock->now();
\usleep(0);
$sample3 = $clock->now();

$this->assertNotSame($sample1->format($timeFormat), $sample2->format($timeFormat));
Expand All @@ -46,7 +48,9 @@ public function it_returns_time_that_has_ticked(): void
// Mutable variant.

$sample1 = $clock->nowMutable();
\usleep(0);
$sample2 = $clock->nowMutable();
\usleep(0);
$sample3 = $clock->nowMutable();

$this->assertNotSame($sample1->format($timeFormat), $sample2->format($timeFormat));
Expand Down

0 comments on commit 46bfdfd

Please sign in to comment.