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 49992c5

Browse filesBrowse files
author
Robin Chalas
committed
Merge branch '2.8' into 3.4
* 2.8: [Console] Fix SymfonyQuestionHelper::askQuestion() with choice value as default
2 parents 8bc014c + d32d768 commit 49992c5
Copy full SHA for 49992c5

File tree

Expand file treeCollapse file tree

2 files changed

+13
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+13
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Helper/SymfonyQuestionHelper.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ protected function writePrompt(OutputInterface $output, Question $question)
8686

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

9191
break;
9292

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Helper/SymfonyQuestionHelperTest.php
+12Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.