@@ -136,27 +136,45 @@ public function testWillWriteAuthCommandIfRedisUnixUriContainsUserInfo()
136
136
137
137
public function testWillResolveWhenAuthCommandReceivesOkResponseIfRedisUriContainsUserInfo ()
138
138
{
139
- $ stream = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('write ' ))->getMock ();
139
+ $ dataHandler = null ;
140
+ $ stream = $ this ->getMockBuilder ('React\Socket\ConnectionInterface ' )->getMock ();
140
141
$ stream ->expects ($ this ->once ())->method ('write ' )->with ("*2 \r\n$4 \r\nauth \r\n$5 \r\nworld \r\n" );
142
+ $ stream ->expects ($ this ->exactly (2 ))->method ('on ' )->withConsecutive (
143
+ array ('data ' , $ this ->callback (function ($ arg ) use (&$ dataHandler ) {
144
+ $ dataHandler = $ arg ;
145
+ return true ;
146
+ })),
147
+ array ('close ' , $ this ->anything ())
148
+ );
141
149
142
150
$ this ->connector ->expects ($ this ->once ())->method ('connect ' )->willReturn (Promise \resolve ($ stream ));
143
151
$ promise = $ this ->factory ->createClient ('redis://:world@localhost ' );
144
152
145
- $ stream ->emit ('data ' , array ("+OK \r\n" ));
153
+ $ this ->assertTrue (is_callable ($ dataHandler ));
154
+ $ dataHandler ("+OK \r\n" );
146
155
147
156
$ promise ->then ($ this ->expectCallableOnceWith ($ this ->isInstanceOf ('Clue\React\Redis\Client ' )));
148
157
}
149
158
150
159
public function testWillRejectAndCloseAutomaticallyWhenAuthCommandReceivesErrorResponseIfRedisUriContainsUserInfo ()
151
160
{
152
- $ stream = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('write ' , 'close ' ))->getMock ();
161
+ $ dataHandler = null ;
162
+ $ stream = $ this ->getMockBuilder ('React\Socket\ConnectionInterface ' )->getMock ();
153
163
$ stream ->expects ($ this ->once ())->method ('write ' )->with ("*2 \r\n$4 \r\nauth \r\n$5 \r\nworld \r\n" );
154
164
$ stream ->expects ($ this ->once ())->method ('close ' );
165
+ $ stream ->expects ($ this ->exactly (2 ))->method ('on ' )->withConsecutive (
166
+ array ('data ' , $ this ->callback (function ($ arg ) use (&$ dataHandler ) {
167
+ $ dataHandler = $ arg ;
168
+ return true ;
169
+ })),
170
+ array ('close ' , $ this ->anything ())
171
+ );
155
172
156
173
$ this ->connector ->expects ($ this ->once ())->method ('connect ' )->willReturn (Promise \resolve ($ stream ));
157
174
$ promise = $ this ->factory ->createClient ('redis://:world@localhost ' );
158
175
159
- $ stream ->emit ('data ' , array ("-ERR invalid password \r\n" ));
176
+ $ this ->assertTrue (is_callable ($ dataHandler ));
177
+ $ dataHandler ("-ERR invalid password \r\n" );
160
178
161
179
$ promise ->then (null , $ this ->expectCallableOnceWith (
162
180
$ this ->logicalAnd (
@@ -182,27 +200,45 @@ public function testWillWriteSelectCommandIfRedisUnixUriContainsDbQueryParameter
182
200
183
201
public function testWillResolveWhenSelectCommandReceivesOkResponseIfRedisUriContainsPath ()
184
202
{
185
- $ stream = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('write ' ))->getMock ();
203
+ $ dataHandler = null ;
204
+ $ stream = $ this ->getMockBuilder ('React\Socket\ConnectionInterface ' )->getMock ();
186
205
$ stream ->expects ($ this ->once ())->method ('write ' )->with ("*2 \r\n$6 \r\nselect \r\n$3 \r\n123 \r\n" );
206
+ $ stream ->expects ($ this ->exactly (2 ))->method ('on ' )->withConsecutive (
207
+ array ('data ' , $ this ->callback (function ($ arg ) use (&$ dataHandler ) {
208
+ $ dataHandler = $ arg ;
209
+ return true ;
210
+ })),
211
+ array ('close ' , $ this ->anything ())
212
+ );
187
213
188
214
$ this ->connector ->expects ($ this ->once ())->method ('connect ' )->willReturn (Promise \resolve ($ stream ));
189
215
$ promise = $ this ->factory ->createClient ('redis://localhost/123 ' );
190
216
191
- $ stream ->emit ('data ' , array ("+OK \r\n" ));
217
+ $ this ->assertTrue (is_callable ($ dataHandler ));
218
+ $ dataHandler ("+OK \r\n" );
192
219
193
220
$ promise ->then ($ this ->expectCallableOnceWith ($ this ->isInstanceOf ('Clue\React\Redis\Client ' )));
194
221
}
195
222
196
223
public function testWillRejectAndCloseAutomaticallyWhenSelectCommandReceivesErrorResponseIfRedisUriContainsPath ()
197
224
{
198
- $ stream = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('write ' , 'close ' ))->getMock ();
225
+ $ dataHandler = null ;
226
+ $ stream = $ this ->getMockBuilder ('React\Socket\ConnectionInterface ' )->getMock ();
199
227
$ stream ->expects ($ this ->once ())->method ('write ' )->with ("*2 \r\n$6 \r\nselect \r\n$3 \r\n123 \r\n" );
200
228
$ stream ->expects ($ this ->once ())->method ('close ' );
229
+ $ stream ->expects ($ this ->exactly (2 ))->method ('on ' )->withConsecutive (
230
+ array ('data ' , $ this ->callback (function ($ arg ) use (&$ dataHandler ) {
231
+ $ dataHandler = $ arg ;
232
+ return true ;
233
+ })),
234
+ array ('close ' , $ this ->anything ())
235
+ );
201
236
202
237
$ this ->connector ->expects ($ this ->once ())->method ('connect ' )->willReturn (Promise \resolve ($ stream ));
203
238
$ promise = $ this ->factory ->createClient ('redis://localhost/123 ' );
204
239
205
- $ stream ->emit ('data ' , array ("-ERR DB index is out of range \r\n" ));
240
+ $ this ->assertTrue (is_callable ($ dataHandler ));
241
+ $ dataHandler ("-ERR DB index is out of range \r\n" );
206
242
207
243
$ promise ->then (null , $ this ->expectCallableOnceWith (
208
244
$ this ->logicalAnd (
0 commit comments