@@ -75,22 +75,54 @@ public function testPingWillRejectWhenUnderlyingClientRejectsPing()
7575 $ promise ->then (null , $ this ->expectCallableOnceWith ($ error ));
7676 }
7777
78- public function testPingWillRejectAndEmitErrorAndCloseWhenFactoryRejectsUnderlyingClient ()
78+ public function testPingWillRejectAndNotEmitErrorOrCloseWhenFactoryRejectsUnderlyingClient ()
7979 {
8080 $ error = new \RuntimeException ();
8181
8282 $ deferred = new Deferred ();
8383 $ this ->factory ->expects ($ this ->once ())->method ('createClient ' )->willReturn ($ deferred ->promise ());
8484
85- $ this ->client ->on ('error ' , $ this ->expectCallableOnceWith ( $ error ));
86- $ this ->client ->on ('close ' , $ this ->expectCallableOnce ());
85+ $ this ->client ->on ('error ' , $ this ->expectCallableNever ( ));
86+ $ this ->client ->on ('close ' , $ this ->expectCallableNever ());
8787
8888 $ promise = $ this ->client ->ping ();
8989 $ deferred ->reject ($ error );
9090
9191 $ promise ->then (null , $ this ->expectCallableOnceWith ($ error ));
9292 }
9393
94+ public function testPingAfterPreviousFactoryRejectsUnderlyingClientWillCreateNewUnderlyingConnection ()
95+ {
96+ $ error = new \RuntimeException ();
97+
98+ $ deferred = new Deferred ();
99+ $ this ->factory ->expects ($ this ->exactly (2 ))->method ('createClient ' )->willReturnOnConsecutiveCalls (
100+ $ deferred ->promise (),
101+ new Promise (function () { })
102+ );
103+
104+ $ this ->client ->ping ();
105+ $ deferred ->reject ($ error );
106+
107+ $ this ->client ->ping ();
108+ }
109+
110+ public function testPingAfterPreviousUnderlyingClientAlreadyClosedWillCreateNewUnderlyingConnection ()
111+ {
112+ $ client = $ this ->getMockBuilder ('Clue\React\Redis\StreamingClient ' )->disableOriginalConstructor ()->setMethods (array ('__call ' ))->getMock ();
113+ $ client ->expects ($ this ->once ())->method ('__call ' )->with ('ping ' )->willReturn (\React \Promise \resolve ('PONG ' ));
114+
115+ $ this ->factory ->expects ($ this ->exactly (2 ))->method ('createClient ' )->willReturnOnConsecutiveCalls (
116+ \React \Promise \resolve ($ client ),
117+ new Promise (function () { })
118+ );
119+
120+ $ this ->client ->ping ();
121+ $ client ->emit ('close ' );
122+
123+ $ this ->client ->ping ();
124+ }
125+
94126 public function testPingAfterCloseWillRejectWithoutCreatingUnderlyingConnection ()
95127 {
96128 $ this ->factory ->expects ($ this ->never ())->method ('createClient ' );
@@ -144,6 +176,7 @@ public function testCloseAfterPingWillEmitCloseWithoutErrorWhenUnderlyingClientC
144176 public function testCloseAfterPingWillCloseUnderlyingClientConnectionWhenAlreadyResolved ()
145177 {
146178 $ client = $ this ->getMockBuilder ('Clue\React\Redis\Client ' )->getMock ();
179+ $ client ->expects ($ this ->once ())->method ('__call ' )->willReturn (\React \Promise \resolve ());
147180 $ client ->expects ($ this ->once ())->method ('close ' );
148181
149182 $ deferred = new Deferred ();
@@ -174,39 +207,61 @@ public function testEndAfterPingWillEndUnderlyingClient()
174207 $ this ->client ->end ();
175208 }
176209
177- public function testEmitsErrorEventWhenUnderlyingClientEmitsError ()
210+ public function testEndAfterPingWillCloseClientWhenUnderlyingClientEmitsClose ()
211+ {
212+ $ client = $ this ->getMockBuilder ('Clue\React\Redis\StreamingClient ' )->disableOriginalConstructor ()->setMethods (array ('__call ' , 'end ' ))->getMock ();
213+ //$client = $this->getMockBuilder('Clue\React\Redis\Client')->getMock();
214+ $ client ->expects ($ this ->once ())->method ('__call ' )->with ('ping ' )->willReturn (\React \Promise \resolve ('PONG ' ));
215+ $ client ->expects ($ this ->once ())->method ('end ' );
216+
217+ $ deferred = new Deferred ();
218+ $ this ->factory ->expects ($ this ->once ())->method ('createClient ' )->willReturn ($ deferred ->promise ());
219+
220+ $ this ->client ->ping ();
221+ $ deferred ->resolve ($ client );
222+
223+ $ this ->client ->on ('close ' , $ this ->expectCallableOnce ());
224+ $ this ->client ->end ();
225+
226+ $ client ->emit ('close ' );
227+ }
228+
229+ public function testEmitsNoErrorEventWhenUnderlyingClientEmitsError ()
178230 {
179231 $ error = new \RuntimeException ();
180232
181- $ client = $ this ->getMockBuilder ('Clue\React\Redis\StreamingClient ' )->disableOriginalConstructor ()->setMethods (array ('close ' ))->getMock ();
233+ $ client = $ this ->getMockBuilder ('Clue\React\Redis\StreamingClient ' )->disableOriginalConstructor ()->setMethods (array ('__call ' ))->getMock ();
234+ $ client ->expects ($ this ->once ())->method ('__call ' )->willReturn (\React \Promise \resolve ());
182235
183236 $ deferred = new Deferred ();
184237 $ this ->factory ->expects ($ this ->once ())->method ('createClient ' )->willReturn ($ deferred ->promise ());
185238
186239 $ this ->client ->ping ();
187240 $ deferred ->resolve ($ client );
188241
189- $ this ->client ->on ('error ' , $ this ->expectCallableOnceWith ( $ error ));
242+ $ this ->client ->on ('error ' , $ this ->expectCallableNever ( ));
190243 $ client ->emit ('error ' , array ($ error ));
191244 }
192245
193- public function testEmitsCloseEventWhenUnderlyingClientEmitsClose ()
246+ public function testEmitsNoCloseEventWhenUnderlyingClientEmitsClose ()
194247 {
195- $ client = $ this ->getMockBuilder ('Clue\React\Redis\StreamingClient ' )->disableOriginalConstructor ()->setMethods (array ('close ' ))->getMock ();
248+ $ client = $ this ->getMockBuilder ('Clue\React\Redis\StreamingClient ' )->disableOriginalConstructor ()->setMethods (array ('__call ' ))->getMock ();
249+ $ client ->expects ($ this ->once ())->method ('__call ' )->willReturn (\React \Promise \resolve ());
196250
197251 $ deferred = new Deferred ();
198252 $ this ->factory ->expects ($ this ->once ())->method ('createClient ' )->willReturn ($ deferred ->promise ());
199253
200254 $ this ->client ->ping ();
201255 $ deferred ->resolve ($ client );
202256
203- $ this ->client ->on ('close ' , $ this ->expectCallableOnce ());
257+ $ this ->client ->on ('close ' , $ this ->expectCallableNever ());
204258 $ client ->emit ('close ' );
205259 }
206260
207261 public function testEmitsMessageEventWhenUnderlyingClientEmitsMessageForPubSubChannel ()
208262 {
209- $ client = $ this ->getMockBuilder ('Clue\React\Redis\StreamingClient ' )->disableOriginalConstructor ()->setMethods (array ('close ' ))->getMock ();
263+ $ client = $ this ->getMockBuilder ('Clue\React\Redis\StreamingClient ' )->disableOriginalConstructor ()->setMethods (array ('__call ' ))->getMock ();
264+ $ client ->expects ($ this ->once ())->method ('__call ' )->willReturn (\React \Promise \resolve ());
210265
211266 $ deferred = new Deferred ();
212267 $ this ->factory ->expects ($ this ->once ())->method ('createClient ' )->willReturn ($ deferred ->promise ());
0 commit comments