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

Commit 453ed56

Browse files
committed
Merge branch 'release/0.6.0'
2 parents 6cf2682 + e4b45e8 commit 453ed56

4 files changed

Lines changed: 40 additions & 14 deletions

File tree

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ Introduction
1616

1717
A PHP client for the [NATS messaging system](https://nats.io).
1818

19-
> Note: phpnats is under heavy development.
20-
2119
Requirements
2220
------------
2321

24-
* php ~5.4
22+
* php 5.4+
2523
* [nats](https://github.com/derekcollison/nats) or [gnatsd](https://github.com/apcera/gnatsd)
2624

2725

@@ -68,7 +66,7 @@ $callback = function($payload)
6866
};
6967
$client->subscribe("foo", $callback);
7068

71-
# Request
69+
# Request
7270
$c->request('sayhello', 'Marty McFly', function ($response) {
7371
echo $response->getBody();
7472
});

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.5.0
1+
0.6.0

src/Connection.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ private function getStream($address, $timeout = null)
186186
}
187187
$errno = null;
188188
$errstr = null;
189-
//$fp = stream_socket_client($address, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT);
190189

191190
$fp = $this->streamWrapper->getStreamSocketClient($address, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT);
192191

@@ -221,6 +220,17 @@ public function connect($timeout = null)
221220
$this->streamSocket = $this->getStream($this->options->getAddress(), $timeout);
222221
$msg = 'CONNECT '.$this->options;
223222
$this->send($msg);
223+
224+
$response = $this->receive();
225+
226+
$this->ping();
227+
$response = $this->receive();
228+
229+
if ($response !== "PONG") {
230+
if (strpos($response, '-ERR')!== false) {
231+
throw new \Exception("Failing connection: $response");
232+
}
233+
}
224234
}
225235

226236
/**
@@ -333,6 +343,9 @@ private function handleMSG($line)
333343
if (count($parts) == 5) {
334344
$length = $parts[5];
335345
$subject = $parts[3];
346+
} elseif (count($parts) == 4) {
347+
$length = $parts[3];
348+
$subject = $parts[1];
336349
}
337350

338351
$payload = $this->receive($length);

tests/Unit/ConnectionTest.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
use Nats;
55
use Nats\ConnectionOptions;
66
use Nats\StreamWrapper;
7-
use org\bovigo\vfs\vfsStream;
8-
use org\bovigo\vfs\vfsStreamFile;
97
use Prophecy\Argument;
108

119
/**
@@ -43,20 +41,36 @@ class ConnectionTest extends \PHPUnit_Framework_TestCase
4341
public function setUp()
4442
{
4543
$options = new ConnectionOptions();
44+
$streamWrapper = $this->getMockStreamSocketClient();
4645

46+
$this->c = new Nats\Connection($options);
47+
$this->c->setStreamWrapper($streamWrapper->reveal());
48+
$this->c->connect();
49+
}
50+
51+
/**
52+
* Function for building Socket Mock.
53+
*
54+
* @return StreamWrapper
55+
*/
56+
private function getMockStreamSocketClient()
57+
{
4758
$streamWrapper = $this->prophesize("Nats\StreamWrapper");
59+
$streamWrapper->setStreamTimeout(Argument::any(), Argument::any())->willReturn(true);
4860
$streamWrapper->getStreamSocketClient(Argument::any(), Argument::any(), Argument::any(), Argument::any(), Argument::any())->will(function ($args) {
49-
return fopen("/tmp/".uniqid(), 'w');
61+
$fileName = "/tmp/".uniqid();
62+
$f = fopen($fileName, 'w');
63+
fwrite($f, "INFO: \n");
64+
fwrite($f, "-ERR \n");
5065

51-
});
66+
return $f;
5267

53-
$streamWrapper->setStreamTimeout(Argument::any(), Argument::any())->willReturn(true);
68+
});
5469

55-
$this->c = new Nats\Connection($options);
56-
$this->c->setStreamWrapper($streamWrapper->reveal());
57-
$this->c->connect();
70+
return $streamWrapper;
5871
}
5972

73+
6074
/**
6175
* Test Connection.
6276
*
@@ -73,6 +87,7 @@ public function testConnection()
7387
$this->assertFalse($this->c->isConnected());
7488
}
7589

90+
7691
/**
7792
* Test Ping command.
7893
*

0 commit comments

Comments
 (0)