Skip to content

Commit

Permalink
bug #52132 [Console] Fix horizontal table top border is incorrectly r…
Browse files Browse the repository at this point in the history
…endered (OskarStark)

This PR was squashed before being merged into the 6.3 branch.

Discussion
----------

[Console] Fix horizontal table top border is incorrectly rendered

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #52101
| License       | MIT

cc `@alainrinder`

Commits
-------

6ef10c1f07 [Console] Fix horizontal table top border is incorrectly rendered
  • Loading branch information
nicolas-grekas committed Oct 31, 2023
2 parents 116d7f1 + 69b26af commit 0d14a9f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
4 changes: 2 additions & 2 deletions 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 Tests/Helper/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1998,4 +1998,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 0d14a9f

Please sign in to comment.