8000 [Console] fix table setHeaderTitle without headers · symfony/symfony@e4a0c5d · GitHub
[go: up one dir, main page]

Skip to content

Commit e4a0c5d

Browse files
a1812chalasr
authored andcommitted
[Console] fix table setHeaderTitle without headers
1 parent 154f7e9 commit e4a0c5d

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

src/Symfony/Component/Console/Helper/Table.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ public function render()
374374

375375
$isHeader = !$this->horizontal;
376376
$isFirstRow = $this->horizontal;
377+
$hasTitle = (bool) $this->headerTitle;
377378
foreach ($rows as $row) {
378379
if ($divider === $row) {
379380
$isHeader = false;
@@ -391,12 +392,13 @@ public function render()
391392
}
392393

393394
if ($isHeader || $isFirstRow) {
394-
if ($isFirstRow) {
395-
$this->renderRowSeparator(self::SEPARATOR_TOP_BOTTOM);
396-
$isFirstRow = false;
397-
} else {
398-
$this->renderRowSeparator(self::SEPARATOR_TOP, $this->headerTitle, $this->style->getHeaderTitleFormat());
399-
}
395+
$this->renderRowSeparator(
396+
$isHeader ? self::SEPARATOR_TOP : self::SEPARATOR_TOP_BOTTOM,
397+
$hasTitle ? $this->headerTitle : null,
398+
$hasTitle ? $this->style->getHeaderTitleFormat() : null
399+
);
400+
$isFirstRow = false;
401+
$hasTitle = false;
400402
}
401403
if ($this->horizontal) {
402404
$this->renderRow($row, $this->style->getCellRowFormat(), $this->style->getCellHeaderFormat());

src/Symfony/Component/Console/Tests/Helper/TableTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,27 @@ public function renderSetTitle()
11151115
];
11161116
}
11171117

1118+
public function testSetTitleWithoutHeaders()
1119+
{
1120+
(new Table($output = $this->getOutputStream()))
1121+
->setHeaderTitle('Reproducer')
1122+
->setRows([
1123+
['Value', '123-456'],
1124+
['Some other value', '789-0'],
1125+
])
1126+
->render();
1127+
1128+
$expected = <<<'TABLE'
1129+
+-------- Reproducer --------+
1130+
| Value | 123-456 |
1131+
| Some other value | 789-0 |
1132+
+------------------+---------+
1133+
1134+
TABLE;
1135+
1136+
$this->assertSame($expected, $this->getOutputContent($output));
1137+
}
1138+
11181139
public function testColumnMaxWidths()
11191140
{
11201141
$table = new Table($output = $this->getOutputStream());

0 commit comments

Comments
 (0)
0