|
16 | 16 | use Symfony\Component\Console\Exception\RuntimeException;
|
17 | 17 | use Symfony\Component\Console\Formatter\OutputFormatter;
|
18 | 18 | use Symfony\Component\Console\Input\ArrayInput;
|
| 19 | +use Symfony\Component\Console\Input\Input; |
19 | 20 | use Symfony\Component\Console\Input\InputInterface;
|
20 | 21 | use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
21 | 22 | use Symfony\Component\Console\Output\ConsoleSectionOutput;
|
22 | 23 | use Symfony\Component\Console\Output\NullOutput;
|
23 | 24 | use Symfony\Component\Console\Output\OutputInterface;
|
| 25 | +use Symfony\Component\Console\Output\StreamOutput; |
24 | 26 | use Symfony\Component\Console\Style\SymfonyStyle;
|
25 | 27 | use Symfony\Component\Console\Tester\CommandTester;
|
26 | 28 |
|
@@ -181,4 +183,38 @@ public function testMemoryConsumption()
|
181 | 183 |
|
182 | 184 | $this->assertSame(0, memory_get_usage() - $start);
|
183 | 185 | }
|
| 186 | + |
| 187 | + public function testAskAndClearExpectFullSectionCleared() |
| 188 | + { |
| 189 | + $answer = 'Answer'; |
| 190 | + $inputStream = fopen('php://memory', 'r+'); |
| 191 | + fwrite($inputStream, $answer.PHP_EOL); |
| 192 | + rewind($inputStream); |
| 193 | + $input = $this->createMock(Input::class); |
| 194 | + $sections = []; |
| 195 | + $output = new ConsoleSectionOutput(fopen('php://memory', 'r+', false), $sections, StreamOutput::VERBOSITY_NORMAL, true, new OutputFormatter()); |
| 196 | + $input |
| 197 | + ->method('isInteractive') |
| 198 | + ->willReturn(true); |
| 199 | + $input |
| 200 | + ->method('getStream') |
| 201 | + ->willReturn($inputStream); |
| 202 | + |
| 203 | + $style = new SymfonyStyle($input, $output); |
| 204 | + |
| 205 | + $style->write('foo'); |
| 206 | + $givenAnswer = $style->ask('Dummy question?'); |
| 207 | + $output->write('bar'); |
| 208 | + $output->clear(); |
| 209 | + |
| 210 | + rewind($output->getStream()); |
| 211 | + $this->assertEquals($answer,$givenAnswer); |
| 212 | + $this->assertEquals( |
| 213 | + 'foo'.PHP_EOL. // write foo |
| 214 | + PHP_EOL.PHP_EOL.PHP_EOL." \033[32mDummy question?\033[39m:".PHP_EOL.' > '.PHP_EOL.PHP_EOL.PHP_EOL. // question |
| 215 | + 'bar'.PHP_EOL. // write bar |
| 216 | + "\033[10A\033[0J", // clear 10 lines (9 output lines and one from the answer input return) |
| 217 | + stream_get_contents($output->getStream()) |
| 218 | + ); |
| 219 | + } |
184 | 220 | }
|
0 commit comments