8000 Fix `sleep()` in `MockClock` · symfony/symfony@f1a80b0 · GitHub
[go: up one dir, main page]

Skip to content

Commit f1a80b0

Browse files
committed
Fix sleep() in MockClock
1 parent 4f20ec6 commit f1a80b0

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/Symfony/Component/Clock/MockClock.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ public function sleep(float|int $seconds): void
4242
{
4343
$now = explode('.', $this->now->format('U.u'));
4444

45-
if (0 < $s = (int) $seconds) {
45+
if (0 < $s = floor($seconds)) {
4646
$now[0] += $s;
4747
}
4848

49-
if (0 < ($us = $seconds - $s) && 1E6 <= $now[1] += $us * 1E6) {
49+
if (0 < ($us = $seconds - $s) && 1E6 <= $now[1] += round($us * 1E6)) {
5050
++$now[0];
5151
$now[1] -= 1E6;
5252
}

src/Symfony/Component/Clock/Tests/MockClockTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ public function testNow()
5555

5656
public function testSleep()
5757
{
58-
$clock = new MockClock((new \DateTimeImmutable('@123.456'))->setTimezone(new \DateTimeZone('UTC')));
58+
$clock = new MockClock((new \DateTimeImmutable('2112-09-17 23:53:00.999Z'))->setTimezone(new \DateTimeZone('UTC')));
5959
$tz = $clock->now()->getTimezone()->getName();
6060

61-
$clock->sleep(4.999);
62-
$this->assertSame('128.455000', $clock->now()->format('U.u'));
61+
$clock->sleep(2.002001);
62+
$this->assertSame('2112-09-17 23:53:03.001001', $clock->now()->format('Y-m-d H:i:s.u'));
6363
$this->assertSame($tz, $clock->now()->getTimezone()->getName());
6464
}
6565

0 commit comments

Comments
 (0)
0