forked from clue/reactphp-connection-manager-extra
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectionManagerConcurrentTest.php
More file actions
65 lines (47 loc) · 2.62 KB
/
ConnectionManagerConcurrentTest.php
File metadata and controls
65 lines (47 loc) · 2.62 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
<?php
namespace ConnectionManager\Tests\Extra\Multiple;
use ConnectionManager\Extra\Multiple\ConnectionManagerConcurrent;
use React\Promise;
use ConnectionManager\Tests\Extra\TestCase;
class ConnectionManagerConcurrentTest extends TestCase
{
public function testEmptyListsThrows()
{
$this->setExpectedException("InvalidArgumentException");
new ConnectionManagerConcurrent(array());
}
public function testWillForwardToInnerConnector()
{
$pending = new Promise\Promise(function() { });
$only = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$only->expects($this->once())->method('connect')->with('google.com:80')->willReturn($pending);
$connector = new ConnectionManagerConcurrent(array($only));
$promise = $connector->connect('google.com:80');
$promise->then($this->expectCallableNever(), $this->expectCallableNever());
}
public function testWillCancelOtherIfOneResolves()
{
$resolved = Promise\resolve($this->getMockBuilder('React\Stream\DuplexStreamInterface')->getMock());
$first = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$first->expects($this->once())->method('connect')->with('google.com:80')->willReturn($resolved);
$pending = new Promise\Promise(function() { }, $this->expectCallableOnce());
$second = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$second->expects($this->once())->method('connect')->with('google.com:80')->willReturn($pending);
$connector = new ConnectionManagerConcurrent(array($first, $second));
$promise = $connector->connect('google.com:80');
$this->assertPromiseResolve($promise);
}
public function testWillCloseOtherIfOneResolves()
{
$resolved = Promise\resolve($this->getMockBuilder('React\Stream\DuplexStreamInterface')->getMock());
$first = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$first->expects($this->once())->method('connect')->with('google.com:80')->willReturn($resolved);
$slower = $this->getMockBuilder('React\Stream\DuplexStreamInterface')->getMock();
$slower->expects($this->once())->method('close');
$second = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$second->expects($this->once())->method('connect')->with('google.com:80')->willReturn(Promise\resolve($slower));
$connector = new ConnectionManagerConcurrent(array($first, $second));
$promise = $connector->connect('google.com:80');
$this->assertPromiseResolve($promise);
}
}