@@ -195,36 +195,47 @@ public function testDataEventWillBeEmittedForCompleteLine()
195
195
{
196
196
$ this ->readline ->on ('data ' , $ this ->expectCallableOnceWith ('hello ' ));
197
197
198
- $ this ->pushInputBytes ( $ this -> readline , "hello \n" );
198
+ $ this ->input -> emit ( ' data ' , array ( "hello \n" ) );
199
199
}
200
200
201
- public function testDataEventWillNotBeEmittedForIncompleteLine ()
201
+ public function testDataEventWillNotBeEmittedForIncompleteLineButWillStayInInputBuffer ()
202
202
{
203
203
$ this ->readline ->on ('data ' , $ this ->expectCallableNever ());
204
204
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 ());
206
217
}
207
218
208
219
public function testDataEventWillBeEmittedForEmptyLine ()
209
220
{
210
221
$ this ->readline ->on ('data ' , $ this ->expectCallableOnceWith ('' ));
211
222
212
- $ this ->pushInputBytes ( $ this -> readline , "\n" );
223
+ $ this ->input -> emit ( ' data ' , array ( "\n" ) );
213
224
}
214
225
215
226
public function testWriteSimpleCharWritesOnce ()
216
227
{
217
228
$ this ->output ->expects ($ this ->once ())->method ('write ' )->with ($ this ->equalTo ("\r\033[K " . "k " ));
218
229
219
- $ this ->pushInputBytes ( $ this -> readline , 'k ' );
230
+ $ this ->input -> emit ( ' data ' , array ( 'k ' ) );
220
231
}
221
232
222
233
public function testWriteMultiByteCharWritesOnce ()
223
234
{
224
235
$ this ->output ->expects ($ this ->once ())->method ('write ' )->with ($ this ->equalTo ("\r\033[K " . "\xF0\x9D\x84\x9E" ));
225
236
226
237
// "𝄞" – 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" ) );
228
239
}
229
240
230
241
public function testKeysHomeMovesToFront ()
@@ -276,7 +287,7 @@ public function testKeysRightMovesToRight(Readline $readline)
276
287
277
288
public function testKeysSimpleChars ()
278
289
{
279
- $ this ->pushInputBytes ( $ this -> readline , 'hi! ' );
290
+ $ this ->input -> emit ( ' data ' , array ( 'hi! ' ) );
280
291
281
292
$ this ->assertEquals ('hi! ' , $ this ->readline ->getInput ());
282
293
$ this ->assertEquals (3 , $ this ->readline ->getCursorPosition ());
@@ -300,7 +311,7 @@ public function testKeysBackspaceDeletesLastCharacter(Readline $readline)
300
311
301
312
public function testKeysMultiByteInput ()
302
313
{
303
- $ this ->pushInputBytes ( $ this -> readline , 'hä ' );
314
+ $ this ->input -> emit ( ' data ' , array ( 'hä ' ) );
304
315
305
316
$ this ->assertEquals ('hä ' , $ this ->readline ->getInput ());
306
317
$ this ->assertEquals (2 , $ this ->readline ->getCursorPosition ());
@@ -372,7 +383,7 @@ public function testKeysPrependCharacterInFrontOfMultiByte()
372
383
$ this ->readline ->setInput ('ü ' );
373
384
$ this ->readline ->moveCursorTo (0 );
374
385
375
- $ this ->pushInputBytes ( $ this -> readline , 'h ' );
386
+ $ this ->input -> emit ( ' data ' , array ( 'h ' ) );
376
387
377
388
$ this ->assertEquals ('hü ' , $ this ->readline ->getInput ());
378
389
$ this ->assertEquals (1 , $ this ->readline ->getCursorPosition ());
@@ -383,7 +394,7 @@ public function testKeysWriteMultiByteAfterMultiByte()
383
394
{
384
395
$ this ->readline ->setInput ('ü ' );
385
396
386
- $ this ->pushInputBytes ( $ this -> readline , 'ä ' );
397
+ $ this ->input -> emit ( ' data ' , array ( 'ä ' ) );
387
398
388
399
$ this ->assertEquals ('üä ' , $ this ->readline ->getInput ());
389
400
$ this ->assertEquals (2 , $ this ->readline ->getCursorPosition ());
@@ -395,7 +406,7 @@ public function testKeysPrependMultiByteInFrontOfMultiByte()
395
406
$ this ->readline ->setInput ('ü ' );
396
407
$ this ->readline ->moveCursorTo (0 );
397
408
398
- $ this ->pushInputBytes ( $ this -> readline , 'ä ' );
409
+ $ this ->input -> emit ( ' data ' , array ( 'ä ' ) );
399
410
400
411
$ this ->assertEquals ('äü ' , $ this ->readline ->getInput ());
401
412
$ this ->assertEquals (1 , $ this ->readline ->getCursorPosition ());
@@ -618,11 +629,4 @@ public function testPipeWillReturnDest()
618
629
619
630
$ this ->assertEquals ($ dest , $ ret );
620
631
}
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
- }
628
632
}
0 commit comments