Skip to content

Commit 63fccc4

Browse files
bug symfony#61693 [Console] Don’t append a new line to test inputs ending with an EOT (MatTheCat)
This PR was merged into the 6.4 branch. Discussion ---------- [Console] Don’t append a new line to test inputs ending with an EOT | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | N/A | License | MIT symfony#61501 wrote a new line before multiline test inputs’ EOT character, and symfony#61690 wrote it after… so the next input would always be empty. This PR doesn’t write a new line if a test input ends with `\x4` so that the stream matches the inputs. Commits ------- 74ae155 [Console] Don’t append a new line to test inputs ending with an EOT
2 parents f1fb422 + 74ae155 commit 63fccc4

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/Symfony/Component/Console/Tester/TesterTrait.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,11 @@ private static function createStream(array $inputs)
168168
$stream = fopen('php://memory', 'r+', false);
169169

170170
foreach ($inputs as $input) {
171-
fwrite($stream, $input.\PHP_EOL);
171+
fwrite($stream, $input);
172+
173+
if (!str_ends_with($input, "\x4")) {
174+
fwrite($stream, \PHP_EOL);
175+
}
172176
}
173177

174178
rewind($stream);

src/Symfony/Component/Console/Tests/Tester/CommandTesterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function testCommandWithMultilineInputs()
136136
$command = new Command('foo');
137137
$command->setHelperSet(new HelperSet([new QuestionHelper()]));
138138
$command->setCode(function (InputInterface $input, OutputInterface $output) use ($question, $command): int {
139-
$output->write($command->getHelper('question')->ask($input, $output, (new Question($question."\n"))->setMultiline(true)));
139+
$output->write($command->getHelper('question')->ask($input, $output, (new Question($question))->setMultiline(true)));
140140
$output->write(stream_get_contents($input->getStream()));
141141

142142
return 0;
@@ -152,7 +152,7 @@ public function testCommandWithMultilineInputs()
152152
$tester->execute([]);
153153

154154
$tester->assertCommandIsSuccessful();
155-
$this->assertSame($question."\n".$address."\n".$address."\n", $tester->getDisplay());
155+
$this->assertSame($question.$address.$address.\PHP_EOL, $tester->getDisplay());
156156
}
157157

158158
public function testCommandWithDefaultInputs()

0 commit comments

Comments
 (0)