@@ -195,36 +195,47 @@ public function testDataEventWillBeEmittedForCompleteLine()
195195 {
196196 $ this ->readline ->on ('data ' , $ this ->expectCallableOnceWith ('hello ' ));
197197
198- $ this ->pushInputBytes ( $ this -> readline , "hello \n" );
198+ $ this ->input -> emit ( ' data ' , array ( "hello \n" ) );
199199 }
200200
201- public function testDataEventWillNotBeEmittedForIncompleteLine ()
201+ public function testDataEventWillNotBeEmittedForIncompleteLineButWillStayInInputBuffer ()
202202 {
203203 $ this ->readline ->on ('data ' , $ this ->expectCallableNever ());
204204
205- $ this ->pushInputBytes ($ this ->readline , "hello " );
205+ $ this ->input ->emit ('data ' , array ("hello " ));
206+
207+ $ this ->assertEquals ('hello ' , $ this ->readline ->getInput ());
208+ }
209+
210+ public function testDataEventWillBeEmittedForCompleteLineAndRemainingWillStayInInputBuffer ()
211+ {
212+ $ this ->readline ->on ('data ' , $ this ->expectCallableOnceWith ('hello ' ));
213+
214+ $ this ->input ->emit ('data ' , array ("hello \nworld " ));
215+
216+ $ this ->assertEquals ('world ' , $ this ->readline ->getInput ());
206217 }
207218
208219 public function testDataEventWillBeEmittedForEmptyLine ()
209220 {
210221 $ this ->readline ->on ('data ' , $ this ->expectCallableOnceWith ('' ));
211222
212- $ this ->pushInputBytes ( $ this -> readline , "\n" );
223+ $ this ->input -> emit ( ' data ' , array ( "\n" ) );
213224 }
214225
215226 public function testWriteSimpleCharWritesOnce ()
216227 {
217228 $ this ->output ->expects ($ this ->once ())->method ('write ' )->with ($ this ->equalTo ("\r\033[K " . "k " ));
218229
219- $ this ->pushInputBytes ( $ this -> readline , 'k ' );
230+ $ this ->input -> emit ( ' data ' , array ( 'k ' ) );
220231 }
221232
222233 public function testWriteMultiByteCharWritesOnce ()
223234 {
224235 $ this ->output ->expects ($ this ->once ())->method ('write ' )->with ($ this ->equalTo ("\r\033[K " . "\xF0\x9D\x84\x9E" ));
225236
226237 // "𝄞" – U+1D11E MUSICAL SYMBOL G CLEF
227- $ this ->pushInputBytes ( $ this -> readline , "\xF0\x9D\x84\x9E" );
238+ $ this ->input -> emit ( ' data ' , array ( "\xF0\x9D\x84\x9E" ) );
228239 }
229240
230241 public function testKeysHomeMovesToFront ()
@@ -276,7 +287,7 @@ public function testKeysRightMovesToRight(Readline $readline)
276287
277288 public function testKeysSimpleChars ()
278289 {
279- $ this ->pushInputBytes ( $ this -> readline , 'hi! ' );
290+ $ this ->input -> emit ( ' data ' , array ( 'hi! ' ) );
280291
281292 $ this ->assertEquals ('hi! ' , $ this ->readline ->getInput ());
282293 $ this ->assertEquals (3 , $ this ->readline ->getCursorPosition ());
@@ -300,7 +311,7 @@ public function testKeysBackspaceDeletesLastCharacter(Readline $readline)
300311
301312 public function testKeysMultiByteInput ()
302313 {
303- $ this ->pushInputBytes ( $ this -> readline , 'hä ' );
314+ $ this ->input -> emit ( ' data ' , array ( 'hä ' ) );
304315
305316 $ this ->assertEquals ('hä ' , $ this ->readline ->getInput ());
306317 $ this ->assertEquals (2 , $ this ->readline ->getCursorPosition ());
@@ -372,7 +383,7 @@ public function testKeysPrependCharacterInFrontOfMultiByte()
372383 $ this ->readline ->setInput ('ü ' );
373384 $ this ->readline ->moveCursorTo (0 );
374385
375- $ this ->pushInputBytes ( $ this -> readline , 'h ' );
386+ $ this ->input -> emit ( ' data ' , array ( 'h ' ) );
376387
377388 $ this ->assertEquals ('hü ' , $ this ->readline ->getInput ());
378389 $ this ->assertEquals (1 , $ this ->readline ->getCursorPosition ());
@@ -383,7 +394,7 @@ public function testKeysWriteMultiByteAfterMultiByte()
383394 {
384395 $ this ->readline ->setInput ('ü ' );
385396
386- $ this ->pushInputBytes ( $ this -> readline , 'ä ' );
397+ $ this ->input -> emit ( ' data ' , array ( 'ä ' ) );
387398
388399 $ this ->assertEquals ('üä ' , $ this ->readline ->getInput ());
389400 $ this ->assertEquals (2 , $ this ->readline ->getCursorPosition ());
@@ -395,7 +406,7 @@ public function testKeysPrependMultiByteInFrontOfMultiByte()
395406 $ this ->readline ->setInput ('ü ' );
396407 $ this ->readline ->moveCursorTo (0 );
397408
398- $ this ->pushInputBytes ( $ this -> readline , 'ä ' );
409+ $ this ->input -> emit ( ' data ' , array ( 'ä ' ) );
399410
400411 $ this ->assertEquals ('äü ' , $ this ->readline ->getInput ());
401412 $ this ->assertEquals (1 , $ this ->readline ->getCursorPosition ());
@@ -618,11 +629,4 @@ public function testPipeWillReturnDest()
618629
619630 $ this ->assertEquals ($ dest , $ ret );
620631 }
621-
622- private function pushInputBytes (Readline $ readline , $ bytes )
623- {
624- foreach (str_split ($ bytes , 1 ) as $ byte ) {
625- $ this ->input ->emit ('data ' , array ($ byte ));
626- }
627- }
628632}
0 commit comments