Skip to content

Commit 1badb1f

Browse files
authored
Merge pull request #65 from clue-labs/compat
Forward compatibility with upcoming Socket v1.0 and v0.8 and EventLoop v1.0 and Evenement v3
2 parents f375ea7 + 9faa1ec commit 1badb1f

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
],
1313
"require": {
1414
"php": ">=5.3",
15-
"react/event-loop": "0.3.*|0.4.*",
16-
"react/promise": "^2.0 || ^1.1",
17-
"react/socket": "^0.7",
1815
"clue/redis-protocol": "0.3.*",
19-
"evenement/evenement": "~1.0|~2.0"
16+
"evenement/evenement": "^3.0 || ^2.0 || ^1.0",
17+
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3",
18+
"react/promise": "^2.0 || ^1.1",
19+
"react/socket": "^1.0 || ^0.8 || ^0.7"
2020
},
2121
"autoload": {
2222
"psr-4": { "Clue\\React\\Redis\\": "src/" }

tests/FunctionalTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Clue\React\Redis\StreamingClient;
66
use React\Promise\Deferred;
77
use React\Stream\Stream;
8+
use React\Stream\DuplexResourceStream;
89

910
class FunctionalTest extends TestCase
1011
{
@@ -161,7 +162,7 @@ protected function createClientResponse($response)
161162
fwrite($fp, $response);
162163
fseek($fp, 0);
163164

164-
$stream = new Stream($fp, $this->loop);
165+
$stream = class_exists('React\Stream\DuplexResourceStream') ? new DuplexResourceStream($fp, $this->loop) : new Stream($fp, $this->loop);
165166

166167
return new StreamingClient($stream);
167168
}

tests/StreamingClientTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Clue\Redis\Protocol\Model\ErrorReply;
88
use Clue\Redis\Protocol\Model\MultiBulkReply;
99
use Clue\React\Redis\Client;
10+
use React\Stream\ThroughStream;
1011

1112
class StreamingClientTest extends TestCase
1213
{
@@ -17,7 +18,7 @@ class StreamingClientTest extends TestCase
1718

1819
public function setUp()
1920
{
20-
$this->stream = $this->getMockBuilder('React\Stream\Stream')->disableOriginalConstructor()->setMethods(array('write', 'close', 'resume', 'pause'))->getMock();
21+
$this->stream = $this->getMockBuilder('React\Stream\DuplexStreamInterface')->getMock();
2122
$this->parser = $this->getMockBuilder('Clue\Redis\Protocol\Parser\ParserInterface')->getMock();
2223
$this->serializer = $this->getMockBuilder('Clue\Redis\Protocol\Serializer\SerializerInterface')->getMock();
2324

@@ -34,29 +35,38 @@ public function testSending()
3435

3536
public function testClosingClientEmitsEvent()
3637
{
37-
//$this->client->on('close', $this->expectCallableOnce());
38+
$this->client->on('close', $this->expectCallableOnce());
3839

3940
$this->client->close();
4041
}
4142

4243
public function testClosingStreamClosesClient()
4344
{
45+
$this->stream = new ThroughStream();
46+
$this->client = new StreamingClient($this->stream, $this->parser, $this->serializer);
47+
4448
$this->client->on('close', $this->expectCallableOnce());
4549

4650
$this->stream->emit('close');
4751
}
4852

4953
public function testReceiveParseErrorEmitsErrorEvent()
5054
{
55+
$this->stream = new ThroughStream();
56+
$this->client = new StreamingClient($this->stream, $this->parser, $this->serializer);
57+
5158
$this->client->on('error', $this->expectCallableOnce());
52-
//$this->client->on('close', $this->expectCallableOnce());
59+
$this->client->on('close', $this->expectCallableOnce());
5360

5461
$this->parser->expects($this->once())->method('pushIncoming')->with($this->equalTo('message'))->will($this->throwException(new ParserException()));
5562
$this->stream->emit('data', array('message'));
5663
}
5764

5865
public function testReceiveThrowMessageEmitsErrorEvent()
5966
{
67+
$this->stream = new ThroughStream();
68+
$this->client = new StreamingClient($this->stream, $this->parser, $this->serializer);
69+
6070
$this->client->on('error', $this->expectCallableOnce());
6171

6272
$this->parser->expects($this->once())->method('pushIncoming')->with($this->equalTo('message'))->will($this->returnValue(array(new IntegerReply(2))));

0 commit comments

Comments
 (0)