Browse Source

Add more assertion methods to ConsoleIntegrationTestCase.

Add assertions for checking table rows, and empty output.
Mark Story 8 years ago
parent
commit
07640f8108

+ 29 - 0
src/TestSuite/ConsoleIntegrationTestCase.php

@@ -139,6 +139,18 @@ class ConsoleIntegrationTestCase extends TestCase
     }
 
     /**
+     * Asserts that `stdout` is empty
+     *
+     * @param string $message The message to output when the assertion fails.
+     * @return void
+     */
+    public function assertOutputEmpty($message = 'stdout was not empty')
+    {
+        $output = implode(PHP_EOL, $this->_out->messages());
+        $this->assertSame('', $output, $message);
+    }
+
+    /**
      * Asserts `stdout` contains expected output
      *
      * @param string $expected Expected output
@@ -165,6 +177,23 @@ class ConsoleIntegrationTestCase extends TestCase
     }
 
     /**
+     * Check that a row of cells exists in the output.
+     *
+     * @param array $row Row of cells to ensure exist in the output.
+     * @param string $message Failure message.
+     * @return void
+     */
+    protected function assertOutputContainsRow(array $row, $message = '')
+    {
+        $row = array_map(function ($cell) {
+            return preg_quote($cell, '/');
+        }, $row);
+        $cells = implode('\s+\|\s+', $row);
+        $pattern = '/' . $cells . '/';
+        $this->assertOutputRegexp($pattern);
+    }
+
+    /**
      * Asserts `stderr` contains expected output
      *
      * @param string $expected Expected output

+ 2 - 0
tests/TestCase/TestSuite/ConsoleIntegrationTestCaseTest.php

@@ -80,6 +80,7 @@ class ConsoleIntegrationTestCaseTest extends ConsoleIntegrationTestCase
     {
         $this->exec('integration args_and_options arg --opt="some string"');
 
+        $this->assertErrorEmpty();
         $this->assertOutputContains('arg: arg');
         $this->assertOutputContains('opt: some string');
         $this->assertExitCode(Shell::CODE_SUCCESS);
@@ -94,6 +95,7 @@ class ConsoleIntegrationTestCaseTest extends ConsoleIntegrationTestCase
     {
         $this->exec('integration args_and_options');
 
+        $this->assertOutputEmpty();
         $this->assertErrorContains('Missing required arguments');
         $this->assertErrorContains('arg is required');
         $this->assertExitCode(Shell::CODE_ERROR);