Merge branch '2.8' into 3.4
* 2.8: [Console] Fix SymfonyQuestionHelper::askQuestion() with choice value as default
This commit is contained in:
commit
49992c5dfb
@ -86,7 +86,7 @@ class SymfonyQuestionHelper extends QuestionHelper
|
|||||||
|
|
||||||
case $question instanceof ChoiceQuestion:
|
case $question instanceof ChoiceQuestion:
|
||||||
$choices = $question->getChoices();
|
$choices = $question->getChoices();
|
||||||
$text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape($choices[$default]));
|
$text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape(isset($choices[$default]) ? $choices[$default] : $default));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -74,6 +74,18 @@ class SymfonyQuestionHelperTest extends AbstractQuestionHelperTest
|
|||||||
$this->assertOutputContains('What is your favorite superhero? [Superman, Batman]', $output);
|
$this->assertOutputContains('What is your favorite superhero? [Superman, Batman]', $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAskChoiceWithChoiceValueAsDefault()
|
||||||
|
{
|
||||||
|
$questionHelper = new SymfonyQuestionHelper();
|
||||||
|
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||||
|
$questionHelper->setHelperSet($helperSet);
|
||||||
|
$question = new ChoiceQuestion('What is your favorite superhero?', array('Superman', 'Batman', 'Spiderman'), 'Batman');
|
||||||
|
$question->setMaxAttempts(1);
|
||||||
|
|
||||||
|
$this->assertSame('Batman', $questionHelper->ask($this->createStreamableInputInterfaceMock($this->getInputStream("Batman\n")), $output = $this->createOutputInterface(), $question));
|
||||||
|
$this->assertOutputContains('What is your favorite superhero? [Batman]', $output);
|
||||||
|
}
|
||||||
|
|
||||||
public function testAskReturnsNullIfValidatorAllowsIt()
|
public function testAskReturnsNullIfValidatorAllowsIt()
|
||||||
{
|
{
|
||||||
$questionHelper = new SymfonyQuestionHelper();
|
$questionHelper = new SymfonyQuestionHelper();
|
||||||
|
Reference in New Issue
Block a user