[Console] Fix inconsistent result for choice questions in non-interactive mode
This commit is contained in:
parent
d45ecefe0c
commit
198b895eac
@ -49,7 +49,13 @@ class QuestionHelper extends Helper
|
|||||||
if (!$input->isInteractive()) {
|
if (!$input->isInteractive()) {
|
||||||
$default = $question->getDefault();
|
$default = $question->getDefault();
|
||||||
|
|
||||||
if (null !== $default && $question instanceof ChoiceQuestion) {
|
if (null === $default) {
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($validator = $question->getValidator()) {
|
||||||
|
return \call_user_func($question->getValidator(), $default);
|
||||||
|
} elseif ($question instanceof ChoiceQuestion) {
|
||||||
$choices = $question->getChoices();
|
$choices = $question->getChoices();
|
||||||
|
|
||||||
if (!$question->isMultiselect()) {
|
if (!$question->isMultiselect()) {
|
||||||
|
@ -137,6 +137,9 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
|||||||
$question->setMultiselect(true);
|
$question->setMultiselect(true);
|
||||||
$this->assertNull($questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
|
$this->assertNull($questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
|
||||||
|
|
||||||
|
$question = new ChoiceQuestion('Who are your favorite superheros?', ['a' => 'Batman', 'b' => 'Superman'], 'a');
|
||||||
|
$this->assertSame('a', $questionHelper->ask($this->createStreamableInputInterfaceMock('', false), $this->createOutputInterface(), $question), 'ChoiceQuestion validator returns the key if it\'s a string');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, '');
|
$question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, '');
|
||||||
$question->setMultiselect(true);
|
$question->setMultiselect(true);
|
||||||
|
Reference in New Issue
Block a user