14
14
use PHPUnit \Framework \TestCase ;
15
15
use Symfony \Component \Clock \NativeClock ;
16
16
17
+ /**
18
+ * @group time-sensitive
19
+ */
17
20
class NativeClockTest extends TestCase
18
21
{
19
22
public function testConstruct ()
@@ -32,14 +35,14 @@ public function testConstruct()
32
35
public function testNow ()
33
36
{
34
37
$ clock = new NativeClock ();
35
- $ before = new \ DateTimeImmutable ( );
38
+ $ before = microtime ( true );
36
39
usleep (10 );
37
40
$ now = $ clock ->now ();
38
41
usleep (10 );
39
- $ after = new \ DateTimeImmutable ( );
42
+ $ after = microtime ( true );
40
43
41
- $ this ->assertGreaterThan ($ before , $ now );
42
- $ this ->assertLessThan ($ after , $ now );
44
+ $ this ->assertGreaterThan ($ before , ( float ) $ now-> format ( ' U.u ' ) );
45
+ $ this ->assertLessThan ($ after , ( float ) $ now-> format ( ' U.u ' ) );
43
46
}
44
47
45
48
public function testSleep ()
@@ -53,7 +56,7 @@ public function testSleep()
53
56
usleep (10 );
54
57
$ after = microtime (true );
55
58
56
- $ this ->assertGreaterThan ($ before + 1.5 , $ now );
59
+ $ this ->assertSame ($ before + 1.5 , $ now );
57
60
$ this ->assertLessThan ($ after , $ now );
58
61
$ this ->assertLessThan (1.9 , $ now - $ before );
59
62
$ this ->assertSame ($ tz , $ clock ->now ()->getTimezone ()->getName ());
0 commit comments