Skip to content

Commit

Permalink
[Console] fix a bug when you are passing a default value and passing …
Browse files Browse the repository at this point in the history
…-n would ouput the index
  • Loading branch information
Amrouche Hamza committed Dec 16, 2017
1 parent 76b7cac commit 41ffc69
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Symfony/Component/Console/Helper/QuestionHelper.php
Expand Up @@ -45,6 +45,12 @@ public function ask(InputInterface $input, OutputInterface $output, Question $qu
}

if (!$input->isInteractive()) {
if ($question instanceof ChoiceQuestion) {
$choices = $question->getChoices();

return $choices[$question->getDefault()];
}

return $question->getDefault();
}

Expand Down
Expand Up @@ -84,6 +84,10 @@ public function testAskChoice()
$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()
Expand Down

0 comments on commit 41ffc69

Please sign in to comment.