Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Closed
wants to merge 1 commit into from

3 participants

@xabbuh
Collaborator
Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #8625
License MIT
Doc PR
src/Symfony/Component/Console/Tester/CommandTester.php
@@ -52,6 +52,16 @@ public function __construct(Command $command)
*/
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
+ $application = $this->command->getApplication();
+ if ($application != null) {
@stloyd
stloyd added a note

Should be null !== $application to match CS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/Symfony/Component/Console/Tester/CommandTester.php
@@ -52,6 +52,16 @@ public function __construct(Command $command)
*/
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
+ $application = $this->command->getApplication();
+ if ($application != null) {
+ $definition = $application->getDefinition();
+ if ($definition->hasArgument("command") && !isset($input['command'])) {
@stloyd
stloyd added a note

Please use ' not ".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/Symfony/Component/Console/Tester/CommandTester.php
@@ -52,6 +52,16 @@ public function __construct(Command $command)
*/
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
+ $application = $this->command->getApplication();
@stloyd
stloyd added a note

Shouldn't you do first the check:

if (!isset($input['command']))) {
   // Your patch here
}

To avoid unnecessary calls?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@xabbuh
Collaborator

Thanks for your feedback, @stloyd. I modified the PR accordingly.

src/Symfony/Component/Console/Tester/CommandTester.php
@@ -52,6 +52,18 @@ public function __construct(Command $command)
*/
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 ($application !== null) {
@stof Collaborator
stof added a note

it should be null !== $application

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@fabpot fabpot closed this pull request from a commit
@fabpot fabpot 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
ad7be73
@fabpot fabpot closed this in ad7be73
@xabbuh xabbuh deleted the xabbuh:issue-8625 branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 0 deletions.
  1. +12 −0 src/Symfony/Component/Console/Tester/CommandTester.php
View
12 src/Symfony/Component/Console/Tester/CommandTester.php
@@ -52,6 +52,18 @@ public function __construct(Command $command)
*/
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']);
Something went wrong with that request. Please try again.