@@ -136,27 +136,45 @@ public function testWillWriteAuthCommandIfRedisUnixUriContainsUserInfo()
136136
137137 public function testWillResolveWhenAuthCommandReceivesOkResponseIfRedisUriContainsUserInfo ()
138138 {
139- $ stream = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('write ' ))->getMock ();
139+ $ dataHandler = null ;
140+ $ stream = $ this ->getMockBuilder ('React\Socket\ConnectionInterface ' )->getMock ();
140141 $ 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+ );
141149
142150 $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->willReturn (Promise \resolve ($ stream ));
143151 $ promise = $ this ->factory ->createClient ('redis://:world@localhost ' );
144152
145- $ stream ->emit ('data ' , array ("+OK \r\n" ));
153+ $ this ->assertTrue (is_callable ($ dataHandler ));
154+ $ dataHandler ("+OK \r\n" );
146155
147156 $ promise ->then ($ this ->expectCallableOnceWith ($ this ->isInstanceOf ('Clue\React\Redis\Client ' )));
148157 }
149158
150159 public function testWillRejectAndCloseAutomaticallyWhenAuthCommandReceivesErrorResponseIfRedisUriContainsUserInfo ()
151160 {
152- $ stream = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('write ' , 'close ' ))->getMock ();
161+ $ dataHandler = null ;
162+ $ stream = $ this ->getMockBuilder ('React\Socket\ConnectionInterface ' )->getMock ();
153163 $ stream ->expects ($ this ->once ())->method ('write ' )->with ("*2 \r\n$4 \r\nauth \r\n$5 \r\nworld \r\n" );
154164 $ 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+ );
155172
156173 $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->willReturn (Promise \resolve ($ stream ));
157174 $ promise = $ this ->factory ->createClient ('redis://:world@localhost ' );
158175
159- $ stream ->emit ('data ' , array ("-ERR invalid password \r\n" ));
176+ $ this ->assertTrue (is_callable ($ dataHandler ));
177+ $ dataHandler ("-ERR invalid password \r\n" );
160178
161179 $ promise ->then (null , $ this ->expectCallableOnceWith (
162180 $ this ->logicalAnd (
@@ -182,27 +200,45 @@ public function testWillWriteSelectCommandIfRedisUnixUriContainsDbQueryParameter
182200
183201 public function testWillResolveWhenSelectCommandReceivesOkResponseIfRedisUriContainsPath ()
184202 {
185- $ stream = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('write ' ))->getMock ();
203+ $ dataHandler = null ;
204+ $ stream = $ this ->getMockBuilder ('React\Socket\ConnectionInterface ' )->getMock ();
186205 $ 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+ );
187213
188214 $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->willReturn (Promise \resolve ($ stream ));
189215 $ promise = $ this ->factory ->createClient ('redis://localhost/123 ' );
190216
191- $ stream ->emit ('data ' , array ("+OK \r\n" ));
217+ $ this ->assertTrue (is_callable ($ dataHandler ));
218+ $ dataHandler ("+OK \r\n" );
192219
193220 $ promise ->then ($ this ->expectCallableOnceWith ($ this ->isInstanceOf ('Clue\React\Redis\Client ' )));
194221 }
195222
196223 public function testWillRejectAndCloseAutomaticallyWhenSelectCommandReceivesErrorResponseIfRedisUriContainsPath ()
197224 {
198- $ stream = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('write ' , 'close ' ))->getMock ();
225+ $ dataHandler = null ;
226+ $ stream = $ this ->getMockBuilder ('React\Socket\ConnectionInterface ' )->getMock ();
199227 $ stream ->expects ($ this ->once ())->method ('write ' )->with ("*2 \r\n$6 \r\nselect \r\n$3 \r\n123 \r\n" );
200228 $ 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+ );
201236
202237 $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->willReturn (Promise \resolve ($ stream ));
203238 $ promise = $ this ->factory ->createClient ('redis://localhost/123 ' );
204239
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" );
206242
207243 $ promise ->then (null , $ this ->expectCallableOnceWith (
208244 $ this ->logicalAnd (
0 commit comments