Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Commit 82a139b

Browse files
authored
Merge pull request repejota#87 from Rentlio/develop
Suppress warnings on stream_socket_client
2 parents d1fc1da + 6890b6a commit 82a139b

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

src/Nats/Connection.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,19 @@ private function getStream($address, $timeout)
195195
$errno = null;
196196
$errstr = null;
197197

198+
set_error_handler(function(){return true;});
198199
$fp = stream_socket_client($address, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT);
199-
$timeout = number_format($timeout, 3);
200-
$seconds = floor($timeout);
201-
$microseconds = ($timeout - $seconds) * 1000;
202-
stream_set_timeout($fp, $seconds, $microseconds);
200+
restore_error_handler();
203201

204202
if (!$fp) {
205203
throw new \Exception($errstr, $errno);
206204
}
207205

206+
$timeout = number_format($timeout, 3);
207+
$seconds = floor($timeout);
208+
$microseconds = ($timeout - $seconds) * 1000;
209+
stream_set_timeout($fp, $seconds, $microseconds);
210+
208211
return $fp;
209212
}
210213

test/ConnectionTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,23 @@ function ($res) {
205205

206206
$this->assertTrue(true);
207207
}
208+
209+
210+
/**
211+
* Test Connecting when nats server is not available
212+
*
213+
* @return void
214+
*/
215+
public function testRefusedConnection()
216+
{
217+
$this->setExpectedException(\Exception::class);
218+
219+
$options = new ConnectionOptions();
220+
$options->setHost('localhost');
221+
$options->setPort(4223);
222+
223+
$c = new Nats\Connection($options);
224+
$c->connect();
225+
$this->assertFalse($this->c->isConnected());
226+
}
208227
}

0 commit comments

Comments
 (0)