Browse Source

Fix return type annotations.

Mark Story 8 years ago
parent
commit
1a0c8688ed
3 changed files with 13 additions and 4 deletions
  1. 3 1
      src/Console/Command.php
  2. 2 1
      src/Console/CommandRunner.php
  3. 8 2
      tests/TestCase/Console/CommandTest.php

+ 3 - 1
src/Console/Command.php

@@ -174,7 +174,9 @@ class Command
         $this->setOutputLevel($args, $io);
 
         if ($args->getOption('help')) {
-            return $this->displayHelp($parser, $args, $io);
+            $this->displayHelp($parser, $args, $io);
+
+            return static::CODE_SUCCESS;
         }
 
         return $this->execute($args, $io);

+ 2 - 1
src/Console/CommandRunner.php

@@ -136,6 +136,7 @@ class CommandRunner
         $io = $io ?: new ConsoleIo();
         $name = $this->resolveName($commands, $io, array_shift($argv));
 
+        $result = Shell::CODE_ERROR;
         $shell = $this->getShell($io, $commands, $name);
         if ($shell instanceof Shell) {
             $result = $this->runShell($shell, $argv);
@@ -236,7 +237,7 @@ class CommandRunner
      *
      * @param string $className Shell class name.
      * @param \Cake\Console\ConsoleIo $io The IO wrapper for the created shell class.
-     * @return \Cake\Console\Shell
+     * @return \Cake\Console\Shell|\Cake\Console\Command
      */
     protected function createShell($className, ConsoleIo $io)
     {

+ 8 - 2
tests/TestCase/Console/CommandTest.php

@@ -134,7 +134,10 @@ class CommandTest extends TestCase
         $command->setName('cake example');
         $output = new ConsoleOutput();
 
-        $this->assertNull($command->run(['-h'], $this->getMockIo($output)));
+        $this->assertSame(
+            Command::CODE_SUCCESS,
+            $command->run(['-h'], $this->getMockIo($output))
+        );
         $messages = implode("\n", $output->messages());
         $this->assertNotContains('Example', $messages);
         $this->assertContains('cake example [-h]', $messages);
@@ -151,7 +154,10 @@ class CommandTest extends TestCase
         $command->setName('cake example');
         $output = new ConsoleOutput();
 
-        $this->assertNull($command->run(['--help'], $this->getMockIo($output)));
+        $this->assertSame(
+            Command::CODE_SUCCESS,
+            $command->run(['--help'], $this->getMockIo($output))
+        );
         $messages = implode("\n", $output->messages());
         $this->assertNotContains('Example', $messages);
         $this->assertContains('cake example [-h]', $messages);