Description
In the changelog I noticed that @wirwolf recently added runSymfonyConsoleCommand
and I tried to use it with a command that has an argument.
The problem is that when symfony determines the command name to use, it calls getFirstArgument
on the $input
(https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Console/Application.php#L980) which in case of ArrayInput
(which is used in runSymfonyConsoleCommand
) gets you the first element of the 'parameters' array which has a key that does not start with an '-' (https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Console/Input/ArrayInput.php#L40).
Since runSymfonyConsoleCommand
adds the 'command' to the end of the parameters array, this only works if your command doesn't have arguments.
Note: arguments != options, see https://symfony.com/doc/current/console/input.html
Current Behavior
When running
$I->runSymfonyConsoleCommand(
'app:example-command',
['example_argument' => 'this_is_the_argument_value'],
);
This is the output:
1) ExampleCommandCest: Try to test
Test tests/functional/Command/ExampleCommandCest.php:tryToTest
Step Run symfony console command
"app:example-command",{"example_argument":"this_is_the_argument_value"}
Fail Exit code in app:example-command is not equal 0 :
Command "this_is_the_argument_value" is not defined.
Failed asserting that 1 matches expected 0.
Workaround
Adding the 'command' manually at the start of the input array solves this issue for me.
$I->runSymfonyConsoleCommand(
'app:example-command',
[
'command' => 'app:example-command',
'example_argument' => 'this_is_the_argument_value'
],
);
Because then it just gets overridden again in https://github.com/Codeception/module-symfony/blob/master/src/Codeception/Module/Symfony.php#L570
Am I just using this wrong, or is this actually a bug? If it's a bug, I'd be happy to provide a PR to solve it.