forked from clue/reactphp-connection-manager-extra
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectionManagerDelayTest.php
More file actions
66 lines (50 loc) · 1.93 KB
/
ConnectionManagerDelayTest.php
File metadata and controls
66 lines (50 loc) · 1.93 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
namespace ConnectionManager\Tests\Extra;
use ConnectionManager\Extra\ConnectionManagerDelay;
use React\EventLoop\Loop;
class ConnectionManagerDelayTest extends TestCase
{
private $loop;
/**
* @before
*/
public function setUpLoop()
{
$this->loop = Loop::get();
}
public function testConstructWithoutLoopAssignsLoopAutomatically()
{
$unused = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$cm = new ConnectionManagerDelay($unused, 0);
$ref = new \ReflectionProperty($cm, 'loop');
if (PHP_VERSION_ID < 80100) {
$ref->setAccessible(true);
}
$loop = $ref->getValue($cm);
$this->assertInstanceOf('React\EventLoop\LoopInterface', $loop);
}
public function testContructorThrowsExceptionForInvalidLoop()
{
$unused = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$this->setExpectedException('InvalidArgumentException', 'Argument #3 ($loop) expected null|React\EventLoop\LoopInterface');
new ConnectionManagerDelay($unused, 0, 'loop');
}
public function testDelayTenth()
{
$will = $this->createConnectionManagerMock(true);
$cm = new ConnectionManagerDelay($will, 0.1, $this->loop);
$promise = $cm->connect('www.google.com:80');
$this->assertInstanceOf('React\Promise\PromiseInterface', $promise);
Loop::run();
$promise->then($this->expectCallableOnce(), $this->expectCallableNever());
}
public function testCancellationOfPromiseBeforeDelayDoesNotStartConnection()
{
$unused = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$unused->expects($this->never())->method('connect');
$cm = new ConnectionManagerDelay($unused, 1.0, $this->loop);
$promise = $cm->connect('www.google.com:80');
$promise->cancel();
Loop::run();
}
}