Skip to content

Commit 0870356

Browse files
Merge branch '6.3' into 6.4
* 6.3: [Validator] Add annotation in Constraint [VarExporter] Remove unused test files [FrameworkBundle] Remove unused test file [DependencyInjection] Remove unused test file [HttpKernel] Fix missing Request in RequestStack for StreamedResponse Psalm: Ignore UnusedClass errors fix(console): avoid multiple new line when message already ends with a new line
2 parents 14290bc + eca495f commit 0870356

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

Output/ConsoleSectionOutput.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ public function addContent(string $input, bool $newline = true): int
119119
// re-add the line break (that has been removed in the above `explode()` for
120120
// - every line that is not the last line
121121
// - if $newline is required, also add it to the last line
122-
// - if it's not new line, but input ending with `\PHP_EOL`
123-
if ($i < $count || $newline || str_ends_with($input, \PHP_EOL)) {
122+
if ($i < $count || $newline) {
124123
$lineContent .= \PHP_EOL;
125124
}
126125

@@ -168,6 +167,12 @@ public function addNewLineOfInputSubmit(): void
168167
*/
169168
protected function doWrite(string $message, bool $newline)
170169
{
170+
// Simulate newline behavior for consistent output formatting, avoiding extra logic
171+
if (!$newline && str_ends_with($message, \PHP_EOL)) {
172+
$message = substr($message, 0, -\strlen(\PHP_EOL));
173+
$newline = true;
174+
}
175+
171176
if (!$this->isDecorated()) {
172177
parent::doWrite($message, $newline);
173178

Tests/Output/ConsoleSectionOutputTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function testMaxHeightMultipleSections()
159159
$expected .= 'Two'.\PHP_EOL.'Three'.\PHP_EOL.'Four'.\PHP_EOL;
160160

161161
// cause overflow of first section (redraw whole section, without first line)
162-
$firstSection->writeln("Four\nFive\nSix");
162+
$firstSection->writeln('Four'.\PHP_EOL.'Five'.\PHP_EOL.'Six');
163163
$expected .= "\x1b[6A\x1b[0J";
164164
$expected .= 'Four'.\PHP_EOL.'Five'.\PHP_EOL.'Six'.\PHP_EOL;
165165
$expected .= 'Two'.\PHP_EOL.'Three'.\PHP_EOL.'Four'.\PHP_EOL;
@@ -291,4 +291,16 @@ public function testClearSectionContainingQuestion()
291291
rewind($output->getStream());
292292
$this->assertSame('What\'s your favorite super hero?'.\PHP_EOL."\x1b[2A\x1b[0J", stream_get_contents($output->getStream()));
293293
}
294+
295+
public function testWriteWithoutNewLine()
296+
{
297+
$sections = [];
298+
$output = new ConsoleSectionOutput($this->stream, $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
299+
300+
$output->write('Foo'.\PHP_EOL);
301+
$output->write('Bar');
302+
303+
rewind($output->getStream());
304+
$this->assertEquals(escapeshellcmd('Foo'.\PHP_EOL.'Bar'.\PHP_EOL), escapeshellcmd(stream_get_contents($output->getStream())));
305+
}
294306
}

Tests/Style/SymfonyStyleTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,15 @@ public function testAskAndClearExpectFullSectionCleared()
209209

210210
rewind($output->getStream());
211211
$this->assertEquals($answer, $givenAnswer);
212-
$this->assertEquals(
212+
$this->assertEquals(escapeshellcmd(
213213
'start'.\PHP_EOL. // write start
214214
'foo'.\PHP_EOL. // write foo
215215
"\x1b[1A\x1b[0Jfoo and bar".\PHP_EOL. // complete line
216-
\PHP_EOL.\PHP_EOL." \033[32mDummy question?\033[39m:".\PHP_EOL.' > '.\PHP_EOL.\PHP_EOL.\PHP_EOL. // question
217-
'foo2'.\PHP_EOL.\PHP_EOL. // write foo2
216+
\PHP_EOL." \033[32mDummy question?\033[39m:".\PHP_EOL.' > '.\PHP_EOL.\PHP_EOL. // question
217+
'foo2'.\PHP_EOL. // write foo2
218218
'bar2'.\PHP_EOL. // write bar
219-
"\033[12A\033[0J", // clear 12 lines (11 output lines and one from the answer input return)
220-
stream_get_contents($output->getStream())
219+
"\033[9A\033[0J"), // clear 9 lines (8 output lines and one from the answer input return)
220+
escapeshellcmd(stream_get_contents($output->getStream()))
221221
);
222222
}
223223
}

0 commit comments

Comments
 (0)