8000 Merge branch '3.4' into 4.1 · symfony/symfony@492eb5f · GitHub
[go: up one dir, main page]

Skip to content

Commit 492eb5f

Browse files
author
Robin Chalas
committed
Merge branch '3.4' into 4.1
* 3.4: [Console] Fix SymfonyQuestionHelper::askQuestion() with choice value as default
2 parents 6fec32c + 49992c5 commit 492eb5f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected function writePrompt(OutputInterface $output, Question $question)
5858

5959
case $question instanceof ChoiceQuestion:
6060
$choices = $question->getChoices();
61-
$text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape($choices[$default]));
61+
$text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape(isset($choices[$default]) ? $choices[$default] : $default));
6262

6363
break;
6464

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

Copy file name to clipboard
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ public function testAskChoice()
7474
$this->assertOutputContains('What is your favorite superhero? [Superman, Batman]', $output);
7575
}
7676

77+
public function testAskChoiceWithChoiceValueAsDefault()
78+
{
79+
$questionHelper = new SymfonyQuestionHelper();
80+
$helperSet = new HelperSet(array(new FormatterHelper()));
81+
$questionHelper->setHelperSet($helperSet);
82+
$question = new ChoiceQuestion('What is your favorite superhero?', array('Superman', 'Batman', 'Spiderman'), 'Batman');
83+
$question->setMaxAttempts(1);
84+
85+
$this->assertSame('Batman', $questionHelper->ask($this->createStreamableInputInterfaceMock($this->getInputStream("Batman\n")), $output = $this->createOutputInterface(), $question));
86+
$this->assertOutputContains('What is your favorite superhero? [Batman]', $output);
87+
}
88+
7789
public function testAskReturnsNullIfValidatorAllowsIt()
7890
{
7991
$questionHelper = new SymfonyQuestionHelper();

0 commit comments

Comments
 (0)
0