[Console] fix a bug when you are passing a default value and passing -n would ouput the index
This commit is contained in:
parent
76b7cacdd3
commit
41ffc69fa0
|
@ -45,6 +45,12 @@ class QuestionHelper extends Helper
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$input->isInteractive()) {
|
if (!$input->isInteractive()) {
|
||||||
|
if ($question instanceof ChoiceQuestion) {
|
||||||
|
$choices = $question->getChoices();
|
||||||
|
|
||||||
|
return $choices[$question->getDefault()];
|
||||||
|
}
|
||||||
|
|
||||||
return $question->getDefault();
|
return $question->getDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,6 +84,10 @@ class QuestionHelperTest extends TestCase
|
||||||
$question->setMultiselect(true);
|
$question->setMultiselect(true);
|
||||||
|
|
||||||
$this->assertEquals(array('Superman', 'Batman'), $questionHelper->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
$this->assertEquals(array('Superman', 'Batman'), $questionHelper->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||||
|
|
||||||
|
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, 0);
|
||||||
|
// We are supposed to get the default value since we are not in interactive mode
|
||||||
|
$this->assertEquals('Superman', $questionHelper->ask($this->createInputInterfaceMock(true), $this->createOutputInterface(), $question));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAsk()
|
public function testAsk()
|
||||||
|
|
Reference in New Issue