Skip to content

Commit 43fc3f9

Browse files
committed
Replace unreliable functional test with simpler unit tests
1 parent 53f3cf1 commit 43fc3f9

2 files changed

Lines changed: 42 additions & 16 deletions

File tree

tests/IntegrationTest.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -167,20 +167,4 @@ public function testSelfSignedResolvesIfVerificationIsDisabled()
167167
// if we reach this, then everything is good
168168
$this->assertNull(null);
169169
}
170-
171-
public function testCancelPendingConnection()
172-
{
173-
$loop = Factory::create();
174-
175-
$connector = new TcpConnector($loop);
176-
$pending = $connector->connect('8.8.8.8:80');
177-
178-
$loop->addTimer(0.001, function () use ($pending) {
179-
$pending->cancel();
180-
});
181-
182-
$pending->then($this->expectCallableNever(), $this->expectCallableOnce());
183-
184-
$loop->run();
185-
}
186170
}

tests/TcpConnectorTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,24 @@ public function connectionToEmptyPortShouldFail()
2424
$loop->run();
2525
}
2626

27+
/** @test */
28+
public function connectionToTcpServerShouldAddResourceToLoop()
29+
{
30+
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
31+
$connector = new TcpConnector($loop);
32+
33+
$server = new TcpServer(0, $loop);
34+
35+
$valid = false;
36+
$loop->expects($this->once())->method('addWriteStream')->with($this->callback(function ($arg) use (&$valid) {
37+
$valid = is_resource($arg);
38+
return true;
39+
}));
40+
$connector->connect($server->getAddress());
41+
42+
$this->assertTrue($valid);
43+
}
44+
2745
/** @test */
2846
public function connectionToTcpServerShouldSucceed()
2947
{
@@ -196,6 +214,30 @@ public function connectionToInvalidSchemeShouldFailImmediately()
196214
);
197215
}
198216

217+
/** @test */
218+
public function cancellingConnectionShouldRemoveResourceFromLoopAndCloseResource()
219+
{
220+
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
221+
$connector = new TcpConnector($loop);
222+
223+
$server = new TcpServer(0, $loop);
224+
225+
$loop->expects($this->once())->method('addWriteStream');
226+
$promise = $connector->connect($server->getAddress());
227+
228+
$resource = null;
229+
$valid = false;
230+
$loop->expects($this->once())->method('removeWriteStream')->with($this->callback(function ($arg) use (&$resource, &$valid) {
231+
$resource = $arg;
232+
$valid = is_resource($arg);
233+
return true;
234+
}));
235+
$promise->cancel();
236+
237+
$this->assertTrue($valid);
238+
$this->assertFalse(is_resource($resource));
239+
}
240+
199241
/** @test */
200242
public function cancellingConnectionShouldRejectPromise()
201243
{

0 commit comments

Comments
 (0)