Browse Source

Add test case for abort().

mscherer 6 years ago
parent
commit
f2cecec85a
3 changed files with 21 additions and 3 deletions
  1. 4 2
      src/Console/ConsoleIo.php
  2. 1 1
      src/Console/Shell.php
  3. 16 0
      tests/TestCase/Console/ConsoleIoTest.php

+ 4 - 2
src/Console/ConsoleIo.php

@@ -251,8 +251,10 @@ class ConsoleIo
     }
 
     /**
-     * @param string $message
-     * @param int $code
+     * Halts the the current process with a StopException.
+     *
+     * @param string $message Error message.
+     * @param int $code Error code.
      * @return void
      * @throws \Cake\Console\Exception\StopException
      */

+ 1 - 1
src/Console/Shell.php

@@ -827,7 +827,7 @@ class Shell
 
     /**
      * Displays a formatted error message
-     * and exits the application with status code 1
+     * and exits the application with an error code.
      *
      * @param string $message The error message
      * @param int $exitCode The exit code for the shell task.

+ 16 - 0
tests/TestCase/Console/ConsoleIoTest.php

@@ -293,6 +293,22 @@ class ConsoleIoTest extends TestCase
     }
 
     /**
+     * Tests abort() wrapper.
+     *
+     * @expectedException \Cake\Console\Exception\StopException
+     * @expectedExceptionMessage 99
+     * @return void
+     */
+    public function testAbortCustomCode()
+    {
+        $this->err->expects($this->at(0))
+            ->method('write')
+            ->with('<error>Some error</error>', 1);
+
+        $this->io->abort('Some error', 99);
+    }
+
+    /**
      * testNl
      *
      * @return void