Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0d63d18

Browse filesBrowse files
committed
fix table setHeaderTitle without headers
1 parent 45015b9 commit 0d63d18
Copy full SHA for 0d63d18

File tree

Expand file treeCollapse file tree

2 files changed

+55
-6
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+55
-6
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Helper/Table.php
+8-6Lines 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+
$isTitleNeed = (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+
$isTitleNeed ? $this->headerTitle: null,
398+
$isTitleNeed ? $this->style->getHeaderTitleFormat() : null
399+
);
400+
$isFirstRow = false;
401+
$isTitleNeed = false;
400402
}
401403
if ($this->horizontal) {
402404
$this->renderRow($row, $this->style->getCellRowFormat(), $this->style->getCellHeaderFormat());

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Helper/TableTest.php
+47Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,53 @@ public function renderSetTitle()
11101110
| 80-902734-1-6 | And Then There Were None | Agatha Christie |
11111111
+- Page 1/99999999999999999999999999999999999999999999999... -+
11121112

1113+
TABLE
1114+
],
1115+
];
1116+
}
1117+
1118+
/**
1119+
* @dataProvider renderSetTitle2
1120+
*/
1121+
public function testSetTitle2($headerTitle, $headers, $expected)
1122+
{
1123+
(new Table($output = $this->getOutputStream()))
1124+
->setHeaderTitle($headerTitle)
1125+
->setHeaders($headers)
1126+
->setRows([
1127+
['Value', '123-456'],
1128+
['Some other value', '789-0'],
1129+
])
1130+
->render();
1131+
1132+
$this->assertEquals($expected, $this->getOutputContent($output));
1133+
}
1134+
1135+
public function renderSetTitle2(): array
1136+
{
1137+
return [
1138+
[
1139+
'Reproducer',
1140+
[],
1141+
<<<'TABLE'
1142+
+-------- Reproducer --------+
1143+
| Value | 123-456 |
1144+
| Some other value | 789-0 |
1145+
+------------------+---------+
1146+
1147+
TABLE
1148+
],
1149+
[
1150+
'Reproducer',
1151+
['Key', 'Value'],
1152+
<<<'TABLE'
1153+
+-------- Reproducer --------+
1154+
| Key | Value |
1155+
+------------------+---------+
1156+
| Value | 123-456 |
1157+
| Some other value | 789-0 |
1158+
+------------------+---------+
1159+
11131160
TABLE
11141161
],
11151162
];

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.