From ba03d8340960fbe4da779de23d2a1b088540202c Mon Sep 17 00:00:00 2001 From: "Jonathan H. Wage" Date: Tue, 7 Jan 2014 16:13:10 -0500 Subject: [PATCH] Allow ErrorException to be thrown when stream_socket_client() fails to connect. --- src/JWage/APNS/SocketClient.php | 2 +- tests/JWage/APNS/Tests/SocketClientTest.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/JWage/APNS/SocketClient.php b/src/JWage/APNS/SocketClient.php index 3a7f6be..0b3a125 100644 --- a/src/JWage/APNS/SocketClient.php +++ b/src/JWage/APNS/SocketClient.php @@ -98,7 +98,7 @@ protected function createStreamClient() { $address = $this->getSocketAddress(); - $client = stream_socket_client( + $client = @stream_socket_client( $address, $this->error, $this->errorString, diff --git a/tests/JWage/APNS/Tests/SocketClientTest.php b/tests/JWage/APNS/Tests/SocketClientTest.php index 857d56f..e01e6dd 100644 --- a/tests/JWage/APNS/Tests/SocketClientTest.php +++ b/tests/JWage/APNS/Tests/SocketClientTest.php @@ -36,6 +36,16 @@ public function testGetSocketAddress() { $this->assertEquals('ssl://host:1234', $this->socketClient->getTestSocketAddress()); } + + /** + * @expectedException ErrorException + * @expectedExceptionMessage Failed to create stream socket client to "ssl://somethingthatdoesnotexist:100". php_network_getaddresses: getaddrinfo failed: Name or service not known + */ + public function testConnectThrowsException() + { + $socketClient = new SocketClient($this->certificate, 'somethingthatdoesnotexist', 100); + $socketClient->write('test'); + } } class SocketClientStub extends SocketClient