feature#8626 [Console] pass command name automatically if required by the application (xabbuh)

This PR was submitted for the 2.2 branch but it was merged into the master branch instead (closes #8626).

Discussion
----------

[Console] pass command name automatically if required by the application

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #8625
| License       | MIT
| Doc PR        |

Commits
-------

50c8050 [Console] pass command name automatically if required by the application
This commit is contained in:
Fabien Potencier 2013-09-30 21:44:36 +02:00
commit ad7be73e40

View File

@ -55,6 +55,18 @@ class CommandTester
*/
public function execute(array $input, array $options = array())
{
// set the command name automatically if the application requires
// this argument and no command name was passed
if (!isset($input['command'])) {
$application = $this->command->getApplication();
if (null !== $application) {
$definition = $application->getDefinition();
if ($definition->hasArgument('command')) {
$input['command'] = $this->command->getName();
}
}
}
$this->input = new ArrayInput($input);
if (isset($options['interactive'])) {
$this->input->setInteractive($options['interactive']);