77use Clue \Redis \Protocol \Model \ErrorReply ;
88use Clue \Redis \Protocol \Model \MultiBulkReply ;
99use Clue \React \Redis \Client ;
10+ use React \Stream \ThroughStream ;
1011
1112class 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