Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitc51dda0

Browse files
author
Robin Chalas
committed
[Console] Fix SymfonyQuestionHelper::askQuestion() with choice value as default
1 parent40fff43 commitc51dda0

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

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

8383
case$questioninstanceof ChoiceQuestion:
8484
$choices =$question->getChoices();
85-
$text =sprintf(' <info>%s</info> [<comment>%s</comment>]:',$text, OutputFormatter::escape($choices[$default]));
85+
$text =sprintf(' <info>%s</info> [<comment>%s</comment>]:',$text, OutputFormatter::escape(isset($choices[$default]) ?$choices[$default] :$default));
8686

8787
break;
8888

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ public function testAskChoice()
7575
$this->assertOutputContains('What is your favorite superhero? [Superman, Batman]',$output);
7676
}
7777

78+
publicfunctiontestAskChoiceWithChoiceValueAsDefault()
79+
{
80+
$questionHelper =newSymfonyQuestionHelper();
81+
$helperSet =newHelperSet(array(newFormatterHelper()));
82+
$questionHelper->setHelperSet($helperSet);
83+
$questionHelper->setInputStream($this->getInputStream("Batman\n"));
84+
$question =newChoiceQuestion('What is your favorite superhero?',array('Superman','Batman','Spiderman'),'Batman');
85+
$question->setMaxAttempts(1);
86+
87+
$this->assertSame('Batman',$questionHelper->ask($this->createInputInterfaceMock(),$output =$this->createOutputInterface(),$question));
88+
$this->assertOutputContains('What is your favorite superhero? [Batman]',$output);
89+
}
90+
7891
publicfunctiontestAskReturnsNullIfValidatorAllowsIt()
7992
{
8093
$questionHelper =newSymfonyQuestionHelper();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp