/
ClockTest.php
43 lines (32 loc) · 1.15 KB
/
ClockTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace React\Tests\Http\Io;
use PHPUnit\Framework\TestCase;
use React\Http\Io\Clock;
class ClockTest extends TestCase
{
public function testNowReturnsSameTimestampMultipleTimesInSameTick()
{
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$clock = new Clock($loop);
$now = $clock->now();
$this->assertTrue(is_float($now)); // assertIsFloat() on PHPUnit 8+
$this->assertEquals($now, $clock->now());
}
public function testNowResetsMemoizedTimestampOnFutureTick()
{
$tick = null;
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$loop->expects($this->once())->method('futureTick')->with($this->callback(function ($cb) use (&$tick) {
$tick = $cb;
return true;
}));
$clock = new Clock($loop);
$now = $clock->now();
$ref = new \ReflectionProperty($clock, 'now');
$ref->setAccessible(true);
$this->assertEquals($now, $ref->getValue($clock));
$this->assertNotNull($tick);
$tick();
$this->assertNull($ref->getValue($clock));
}
}