Skip to content

Commit 49cd395

Browse files
authored
Merge pull request repejota#81 from repejota/fixtests
Fixtests
2 parents e3d01f0 + df281b0 commit 49cd395

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

spec/Nats/ConnectionOptionsSpec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function it_has_default_lang_value_as_php() {
3333
}
3434

3535
function it_has_default_version_value_as_null() {
36-
$this->getVersion()->shouldEqual("0.0.5");
36+
$this->getVersion()->shouldEqual("0.7.2");
3737
}
3838

3939
function it_has_default_verbose_value_as_null() {

src/Nats/Connection.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,16 @@ private function receive($len = null)
190190
* @return resource
191191
* @throws \Exception Exception raised if connection fails.
192192
*/
193-
private function getStream($address)
193+
private function getStream($address, $timeout)
194194
{
195195
$errno = null;
196196
$errstr = null;
197197

198-
$fp = stream_socket_client($address, $errno, $errstr, null, STREAM_CLIENT_CONNECT);
198+
$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);
199203

200204
if (!$fp) {
201205
throw new \Exception($errstr, $errno);
@@ -229,7 +233,7 @@ public function connect($timeout = null)
229233
}
230234

231235
$this->timeout = $timeout;
232-
$this->streamSocket = $this->getStream($this->options->getAddress());
236+
$this->streamSocket = $this->getStream($this->options->getAddress(), $timeout);
233237
$this->setStreamTimeout($timeout);
234238

235239
$msg = 'CONNECT '.$this->options;

test/ConnectionOptionsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function testSettersAndGettersWithoutCredentials()
7474
public function testStringRepresentation()
7575
{
7676
$options = new ConnectionOptions();
77-
$this->assertEquals("{\"lang\":\"php\",\"version\":\"0.0.5\",\"verbose\":false,\"pedantic\":false}", $options->__toString());
77+
$this->assertEquals("{\"lang\":\"php\",\"version\":\"0.7.2\",\"verbose\":false,\"pedantic\":false}", $options->__toString());
7878
}
7979

8080
/**
@@ -87,6 +87,6 @@ public function testStringRepresentationWithCredentials()
8787
$options = new ConnectionOptions();
8888
$options->setUser("username");
8989
$options->setPass("password");
90-
$this->assertEquals("{\"lang\":\"php\",\"version\":\"0.0.5\",\"verbose\":false,\"pedantic\":false,\"user\":\"username\",\"pass\":\"password\"}", $options->__toString());
90+
$this->assertEquals("{\"lang\":\"php\",\"version\":\"0.7.2\",\"verbose\":false,\"pedantic\":false,\"user\":\"username\",\"pass\":\"password\"}", $options->__toString());
9191
}
9292
}

test/ConnectionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ function ($message) {
128128
public function testLargeRequest()
129129
{
130130

131-
$content = file_get_contents(dirname(__FILE__).'/test.pdf');
132-
131+
$content = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 51200);
132+
133133
$contentLen = strlen($content);
134134

135135
$contentSum = md5($content);

0 commit comments

Comments
 (0)