Skip to content

[Console] PHPUnit test fails for empty answers #45319

@luisfn

Description

@luisfn

Symfony version(s) affected

6.0.2

Description

I created a command with interactive questions but test fails for empty inputs

How to reproduce

In a command add the following:

$name = $io->ask('Oauth2 Client name', null, function ($value) {
    if (empty($value)) {
        throw new InvalidArgumentException('Client name should not be empty');
    }

    return $value;
});

In your test do

$this->commandTester->setInputs(['']); //null value have the same behaviour
$this->commandTester->execute(['command' => $this->command]);

It will throw Symfony\Component\Console\Exception\MissingInputException : Aborted.

If we replace the default value for the question to '' (empty string), it works, but then it shows [] after the question (not desired)

Possible Solution

No response

Additional Context

No response

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