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

[Console] invalid default returned from ChoiceQuestion on non interactive mode #30774

Copy link
Copy link
Closed
@ThHareau

Description

@ThHareau
Issue body actions

Symfony version(s) affected: symfony/console v4.2.3

Description

ChoiceQuestion returns the index in interactive mode but the value in non interactive mode

How to reproduce
Using this command:

class TestCommand extends Command
{
    protected function configure()
    {
        $this->setName('test');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $choices = [
            'a' => 'aaaa',
            'b' => 'bbbb',
        ];

        $questionHelper = new SymfonyQuestionHelper();
        $choice = $questionHelper->ask(
            $input,
            $output,
            new ChoiceQuestion('Does it work?', $choices, 'a')
        );

        $output->writeln("Choice: $choice");
    }
}

Then php bin/console test or php bin/console -n will not display the same value.

Possible Solution

https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Console/Helper/QuestionHelper.php#L56 should probably return default, and not the value.

Additional context
The opposite bug with reported in #25470 , the non-interactive mode was returning the index instead of the value. I suppose the return value was changed from value to index meanwhile?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.