Description
Symfony version(s) affected
6.4
Description
With the new command profiling feature, a event listener was added that grabs the profile
option from the command inputs:
https://github.com/symfony/symfony/blob/6.4/src/Symfony/Bundle/FrameworkBundle/EventListener/ConsoleProfilerListener.php#L62
Normaly that option is added to every command over the Application: https://github.com/symfony/symfony/blob/6.4/src/Symfony/Bundle/FrameworkBundle/Console/Application.php#L47
However not every command is executed over the Application class, e.g. during unit tests with the CommandTester
or by just dispatching the ConsoleCommandEvent
directly.
In those cases the following error is thrown:
Symfony\Component\Console\Exception\InvalidArgumentException: The "profile" option does not exist.
/.../symfony/console/Input/Input.php:127
/.../symfony/framework-bundle/EventListener/ConsoleProfilerListener.php:62
/.../symfony/event-dispatcher/Debug/WrappedListener.php:116
/.../symfony/event-dispatcher/EventDispatcher.php:206
/.../symfony/event-dispatcher/EventDispatcher.php:56
How to reproduce
Use the command tester to test a manually created command:
$command = new MyCommandToTest();
$commandTester = new CommandTester($command);
$commandTester->run($input);
Note: this differs from how the command tester is documented: https://symfony.com/doc/current/console.html#testing-commands
As there the command is fetched from the application, however, to properly unit test commands without having the whole application booted up, I think the above code is valid for testing commands and should be supported.
Possible Solution
Check if the option exists before accessing it -> PR incoming
Additional Context
No response