forked from clue/reactphp-connection-manager-extra
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectionManagerRandomTest.php
More file actions
57 lines (40 loc) · 1.81 KB
/
ConnectionManagerRandomTest.php
File metadata and controls
57 lines (40 loc) · 1.81 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
<?php
namespace ConnectionManager\Tests\Extra\Multiple;
use ConnectionManager\Extra\Multiple\ConnectionManagerRandom;
use ConnectionManager\Extra\ConnectionManagerReject;
use React\Promise;
use ConnectionManager\Tests\Extra\TestCase;
class ConnectionManagerRandomTest extends TestCase
{
public function testEmptyListThrows()
{
$this->setExpectedException("InvalidArgumentException");
new ConnectionManagerRandom(array());
}
public function testReject()
{
$wont = new ConnectionManagerReject();
$cm = new ConnectionManagerRandom(array($wont));
$promise = $cm->connect('www.google.com:80');
$this->assertInstanceOf('React\Promise\PromiseInterface', $promise);
$promise->then($this->expectCallableNever(), $this->expectCallableOnce());
}
public function testWillTryAllIfEachRejects()
{
$rejected = Promise\reject(new \RuntimeException('nope'));
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$connector->expects($this->exactly(2))->method('connect')->with('google.com:80')->willReturn($rejected);
$cm = new ConnectionManagerRandom(array($connector, $connector));
$promise = $cm->connect('google.com:80');
$this->assertPromiseReject($promise);
}
public function testCancellationWillNotStartAnyFurtherConnections()
{
$pending = new Promise\Promise(function () { }, $this->expectCallableOnce());
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$connector->expects($this->once())->method('connect')->with('google.com:80')->willReturn($pending);
$cm = new ConnectionManagerRandom(array($connector, $connector));
$promise = $cm->connect('google.com:80');
$promise->cancel();
}
}