@@ -75,22 +75,54 @@ public function testPingWillRejectWhenUnderlyingClientRejectsPing()
75
75
$ promise ->then (null , $ this ->expectCallableOnceWith ($ error ));
76
76
}
77
77
78
- public function testPingWillRejectAndEmitErrorAndCloseWhenFactoryRejectsUnderlyingClient ()
78
+ public function testPingWillRejectAndNotEmitErrorOrCloseWhenFactoryRejectsUnderlyingClient ()
79
79
{
80
80
$ error = new \RuntimeException ();
81
81
82
82
$ deferred = new Deferred ();
83
83
$ this ->factory ->expects ($ this ->once ())->method ('createClient ' )->willReturn ($ deferred ->promise ());
84
84
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 ());
87
87
88
88
$ promise = $ this ->client ->ping ();
89
89
$ deferred ->reject ($ error );
90
90
91
91
$ promise ->then (null , $ this ->expectCallableOnceWith ($ error ));
92
92
}
93
93
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
+
94
126
public function testPingAfterCloseWillRejectWithoutCreatingUnderlyingConnection ()
95
127
{
96
128
$ this ->factory ->expects ($ this ->never ())->method ('createClient ' );
@@ -144,6 +176,7 @@ public function testCloseAfterPingWillEmitCloseWithoutErrorWhenUnderlyingClientC
144
176
public function testCloseAfterPingWillCloseUnderlyingClientConnectionWhenAlreadyResolved ()
145
177
{
146
178
$ client = $ this ->getMockBuilder ('Clue\React\Redis\Client ' )->getMock ();
179
+ $ client ->expects ($ this ->once ())->method ('__call ' )->willReturn (\React \Promise \resolve ());
147
180
$ client ->expects ($ this ->once ())->method ('close ' );
148
181
149
182
$ deferred = new Deferred ();
@@ -174,39 +207,61 @@ public function testEndAfterPingWillEndUnderlyingClient()
174
207
$ this ->client ->end ();
175
208
}
176
209
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 ()
178
230
{
179
231
$ error = new \RuntimeException ();
180
232
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 ());
182
235
183
236
$ deferred = new Deferred ();
184
237
$ this ->factory ->expects ($ this ->once ())->method ('createClient ' )->willReturn ($ deferred ->promise ());
185
238
186
239
$ this ->client ->ping ();
187
240
$ deferred ->resolve ($ client );
188
241
189
- $ this ->client ->on ('error ' , $ this ->expectCallableOnceWith ( $ error ));
242
+ $ this ->client ->on ('error ' , $ this ->expectCallableNever ( ));
190
243
$ client ->emit ('error ' , array ($ error ));
191
244
}
192
245
193
- public function testEmitsCloseEventWhenUnderlyingClientEmitsClose ()
246
+ public function testEmitsNoCloseEventWhenUnderlyingClientEmitsClose ()
194
247
{
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 ());
196
250
197
251
$ deferred = new Deferred ();
198
252
$ this ->factory ->expects ($ this ->once ())->method ('createClient ' )->willReturn ($ deferred ->promise ());
199
253
200
254
$ this ->client ->ping ();
201
255
$ deferred ->resolve ($ client );
202
256
203
- $ this ->client ->on ('close ' , $ this ->expectCallableOnce ());
257
+ $ this ->client ->on ('close ' , $ this ->expectCallableNever ());
204
258
$ client ->emit ('close ' );
205
259
}
206
260
207
261
public function testEmitsMessageEventWhenUnderlyingClientEmitsMessageForPubSubChannel ()
208
262
{
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 ());
210
265
211
266
$ deferred = new Deferred ();
212
267
$ this ->factory ->expects ($ this ->once ())->method ('createClient ' )->willReturn ($ deferred ->promise ());
0 commit comments