mirror of
https://github.com/symfony/console.git
synced 2026-03-24 01:12:13 +01:00
Merge branch '8.0' into 8.1
* 8.0: bump symfony/type-info dependency [Console] Fix validator exception masked by MissingInputException on empty input
This commit is contained in:
@@ -492,6 +492,8 @@ class QuestionHelper extends Helper
|
||||
}
|
||||
|
||||
return $value;
|
||||
} catch (MissingInputException $e) {
|
||||
throw $error ?? $e;
|
||||
} catch (RuntimeException $e) {
|
||||
throw $e;
|
||||
} catch (\Exception $error) {
|
||||
|
||||
@@ -824,6 +824,26 @@ class QuestionHelperTest extends AbstractQuestionHelperTestCase
|
||||
$dialog->ask($this->createStreamableInputInterfaceMock($this->getInputStream('')), $this->createOutputInterface(), $question);
|
||||
}
|
||||
|
||||
public function testValidatorExceptionPropagatesOnEmptyInput()
|
||||
{
|
||||
$dialog = new QuestionHelper();
|
||||
|
||||
$question = new Question('What\'s your name?');
|
||||
$question->setValidator(function ($value) {
|
||||
if ('' === $value || null === $value) {
|
||||
throw new \InvalidArgumentException('A value is required.');
|
||||
}
|
||||
|
||||
return $value;
|
||||
});
|
||||
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('A value is required.');
|
||||
|
||||
// Simulate setInputs(['']), which writes "\n" to the stream then EOF
|
||||
$dialog->ask($this->createStreamableInputInterfaceMock($this->getInputStream("\n")), $this->createOutputInterface(), $question);
|
||||
}
|
||||
|
||||
public function testQuestionValidatorRepeatsThePrompt()
|
||||
{
|
||||
$tries = 0;
|
||||
|
||||
Reference in New Issue
Block a user