8000 Merge branch '4.1' · symfony/symfony@344b8ce · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 344b8ce

Browse files
author
Robin Chalas
committed
Merge branch '4.1'
* 4.1: [Console] Fix SymfonyQuestionHelper::askQuestion() with choice value as default
2 parents 4cf1ae4 + 492eb5f commit 344b8ce

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

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