Browse Source

Add tests for custom integer return values.

dereuromark 9 years ago
parent
commit
5e74332885
1 changed files with 54 additions and 0 deletions
  1. 54 0
      tests/TestCase/Console/ShellDispatcherTest.php

+ 54 - 0
tests/TestCase/Console/ShellDispatcherTest.php

@@ -215,6 +215,60 @@ class ShellDispatcherTest extends TestCase
     }
 
     /**
+     * Verifies correct dispatch of Shell subclasses with integer exit codes.
+     *
+     * @return void
+     */
+    public function testDispatchShellWithIntegerSuccessCode()
+    {
+        $dispatcher = $this->getMockBuilder('Cake\Console\ShellDispatcher')
+            ->setMethods(['findShell'])
+            ->getMock();
+        $Shell = $this->getMockBuilder('Cake\Console\Shell')->getMock();
+
+        $Shell->expects($this->once())->method('initialize');
+        $Shell->expects($this->once())->method('runCommand')
+            ->with(['initdb'])
+            ->will($this->returnValue(Shell::CODE_SUCCESS));
+
+        $dispatcher->expects($this->any())
+            ->method('findShell')
+            ->with('mock_without_main')
+            ->will($this->returnValue($Shell));
+
+        $dispatcher->args = ['mock_without_main', 'initdb'];
+        $result = $dispatcher->dispatch();
+        $this->assertEquals(Shell::CODE_SUCCESS, $result);
+    }
+
+    /**
+     * Verifies correct dispatch of Shell subclasses with custom integer exit codes.
+     *
+     * @return void
+     */
+    public function testDispatchShellWithCustomIntegerCodes()
+    {
+        $dispatcher = $this->getMockBuilder('Cake\Console\ShellDispatcher')
+            ->setMethods(['findShell'])
+            ->getMock();
+        $Shell = $this->getMockBuilder('Cake\Console\Shell')->getMock();
+
+        $Shell->expects($this->once())->method('initialize');
+        $Shell->expects($this->once())->method('runCommand')
+            ->with(['initdb'])
+            ->will($this->returnValue(3));
+
+        $dispatcher->expects($this->any())
+            ->method('findShell')
+            ->with('mock_without_main')
+            ->will($this->returnValue($Shell));
+
+        $dispatcher->args = ['mock_without_main', 'initdb'];
+        $result = $dispatcher->dispatch();
+        $this->assertEquals(3, $result);
+    }
+
+    /**
      * Verify correct dispatch of Shell subclasses without a main method
      *
      * @return void