|
16 | 16 | use Symfony\Component\Console\Command\Command; |
17 | 17 | use Symfony\Component\Console\Helper\HelperSet; |
18 | 18 | use Symfony\Component\Console\Helper\QuestionHelper; |
| 19 | +use Symfony\Component\Console\Input\InputInterface; |
19 | 20 | use Symfony\Component\Console\Output\Output; |
| 21 | +use Symfony\Component\Console\Output\OutputInterface; |
20 | 22 | use Symfony\Component\Console\Question\ChoiceQuestion; |
21 | 23 | use Symfony\Component\Console\Question\Question; |
22 | 24 | use Symfony\Component\Console\Style\SymfonyStyle; |
@@ -127,6 +129,32 @@ public function testCommandWithInputs() |
127 | 129 | $this->assertEquals(implode('', $questions), $tester->getDisplay(true)); |
128 | 130 | } |
129 | 131 |
|
| 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 | + |
130 | 158 | public function testCommandWithDefaultInputs() |
131 | 159 | { |
132 | 160 | $questions = [ |
|
0 commit comments