Browse Source

give to phpcs what it wants

thinkingmedia 9 years ago
parent
commit
d751087fe7
2 changed files with 40 additions and 4 deletions
  1. 3 3
      src/Shell/Helper/TableHelper.php
  2. 37 1
      tests/TestCase/Shell/Helper/TableHelperTest.php

+ 3 - 3
src/Shell/Helper/TableHelper.php

@@ -78,7 +78,7 @@ class TableHelper extends Helper
      */
     protected function _render($row, $widths, $options = [])
     {
-        if(!$row || !is_array($row)) {
+        if (!$row || !is_array($row)) {
             return;
         }
 
@@ -102,7 +102,7 @@ class TableHelper extends Helper
      */
     public function output($rows)
     {
-        if(!$rows || !is_array($rows)) {
+        if (!$rows || !is_array($rows)) {
             return;
         }
 
@@ -115,7 +115,7 @@ class TableHelper extends Helper
             $this->_rowSeparator($widths);
         }
 
-        if(!$rows) {
+        if (!$rows) {
             return;
         }
 

+ 37 - 1
tests/TestCase/Shell/Helper/TableHelperTest.php

@@ -64,7 +64,7 @@ class TableHelperTest extends TestCase
     }
 
     /**
-     * Test output with multibyte characters
+     * Test output with multi-byte characters
      *
      * @return void
      */
@@ -209,4 +209,40 @@ class TableHelperTest extends TestCase
         ];
         $this->assertEquals($expected, $this->stub->messages());
     }
+
+    /**
+     * Test output when there is no data.
+     */
+    public function testOutputWithNoData()
+    {
+        $this->helper->output([]);
+        $this->assertEquals([], $this->stub->messages());
+    }
+
+    /**
+     * Test output with a header but no data.
+     */
+    public function testOutputWithHeaderAndNoData()
+    {
+        $data = [
+            ['Header 1', 'Header', 'Long Header']
+        ];
+        $this->helper->output($data);
+        $expected = [
+            '+----------+--------+-------------+',
+            '| <info>Header 1</info> | <info>Header</info> | <info>Long Header</info> |',
+            '+----------+--------+-------------+',
+        ];
+        $this->assertEquals($expected, $this->stub->messages());
+    }
+
+    /**
+     * Test no data when headers are disabled.
+     */
+    public function testOutputHeaderDisabledNoData()
+    {
+        $this->helper->config(['header' => false]);
+        $this->helper->output([]);
+        $this->assertEquals([], $this->stub->messages());
+    }
 }