Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[SymfonyStyle] Unable to test a command in phpUnit #26885

Closed
@FroggDev

Description

@FroggDev
Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? no
Symfony version 4.1

Hi, iam trying to test a Command using symfony style
https://github.com/FroggDev/Symfony_StockManager/blob/master/src/Command/UserManager.php

I tried a lot of things without success in phpUnit with KernelTestCase.
This is the version of the code i am using to test the command:

       // Get the command tester
        $commandTester = new CommandTester(self::$command);

        // Set input scenario
        $commandTester->setInputs([0]); // display user list
        $commandTester->setInputs([5]); // exit

        echo "BEFORE";

        // Execute the command
        $commandTester->execute(['command' => self::$command->getName()]);

        echo "AFTER";

Based on https://symfony.com/doc/current/components/console/helpers/questionhelper.html

The string "Before" is displayed but after the excecute no more output are displayed.
Even any phpUnit output.

Is there anyway to solve this trouble ?

Thanks

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