Skip to content

Commit 00934e2

Browse files
bug symfony#61690 [Console] Don’t automatically append EOT to multiline test inputs (MatTheCat)
This PR was squashed before being merged into the 6.4 branch. Discussion ---------- [Console] Don’t automatically append EOT to multiline test inputs | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | N/A | License | MIT symfony#61501 assumed multiline inputs were answers to multiline questions and suffixed them with an EOT character to mark their end. But if you’re directly reading stdin, you can have line breaks without the need for an EOT: symfony#61501 (comment) Since the `TesterTrait` doesn’t know the inputs’ context, this PR reverts this behavior. Multiline questions will still be able to be tested by manually suffixing the answer with an EOT (`x04`) like in the added test. If it is accepted it’ll be followed by a doc PR. Commits ------- 938fabb [Console] Don’t automatically append EOT to multiline test inputs
2 parents 917a2af + 938fabb commit 00934e2

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,6 @@ private static function createStream(array $inputs)
169169

170170
foreach ($inputs as $input) {
171171
fwrite($stream, $input.\PHP_EOL);
172-
173-
if (str_contains($input, \PHP_EOL)) {
174-
fwrite($stream, "\x4");
175-
}
176172
}
177173

178174
rewind($stream);

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
use Symfony\Component\Console\Command\Command;
1717
use Symfony\Component\Console\Helper\HelperSet;
1818
use Symfony\Component\Console\Helper\QuestionHelper;
19+
use Symfony\Component\Console\Input\InputInterface;
1920
use Symfony\Component\Console\Output\Output;
21+
use Symfony\Component\Console\Output\OutputInterface;
2022
use Symfony\Component\Console\Question\ChoiceQuestion;
2123
use Symfony\Component\Console\Question\Question;
2224
use Symfony\Component\Console\Style\SymfonyStyle;
@@ -127,6 +129,32 @@ public function testCommandWithInputs()
127129
$this->assertEquals(implode('', $questions), $tester->getDisplay(true));
128130
}
129131

132+
public function testCommandWithMultilineInputs()
133+
{
134+
$question = 'What is your address?';
135+
136+
$command = new Command('foo');
137+
$command->setHelperSet(new HelperSet([new QuestionHelper()]));
138+
$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)));
140+
$output->write(stream_get_contents($input->getStream()));
141+
142+
return 0;
143+
});
144+
145+
$tester = new CommandTester($command);
146+
147+
$address = <<<ADDRESS
148+
31 Spooner Street
149+
Quahog
150+
ADDRESS;
151+
$tester->setInputs([$address."\x04", $address]);
152+
$tester->execute([]);
153+
154+
$tester->assertCommandIsSuccessful();
155+
$this->assertSame($question."\n".$address."\n".$address."\n", $tester->getDisplay());
156+
}
157+
130158
public function testCommandWithDefaultInputs()
131159
{
132160
$questions = [

0 commit comments

Comments
 (0)