[Console] fix a bug when you are passing a default value and passing -n would ouput the index

This commit is contained in:
Amrouche Hamza 2017-12-16 06:43:52 +01:00
parent 76b7cacdd3
commit 41ffc69fa0
No known key found for this signature in database
GPG Key ID: 6968F2785ED4F012
2 changed files with 10 additions and 0 deletions

View File

@ -45,6 +45,12 @@ class QuestionHelper extends Helper
}
if (!$input->isInteractive()) {
if ($question instanceof ChoiceQuestion) {
$choices = $question->getChoices();
return $choices[$question->getDefault()];
}
return $question->getDefault();
}

View File

@ -84,6 +84,10 @@ class QuestionHelperTest extends TestCase
$question->setMultiselect(true);
$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()