@@ -461,19 +461,64 @@ public function testAskMultilineResponseWithEOF()
461461 $ question = new Question ('Write an essay ' );
462462 $ question ->setMultiline (true );
463463
464- $ this ->assertEquals ($ essay , $ dialog ->ask ($ this ->createStreamableInputInterfaceMock ($ response ), $ this ->createOutputInterface (), $ question ));
464+ $ this ->assertSame ($ essay , $ dialog ->ask ($ this ->createStreamableInputInterfaceMock ($ response ), $ this ->createOutputInterface (), $ question ));
465465 }
466466
467467 public function testAskMultilineResponseWithSingleNewline ()
468468 {
469- $ response = $ this ->getInputStream ("\n" );
469+ $ response = $ this ->getInputStream (\ PHP_EOL );
470470
471471 $ dialog = new QuestionHelper ();
472472
473473 $ question = new Question ('Write an essay ' );
474474 $ question ->setMultiline (true );
475475
476- $ this ->assertEquals ('' , $ dialog ->ask ($ this ->createStreamableInputInterfaceMock ($ response ), $ this ->createOutputInterface (), $ question ));
476+ $ this ->assertNull ($ dialog ->ask ($ this ->createStreamableInputInterfaceMock ($ response ), $ this ->createOutputInterface (), $ question ));
477+ }
478+
479+ public function testAskMultilineResponseWithDataAfterNewline ()
480+ {
481+ $ response = $ this ->getInputStream (\PHP_EOL .'this is text ' );
482+
483+ $ dialog = new QuestionHelper ();
484+
485+ $ question = new Question ('Write an essay ' );
486+ $ question ->setMultiline (true );
487+
488+ $ this ->assertNull ($ dialog ->ask ($ this ->createStreamableInputInterfaceMock ($ response ), $ this ->createOutputInterface (), $ question ));
489+ }
490+
491+ public function testAskMultilineResponseWithMultipleNewlinesAtEnd ()
492+ {
493+ $ typedText = 'This is a body ' .\PHP_EOL .\PHP_EOL ;
494+ $ response = $ this ->getInputStream ($ typedText );
495+
496+ $ dialog = new QuestionHelper ();
497+
498+ $ question = new Question ('Write an essay ' );
499+ $ question ->setMultiline (true );
500+
501+ $ this ->assertSame ('This is a body ' , $ dialog ->ask ($ this ->createStreamableInputInterfaceMock ($ response ), $ this ->createOutputInterface (), $ question ));
502+ }
503+
504+ public function testAskMultilineResponseWithWithCursorInMiddleOfSeekableInputStream ()
505+ {
506+ $ input = <<<EOD
507+ This
508+ is
509+ some
510+ input
511+ EOD ;
512+ $ response = $ this ->getInputStream ($ input );
513+ fseek ($ response , 8 );
514+
515+ $ dialog = new QuestionHelper ();
516+
517+ $ question = new Question ('Write an essay ' );
518+ $ question ->setMultiline (true );
519+
520+ $ this ->assertSame ("some \ninput " , $ dialog ->ask ($ this ->createStreamableInputInterfaceMock ($ response ), $ this ->createOutputInterface (), $ question ));
521+ $ this ->assertSame (8 , ftell ($ response ));
477522 }
478523
479524 /**
0 commit comments