Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Console] Fix horizontal table top border is incorrectly rendered #52132

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this, because $isHeader is always true

$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)
);
}
}