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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy