Skip to content

Commit 41ffc69

Browse files
author
Amrouche Hamza
committed
[Console] fix a bug when you are passing a default value and passing -n would ouput the index
1 parent 76b7cac commit 41ffc69

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/Symfony/Component/Console/Helper/QuestionHelper.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ public function ask(InputInterface $input, OutputInterface $output, Question $qu
4545
}
4646

4747
if (!$input->isInteractive()) {
48+
if ($question instanceof ChoiceQuestion) {
49+
$choices = $question->getChoices();
50+
51+
return $choices[$question->getDefault()];
52+
}
53+
4854
return $question->getDefault();
4955
}
5056

src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ public function testAskChoice()
8484
$question->setMultiselect(true);
8585

8686
$this->assertEquals(array('Superman', 'Batman'), $questionHelper->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
87+
88+
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, 0);
89+
// We are supposed to get the default value since we are not in interactive mode
90+
$this->assertEquals('Superman', $questionHelper->ask($this->createInputInterfaceMock(true), $this->createOutputInterface(), $question));
8791
}
8892

8993
public function testAsk()

0 commit comments

Comments
 (0)