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

Commit338c78d

Browse files
author
Amrouche Hamza
committed
[Console] fix a bug when you are passing a default value and passing -n would ouput the index
1 parent76b7cac commit338c78d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ public function ask(InputInterface $input, OutputInterface $output, Question $qu
4444
$output =$output->getErrorOutput();
4545
}
4646

47-
if (!$input->isInteractive()) {
47+
$isNotInteractive = !$input->isInteractive();
48+
49+
if ($isNotInteractive &&$questioninstanceof ChoiceQuestion) {
50+
return$question->getChoices()[$question->getDefault()];
51+
}
52+
53+
if ($isNotInteractive) {
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 =newChoiceQuestion('What is your favorite superhero?',$heroes,0);
89+
// We are supposed to get the default value since we are in interactive mode
90+
$this->assertEquals('Superman',$questionHelper->ask($this->createInputInterfaceMock(true),$this->createOutputInterface(),$question));
8791
}
8892

8993
publicfunctiontestAsk()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp