8000 bug #25521 [Console] fix a bug when you are passing a default value a… · symfony/symfony@98bfe80 · GitHub
[go: up one dir, main page]

Skip to content

Commit 98bfe80

Browse files
bug #25521 [Console] fix a bug when you are passing a default value and passing -n would output the index (Simperfit)
This PR was merged into the 2.7 branch. Discussion ---------- [Console] fix a bug when you are passing a default value and passing -n would output the index | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | no <!-- don't forget to update UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | #25470 | License | MIT | Doc PR | We are fixing a bug when you are using a default value with -n, it would output the index instead of the value. Simple reproducer Simperfit/symfony-reproducer@5079dd1?diff=split#diff-77efcc28bc5309e1af9ac07a1e073009R40 Commits ------- 41ffc69 [Console] fix a bug when you are passing a default value and passing -n would ouput the index
2 parents 11bee7f + 41ffc69 commit 98bfe80

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)
0