Skip to content

Commit fbf5f35

Browse files
committed
Test creating invalid socket address and improve test coverage
1 parent b468654 commit fbf5f35

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/TcpConnector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public function create($ip, $port)
2525

2626
$url = $this->getSocketUrl($ip, $port);
2727

28-
$socket = stream_socket_client($url, $errno, $errstr, 0, STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT);
28+
$socket = @stream_socket_client($url, $errno, $errstr, 0, STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT);
2929

30-
if (!$socket) {
30+
if (false === $socket) {
3131
return Promise\reject(new \RuntimeException(
3232
sprintf("connection to %s:%d failed: %s", $ip, $port, $errstr),
3333
$errno

tests/TcpConnectorTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,16 @@ public function connectionToHostnameShouldFailImmediately()
9595
$this->expectCallableOnce()
9696
);
9797
}
98+
99+
/** @test */
100+
public function connectionToInvalidAddressShouldFailImmediately()
101+
{
102+
$loop = $this->getMock('React\EventLoop\LoopInterface');
103+
104+
$connector = new TcpConnector($loop);
105+
$connector->create('255.255.255.255', 12345678)->then(
106+
$this->expectCallableNever(),
107+
$this->expectCallableOnce()
108+
);
109+
}
98110
}

0 commit comments

Comments
 (0)