|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\Console\Tests\Helper;
|
13 | 13 |
|
| 14 | +use Symfony\Component\Console\Application; |
14 | 15 | use Symfony\Component\Console\Exception\InvalidArgumentException;
|
15 | 16 | use Symfony\Component\Console\Formatter\OutputFormatter;
|
16 | 17 | use Symfony\Component\Console\Helper\FormatterHelper;
|
|
21 | 22 | use Symfony\Component\Console\Question\ConfirmationQuestion;
|
22 | 23 | use Symfony\Component\Console\Question\Question;
|
23 | 24 | use Symfony\Component\Console\Terminal;
|
| 25 | +use Symfony\Component\Console\Tester\ApplicationTester; |
24 | 26 |
|
25 | 27 | /**
|
26 | 28 | * @group tty
|
@@ -844,6 +846,38 @@ public function testTraversableMultiselectAutocomplete()
|
844 | 846 | $this->assertEquals(['AcmeDemoBundle', 'AsseticBundle'], $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
845 | 847 | }
|
846 | 848 |
|
| 849 | + public function testQuestionValidatorRepeatsThePrompt() |
| 850 | + { |
| 851 | + $tries = 0; |
| 852 | + $application = new Application(); |
| 853 | + $application->setAutoExit(false); |
| 854 | + $application->register('question') |
| 855 | + ->setCode(function ($input, $output) use (&$tries) { |
| 856 | + $question = new Question('This is a promptable question'); |
| 857 | + $question->setValidator(function ($value) use (&$tries) { |
| 858 | + $tries++; |
| 859 | + if (!$value) { |
| 860 | + throw new \Exception(); |
| 861 | + } |
| 862 | + |
| 863 | + return $value; |
| 864 | + }); |
| 865 | + |
| 866 | + (new QuestionHelper())->ask($input, $output, $question); |
| 867 | + |
| 868 | + return 0; |
| 869 | + }) |
| 870 | + ; |
| 871 | + |
| 872 | + $tester = new ApplicationTester($application); |
| 873 | + $tester->setInputs(['', 'not-empty']); |
| 874 | + |
| 875 | + $statusCode = $tester->run(['command' => 'question'], ['interactive' => true]); |
| 876 | + |
| 877 | + $this->assertSame(2, $tries); |
| 878 | + $this->assertSame($statusCode, 0); |
| 879 | + } |
| 880 | + |
847 | 881 | protected function getInputStream($input)
|
848 | 882 | {
|
849 | 883 | $stream = fopen('php://memory', 'r+', false);
|
|
0 commit comments