Skip to content

Commit

Permalink
[Console] Fix horizontal table top border is incorrectly rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
OskarStark authored and nicolas-grekas committed Oct 31, 2023
1 parent fbd3a63 commit 6ef10c1
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Symfony/Component/Console/Helper/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public function render()

if ($isHeader && !$isHeaderSeparatorRendered) {
$this->renderRowSeparator(
$isHeader ? self::SEPARATOR_TOP : self::SEPARATOR_TOP_BOTTOM,
self::SEPARATOR_TOP,
$hasTitle ? $this->headerTitle : null,
$hasTitle ? $this->style->getHeaderTitleFormat() : null
);
Expand All @@ -421,7 +421,7 @@ public function render()

if ($isFirstRow) {
$this->renderRowSeparator(
$isHeader ? self::SEPARATOR_TOP : self::SEPARATOR_TOP_BOTTOM,
$horizontal ? self::SEPARATOR_TOP : self::SEPARATOR_TOP_BOTTOM,
$hasTitle ? $this->headerTitle : null,
$hasTitle ? $this->style->getHeaderTitleFormat() : null
);
Expand Down
59 changes: 59 additions & 0 deletions src/Symfony/Component/Console/Tests/Helper/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1997,4 +1997,63 @@ public function testWithHyperlinkAndMaxWidth()

$this->assertSame($expected, $this->getOutputContent($output));
}

public function testGithubIssue52101HorizontalTrue()
{
$tableStyle = (new TableStyle())
->setHorizontalBorderChars('─')
->setVerticalBorderChars('│')
->setCrossingChars('┼', '┌', '┬', '┐', '┤', '┘', '┴', '└', '├')
;

$table = (new Table($output = $this->getOutputStream()))
->setStyle($tableStyle)
->setHeaderTitle('Title')
->setHeaders(['Hello', 'World'])
->setRows([[1, 2], [3, 4]])
->setHorizontal(true)
;
$table->render();

$this->assertSame(<<<TABLE
┌──── Title ┬───┐
│ Hello │ 1 │ 3 │
│ World │ 2 │ 4 │
└───────┴───┴───┘
TABLE
,
$this->getOutputContent($output)
);
}

public function testGithubIssue52101HorizontalFalse()
{
$tableStyle = (new TableStyle())
->setHorizontalBorderChars('─')
->setVerticalBorderChars('│')
->setCrossingChars('┼', '┌', '┬', '┐', '┤', '┘', '┴', '└', '├')
;

$table = (new Table($output = $this->getOutputStream()))
->setStyle($tableStyle)
->setHeaderTitle('Title')
->setHeaders(['Hello', 'World'])
->setRows([[1, 2], [3, 4]])
->setHorizontal(false)
;
$table->render();

$this->assertSame(<<<TABLE
┌──── Title ────┐
│ Hello │ World │
├───────┼───────┤
│ 1 │ 2 │
│ 3 │ 4 │
└───────┴───────┘
TABLE,
$this->getOutputContent($output)
);
}
}

0 comments on commit 6ef10c1

Please sign in to comment.