Skip to content

Commit 9832efe

Browse files
Merge branch '5.2' into 5.3
* 5.2: Fix intersection types on tests [Console] fix table setHeaderTitle without headers
2 parents c7fa320 + 2c85cb8 commit 9832efe

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

Helper/Table.php

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

363363
$isHeader = !$this->horizontal;
364364
$isFirstRow = $this->horizontal;
365+
$hasTitle = (bool) $this->headerTitle;
365366
foreach ($rows as $row) {
366367
if ($divider === $row) {
367368
$isHeader = false;
@@ -379,12 +380,13 @@ public function render()
379380
}
380381

381382
if ($isHeader || $isFirstRow) {
382-
if ($isFirstRow) {
383-
$this->renderRowSeparator(self::SEPARATOR_TOP_BOTTOM);
384-
$isFirstRow = false;
385-
} else {
386-
$this->renderRowSeparator(self::SEPARATOR_TOP, $this->headerTitle, $this->style->getHeaderTitleFormat());
387-
}
383+
$this->renderRowSeparator(
384+
$isHeader ? self::SEPARATOR_TOP : self::SEPARATOR_TOP_BOTTOM,
385+
$hasTitle ? $this->headerTitle : null,
386+
$hasTitle ? $this->style->getHeaderTitleFormat() : null
387+
);
388+
$isFirstRow = false;
389+
$hasTitle = false;
388390
}
389391
if ($this->horizontal) {
390392
$this->renderRow($row, $this->style->getCellRowFormat(), $this->style->getCellHeaderFormat());

Tests/Helper/TableTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,27 @@ public function renderSetTitle()
13221322
];
13231323
}
13241324

1325+
public function testSetTitleWithoutHeaders()
1326+
{
1327+
(new Table($output = $this->getOutputStream()))
1328+
->setHeaderTitle('Reproducer')
1329+
->setRows([
1330+
['Value', '123-456'],
1331+
['Some other value', '789-0'],
1332+
])
1333+
->render();
1334+
1335+
$expected = <<<'TABLE'
1336+
+-------- Reproducer --------+
1337+
| Value | 123-456 |
1338+
| Some other value | 789-0 |
1339+
+------------------+---------+
1340+
1341+
TABLE;
1342+
1343+
$this->assertSame($expected, $this->getOutputContent($output));
1344+
}
1345+
13251346
public function testColumnMaxWidths()
13261347
{
13271348
$table = new Table($output = $this->getOutputStream());

0 commit comments

Comments
 (0)