diff --git a/src/Symfony/Component/Console/Helper/Table.php b/src/Symfony/Component/Console/Helper/Table.php index 8f9e972408540..1d0a22baa3245 100644 --- a/src/Symfony/Component/Console/Helper/Table.php +++ b/src/Symfony/Component/Console/Helper/Table.php @@ -374,6 +374,7 @@ public function render() $isHeader = !$this->horizontal; $isFirstRow = $this->horizontal; + $hasTitle = (bool) $this->headerTitle; foreach ($rows as $row) { if ($divider === $row) { $isHeader = false; @@ -391,12 +392,13 @@ public function render() } if ($isHeader || $isFirstRow) { - if ($isFirstRow) { - $this->renderRowSeparator(self::SEPARATOR_TOP_BOTTOM); - $isFirstRow = false; - } else { - $this->renderRowSeparator(self::SEPARATOR_TOP, $this->headerTitle, $this->style->getHeaderTitleFormat()); - } + $this->renderRowSeparator( + $isHeader ? self::SEPARATOR_TOP : self::SEPARATOR_TOP_BOTTOM, + $hasTitle ? $this->headerTitle : null, + $hasTitle ? $this->style->getHeaderTitleFormat() : null + ); + $isFirstRow = false; + $hasTitle = false; } if ($this->horizontal) { $this->renderRow($row, $this->style->getCellRowFormat(), $this->style->getCellHeaderFormat()); diff --git a/src/Symfony/Component/Console/Tests/Helper/TableTest.php b/src/Symfony/Component/Console/Tests/Helper/TableTest.php index d02d6ea42e30d..eed0b166237fe 100644 --- a/src/Symfony/Component/Console/Tests/Helper/TableTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/TableTest.php @@ -1115,6 +1115,27 @@ public function renderSetTitle() ]; } + public function testSetTitleWithoutHeaders() + { + (new Table($output = $this->getOutputStream())) + ->setHeaderTitle('Reproducer') + ->setRows([ + ['Value', '123-456'], + ['Some other value', '789-0'], + ]) + ->render(); + + $expected = <<<'TABLE' ++-------- Reproducer --------+ +| Value | 123-456 | +| Some other value | 789-0 | ++------------------+---------+ + +TABLE; + + $this->assertSame($expected, $this->getOutputContent($output)); + } + public function testColumnMaxWidths() { $table = new Table($output = $this->getOutputStream());