7
7
use Clue \Redis \Protocol \Model \ErrorReply ;
8
8
use Clue \Redis \Protocol \Model \MultiBulkReply ;
9
9
use Clue \React \Redis \Client ;
10
+ use React \Stream \ThroughStream ;
10
11
11
12
class StreamingClientTest extends TestCase
12
13
{
@@ -17,7 +18,7 @@ class StreamingClientTest extends TestCase
17
18
18
19
public function setUp ()
19
20
{
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 ();
21
22
$ this ->parser = $ this ->getMockBuilder ('Clue\Redis\Protocol\Parser\ParserInterface ' )->getMock ();
22
23
$ this ->serializer = $ this ->getMockBuilder ('Clue\Redis\Protocol\Serializer\SerializerInterface ' )->getMock ();
23
24
@@ -34,29 +35,38 @@ public function testSending()
34
35
35
36
public function testClosingClientEmitsEvent ()
36
37
{
37
- // $this->client->on('close', $this->expectCallableOnce());
38
+ $ this ->client ->on ('close ' , $ this ->expectCallableOnce ());
38
39
39
40
$ this ->client ->close ();
40
41
}
41
42
42
43
public function testClosingStreamClosesClient ()
43
44
{
45
+ $ this ->stream = new ThroughStream ();
46
+ $ this ->client = new StreamingClient ($ this ->stream , $ this ->parser , $ this ->serializer );
47
+
44
48
$ this ->client ->on ('close ' , $ this ->expectCallableOnce ());
45
49
46
50
$ this ->stream ->emit ('close ' );
47
51
}
48
52
49
53
public function testReceiveParseErrorEmitsErrorEvent ()
50
54
{
55
+ $ this ->stream = new ThroughStream ();
56
+ $ this ->client = new StreamingClient ($ this ->stream , $ this ->parser , $ this ->serializer );
57
+
51
58
$ this ->client ->on ('error ' , $ this ->expectCallableOnce ());
52
- // $this->client->on('close', $this->expectCallableOnce());
59
+ $ this ->client ->on ('close ' , $ this ->expectCallableOnce ());
53
60
54
61
$ this ->parser ->expects ($ this ->once ())->method ('pushIncoming ' )->with ($ this ->equalTo ('message ' ))->will ($ this ->throwException (new ParserException ()));
55
62
$ this ->stream ->emit ('data ' , array ('message ' ));
56
63
}
57
64
58
65
public function testReceiveThrowMessageEmitsErrorEvent ()
59
66
{
67
+ $ this ->stream = new ThroughStream ();
68
+ $ this ->client = new StreamingClient ($ this ->stream , $ this ->parser , $ this ->serializer );
69
+
60
70
$ this ->client ->on ('error ' , $ this ->expectCallableOnce ());
61
71
62
72
$ this ->parser ->expects ($ this ->once ())->method ('pushIncoming ' )->with ($ this ->equalTo ('message ' ))->will ($ this ->returnValue (array (new IntegerReply (2 ))));
0 commit comments