Skip to content

Commit 1b7acac

Browse files
committed
Fixed failing Test for older PHP Versions
1 parent b8da57d commit 1b7acac

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

tests/ConnectionManagerTimeoutTest.php

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?php
22

33
use ConnectionManager\Extra\ConnectionManagerReject;
4-
5-
use ConnectionManager\Extra\ConnectionManagerDelay;
64
use ConnectionManager\Extra\ConnectionManagerTimeout;
5+
use React\Promise\Deferred;
76
use React\Promise\Promise;
87

98
class ConnectionManagerTimeoutTest extends TestCase
@@ -27,18 +26,38 @@ public function testTimeoutOkay()
2726
$promise->then($this->expectCallableOnce(), $this->expectCallableNever());
2827
}
2928

30-
public function testTimeoutExpire()
29+
public function testTimeoutWillRejectPromiseWhenConnectorExceedsTimeLimit()
3130
{
32-
$will = $this->createConnectionManagerMock(true);
33-
$wont = new ConnectionManagerDelay($will, 0.2, $this->loop);
31+
$connectionPromise = new Promise(function(){});
32+
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
33+
$connector->expects($this->once())->method('connect')->willReturn($connectionPromise);
3434

35-
$cm = new ConnectionManagerTimeout($wont, 0.1, $this->loop);
35+
$cm = new ConnectionManagerTimeout($connector, 0.1, $this->loop);
36+
37+
$promise = $cm->connect('www.google.com:80');
38+
$this->assertInstanceOf('React\Promise\PromiseInterface', $promise);
39+
40+
$this->loop->run();
41+
$promise->then($this->expectCallableNever(), $this->expectCallableOnce());
42+
}
43+
44+
public function testTimeoutWillEndConnectiontWhenConnectorResolvesAfterTimeoutFired()
45+
{
46+
$connectionDeferred = new Deferred();
47+
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
48+
$connector->expects($this->once())->method('connect')->willReturn($connectionDeferred->promise());
49+
50+
$cm = new ConnectionManagerTimeout($connector, 0.1, $this->loop);
3651

3752
$promise = $cm->connect('www.google.com:80');
3853
$this->assertInstanceOf('React\Promise\PromiseInterface', $promise);
3954

4055
$this->loop->run();
4156
$promise->then($this->expectCallableNever(), $this->expectCallableOnce());
57+
58+
$connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock();
59+
$connection->expects($this->once())->method('end');
60+
$connectionDeferred->resolve($connection);
4261
}
4362

4463
public function testTimeoutAbort()

0 commit comments

Comments
 (0)