@@ -36,7 +36,16 @@ public function testWriteStartsOnAFreshLineOnceAndThenContinues(): void
3636 $ output ->write ('first ' );
3737 $ output ->write ('second ' );
3838
39- $ this ->assertSame ([['STDOUT ' , "\nfirst \n" ], ['STDOUT ' , "second \n" ]], $ io ->writes );
39+ $ this ->assertSame (['STDOUT ' , 'STDOUT ' ], array_column ($ io ->writes , 0 ));
40+ $ this ->assertSame (
41+ <<<'EOT'
42+
43+ first
44+ second
45+
46+ EOT,
47+ $ this ->getWrittenText ($ io ),
48+ );
4049 }
4150
4251 public function testPrintLeavesTheCursorAfterTheText (): void
@@ -78,7 +87,17 @@ public function testErrorWritesToStderrAndSharesTheCursorState(): void
7887 $ output ->error ('second ' );
7988 $ output ->write ('third ' );
8089
81- $ this ->assertSame ([['STDOUT ' , "\nfirst \n" ], ['STDERR ' , "second \n" ], ['STDOUT ' , "third \n" ]], $ io ->writes );
90+ $ this ->assertSame (['STDOUT ' , 'STDERR ' , 'STDOUT ' ], array_column ($ io ->writes , 0 ));
91+ $ this ->assertSame (
92+ <<<'EOT'
93+
94+ first
95+ second
96+ third
97+
98+ EOT,
99+ $ this ->getWrittenText ($ io ),
100+ );
82101 }
83102
84103 public function testErrorOutsideTheCliWritesToStdoutWithoutColor (): void
@@ -329,6 +348,37 @@ public function testForStderrTargetsStderrAndKeepsTheCursorState(): void
329348 ], $ io ->writes );
330349 }
331350
351+ public function testForStderrSharesTheDeferredNewLine (): void
352+ {
353+ $ io = new RecordingInputOutput ();
354+ $ output = new Output ($ io , $ this ->createUncoloredTerminal ());
355+
356+ $ output ->print ("first \n" );
357+ $ output ->deferNewLine ();
358+ $ output ->forStderr ()->write ('second ' );
359+ $ output ->write ('third ' );
360+
361+ $ stderr = $ output ->forStderr ();
362+ $ output ->deferNewLine ();
363+ $ output ->write ('fourth ' );
364+ $ stderr ->write ('fifth ' );
365+
366+ $ this ->assertSame (['STDOUT ' , 'STDERR ' , 'STDOUT ' , 'STDOUT ' , 'STDERR ' ], array_column ($ io ->writes , 0 ));
367+ $ this ->assertSame (
368+ <<<'EOT'
369+ first
370+
371+ second
372+ third
373+
374+ fourth
375+ fifth
376+
377+ EOT,
378+ $ this ->getWrittenText ($ io ),
379+ );
380+ }
381+
332382 public function testBeepAndClearScreenLeaveTheCursorStateAlone (): void
333383 {
334384 $ io = new RecordingInputOutput ();
@@ -367,7 +417,16 @@ public function testSetCursorAtLineStartControlsTheNextWrite(): void
367417 $ output ->setCursorAtLineStart (false );
368418 $ output ->write ('second ' );
369419
370- $ this ->assertSame ([['STDOUT ' , "first \n" ], ['STDOUT ' , "\nsecond \n" ]], $ io ->writes );
420+ $ this ->assertSame (['STDOUT ' , 'STDOUT ' ], array_column ($ io ->writes , 0 ));
421+ $ this ->assertSame (
422+ <<<'EOT'
423+ first
424+
425+ second
426+
427+ EOT,
428+ $ this ->getWrittenText ($ io ),
429+ );
371430 }
372431
373432 public function testDeferredNewLineWritesNothingWhenNothingFollows (): void
@@ -394,13 +453,19 @@ public function testDeferredNewLineIsWrittenOnceBeforeTheNextWrites(): void
394453 $ output ->deferNewLine ();
395454 $ output ->print ('fourth ' );
396455
397- $ this ->assertSame ([
398- ['STDOUT ' , "first \n" ],
399- ['STDOUT ' , "\nsecond \n" ],
400- ['STDERR ' , "\nthird \n" ],
401- ['STDOUT ' , "\n" ],
402- ['STDOUT ' , 'fourth ' ],
403- ], $ io ->writes );
456+ $ this ->assertSame (['STDOUT ' , 'STDOUT ' , 'STDERR ' , 'STDOUT ' , 'STDOUT ' ], array_column ($ io ->writes , 0 ));
457+ $ this ->assertSame (
458+ <<<'EOT'
459+ first
460+
461+ second
462+
463+ third
464+
465+ fourth
466+ EOT,
467+ $ this ->getWrittenText ($ io ),
468+ );
404469 }
405470
406471 public function testWriteDeferredNewLineFlushesTheHeldLineOnce (): void
@@ -413,7 +478,15 @@ public function testWriteDeferredNewLineFlushesTheHeldLineOnce(): void
413478 $ output ->writeDeferredNewLine ();
414479 $ output ->write ('next ' );
415480
416- $ this ->assertSame ([['STDOUT ' , "\n" ], ['STDOUT ' , "next \n" ]], $ io ->writes );
481+ $ this ->assertSame (['STDOUT ' , 'STDOUT ' ], array_column ($ io ->writes , 0 ));
482+ $ this ->assertSame (
483+ <<<'EOT'
484+
485+ next
486+
487+ EOT,
488+ $ this ->getWrittenText ($ io ),
489+ );
417490 }
418491
419492 public function testSetInputOutputReplacesTheTransport (): void
@@ -460,11 +533,17 @@ public function testDropsWritesAboveTheLevel(): void
460533 $ output ->write ('very verbose ' , verbosity: Verbosity::VeryVerbose);
461534 $ output ->write ('debug ' , verbosity: Verbosity::Debug);
462535
463- $ this ->assertSame ([
464- ['STDOUT ' , "\nnormal \n" ],
465- ['STDOUT ' , "quiet \n" ],
466- ['STDOUT ' , "very verbose \n" ],
467- ], $ io ->writes );
536+ $ this ->assertSame (['STDOUT ' , 'STDOUT ' , 'STDOUT ' ], array_column ($ io ->writes , 0 ));
537+ $ this ->assertSame (
538+ <<<'EOT'
539+
540+ normal
541+ quiet
542+ very verbose
543+
544+ EOT,
545+ $ this ->getWrittenText ($ io ),
546+ );
468547 }
469548
470549 public function testQuietDropsNormalWritesButKeepsErrors (): void
@@ -482,7 +561,16 @@ public function testQuietDropsNormalWritesButKeepsErrors(): void
482561 $ output ->error ('error ' );
483562 $ output ->write ('quiet ' , verbosity: Verbosity::Quiet);
484563
485- $ this ->assertSame ([['STDERR ' , "\nerror \n" ], ['STDOUT ' , "quiet \n" ]], $ io ->writes );
564+ $ this ->assertSame (['STDERR ' , 'STDOUT ' ], array_column ($ io ->writes , 0 ));
565+ $ this ->assertSame (
566+ <<<'EOT'
567+
568+ error
569+ quiet
570+
571+ EOT,
572+ $ this ->getWrittenText ($ io ),
573+ );
486574 }
487575
488576 public function testSilentDropsEverything (): void
@@ -507,7 +595,16 @@ public function testDroppedWriteLeavesTheCursorAlone(): void
507595 $ output ->print ('dropped ' , verbosity: Verbosity::Verbose);
508596 $ output ->write ('second ' );
509597
510- $ this ->assertSame ([['STDOUT ' , "\nfirst \n" ], ['STDOUT ' , "second \n" ]], $ io ->writes );
598+ $ this ->assertSame (['STDOUT ' , 'STDOUT ' ], array_column ($ io ->writes , 0 ));
599+ $ this ->assertSame (
600+ <<<'EOT'
601+
602+ first
603+ second
604+
605+ EOT,
606+ $ this ->getWrittenText ($ io ),
607+ );
511608 }
512609
513610 public function testForStderrKeepsTheLevelAndWritesAtQuiet (): void
@@ -561,4 +658,9 @@ private function createUncoloredTerminal(): Terminal
561658
562659 return $ terminal ;
563660 }
661+
662+ private function getWrittenText (RecordingInputOutput $ io ): string
663+ {
664+ return implode ('' , array_column ($ io ->writes , 1 ));
665+ }
564666}
0 commit comments