consoleOutput = new ConsoleOutputStub(); $this->helper = new TableShellHelper($this->consoleOutput); } /** * Test output * * @return void */ public function testDefaultOutput() { $data = array( array('Header 1', 'Header', 'Long Header'), array('short', 'Longish thing', 'short'), array('Longer thing', 'short', 'Longest Value'), ); $this->helper->output($data); $expected = array( '+--------------+---------------+---------------+', '| Header 1 | Header | Long Header |', '+--------------+---------------+---------------+', '| short | Longish thing | short |', '| Longer thing | short | Longest Value |', '+--------------+---------------+---------------+', ); $this->assertEquals($expected, $this->consoleOutput->messages()); } /** * Test output with multibyte characters * * @return void */ public function testOutputUtf8() { $data = array( array('Header 1', 'Head', 'Long Header'), array('short', 'ÄÄÄÜÜÜ', 'short'), array('Longer thing', 'longerish', 'Longest Value'), ); $this->helper->output($data); $expected = array( '+--------------+-----------+---------------+', '| Header 1 | Head | Long Header |', '+--------------+-----------+---------------+', '| short | ÄÄÄÜÜÜ | short |', '| Longer thing | longerish | Longest Value |', '+--------------+-----------+---------------+', ); $this->assertEquals($expected, $this->consoleOutput->messages()); } /** * Test output without headers * * @return void */ public function testOutputWithoutHeaderStyle() { $data = array( array('Header 1', 'Header', 'Long Header'), array('short', 'Longish thing', 'short'), array('Longer thing', 'short', 'Longest Value'), ); $this->helper->config(array('headerStyle' => false)); $this->helper->output($data); $expected = array( '+--------------+---------------+---------------+', '| Header 1 | Header | Long Header |', '+--------------+---------------+---------------+', '| short | Longish thing | short |', '| Longer thing | short | Longest Value |', '+--------------+---------------+---------------+', ); $this->assertEquals($expected, $this->consoleOutput->messages()); } /** * Test output with different header style * * @return void */ public function testOutputWithDifferentHeaderStyle() { $data = array( array('Header 1', 'Header', 'Long Header'), array('short', 'Longish thing', 'short'), array('Longer thing', 'short', 'Longest Value'), ); $this->helper->config(array('headerStyle' => 'error')); $this->helper->output($data); $expected = array( '+--------------+---------------+---------------+', '| Header 1 | Header | Long Header |', '+--------------+---------------+---------------+', '| short | Longish thing | short |', '| Longer thing | short | Longest Value |', '+--------------+---------------+---------------+', ); $this->assertEquals($expected, $this->consoleOutput->messages()); } /** * Test output without table headers * * @return void */ public function testOutputWithoutHeaders() { $data = array( array('short', 'Longish thing', 'short'), array('Longer thing', 'short', 'Longest Value'), ); $this->helper->config(array('headers' => false)); $this->helper->output($data); $expected = array( '+--------------+---------------+---------------+', '| short | Longish thing | short |', '| Longer thing | short | Longest Value |', '+--------------+---------------+---------------+', ); $this->assertEquals($expected, $this->consoleOutput->messages()); } /** * Test output with row separator * * @return void */ public function testOutputWithRowSeparator() { $data = array( array('Header 1', 'Header', 'Long Header'), array('short', 'Longish thing', 'short'), array('Longer thing', 'short', 'Longest Value') ); $this->helper->config(array('rowSeparator' => true)); $this->helper->output($data); $expected = array( '+--------------+---------------+---------------+', '| Header 1 | Header | Long Header |', '+--------------+---------------+---------------+', '| short | Longish thing | short |', '+--------------+---------------+---------------+', '| Longer thing | short | Longest Value |', '+--------------+---------------+---------------+', ); $this->assertEquals($expected, $this->consoleOutput->messages()); } /** * Test output with row separator and no headers * * @return void */ public function testOutputWithRowSeparatorAndHeaders() { $data = array( array('Header 1', 'Header', 'Long Header'), array('short', 'Longish thing', 'short'), array('Longer thing', 'short', 'Longest Value'), ); $this->helper->config(array('rowSeparator' => true)); $this->helper->output($data); $expected = array( '+--------------+---------------+---------------+', '| Header 1 | Header | Long Header |', '+--------------+---------------+---------------+', '| short | Longish thing | short |', '+--------------+---------------+---------------+', '| Longer thing | short | Longest Value |', '+--------------+---------------+---------------+', ); $this->assertEquals($expected, $this->consoleOutput->messages()); } }