Browse Source

Flip argument order

This puts arguments people use the most first and matches the argument
order of CommandRunner::run()
Mark Story 7 years ago
parent
commit
f9264a7c3a
2 changed files with 9 additions and 8 deletions
  1. 3 2
      src/Console/Command.php
  2. 6 6
      tests/TestCase/Console/CommandTest.php

+ 3 - 2
src/Console/Command.php

@@ -254,11 +254,11 @@ class Command
      * Execute another command with the provided set of arguments.
      *
      * @param string|\Cake\Console\Command $command The command class name or command instance.
-     * @param \Cake\Console\ConsoleIo $io The ConsoleIo instance to use for the executed command.
      * @param array $args The arguments to invoke the command with.
+     * @param \Cake\Console\ConsoleIo $io The ConsoleIo instance to use for the executed command.
      * @return int|null The exit code or null for success of the command.
      */
-    public function executeCommand($command, ConsoleIo $io, array $args = [])
+    public function executeCommand($command, array $args = [], ?ConsoleIo $io = null)
     {
         if (is_string($command)) {
             if (!class_exists($command)) {
@@ -272,6 +272,7 @@ class Command
                 "Command '{$commandType}' is not a subclass of Cake\Console\Command."
             );
         }
+        $io = $io ?: new ConsoleIo();
 
         try {
             return $command->run($args, $io);

+ 6 - 6
tests/TestCase/Console/CommandTest.php

@@ -283,7 +283,7 @@ class CommandTest extends TestCase
     {
         $output = new ConsoleOutput();
         $command = new Command();
-        $result = $command->executeCommand(DemoCommand::class, $this->getMockIo($output));
+        $result = $command->executeCommand(DemoCommand::class, [], $this->getMockIo($output));
         $this->assertNull($result);
         $this->assertEquals(['Quiet!', 'Demo Command!'], $output->messages());
     }
@@ -299,7 +299,7 @@ class CommandTest extends TestCase
         $this->expectExceptionMessage("Command class 'Nope' does not exist");
 
         $command = new Command();
-        $command->executeCommand('Nope', $this->getMockIo(new ConsoleOutput()));
+        $command->executeCommand('Nope', [], $this->getMockIo(new ConsoleOutput()));
     }
 
     /**
@@ -311,7 +311,7 @@ class CommandTest extends TestCase
     {
         $output = new ConsoleOutput();
         $command = new Command();
-        $command->executeCommand(DemoCommand::class, $this->getMockIo($output), ['Jane']);
+        $command->executeCommand(DemoCommand::class, ['Jane'], $this->getMockIo($output));
         $this->assertEquals(['Quiet!', 'Demo Command!', 'Jane'], $output->messages());
     }
 
@@ -324,7 +324,7 @@ class CommandTest extends TestCase
     {
         $output = new ConsoleOutput();
         $command = new Command();
-        $command->executeCommand(DemoCommand::class, $this->getMockIo($output), ['--quiet', 'Jane']);
+        $command->executeCommand(DemoCommand::class, ['--quiet', 'Jane'], $this->getMockIo($output));
         $this->assertEquals(['Quiet!'], $output->messages());
     }
 
@@ -337,7 +337,7 @@ class CommandTest extends TestCase
     {
         $output = new ConsoleOutput();
         $command = new Command();
-        $result = $command->executeCommand(new DemoCommand(), $this->getMockIo($output));
+        $result = $command->executeCommand(new DemoCommand(), [], $this->getMockIo($output));
         $this->assertNull($result);
         $this->assertEquals(['Quiet!', 'Demo Command!'], $output->messages());
     }
@@ -353,7 +353,7 @@ class CommandTest extends TestCase
         $this->expectExceptionMessage("Command 'stdClass' is not a subclass");
 
         $command = new Command();
-        $command->executeCommand(new \stdClass, $this->getMockIo(new ConsoleOutput()));
+        $command->executeCommand(new \stdClass, [], $this->getMockIo(new ConsoleOutput()));
     }
 
     protected function getMockIo($output)