Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 78a6b2b

Browse files
MatTheCatnicolas-grekas
authored andcommitted
[Console] Don’t automatically append EOT to multiline test inputs
1 parent 6e654c0 commit 78a6b2b

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

‎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);

‎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)

AltStyle によって変換されたページ (->オリジナル) /