8000 [Console] Fixed boxed table style with colspan by ro0NL · Pull Request #28548 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Fixed boxed table style with colspan #28548

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

Merged
merged 1 commit into from
Sep 22, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 @@ -570,7 +570,7 @@ private function calculateColumnsWidth($rows)
$lengths[] = $this->getCellWidth($row, $column);
}

$this->columnWidths[$column] = max($lengths) + \strlen($this->style->getCellRowContentFormat()) - 2;
$this->columnWidths[$column] = max($lengths) + Helper::strlen($this->style->getCellRowContentFormat()) - 2;
}
}

Expand All @@ -581,7 +581,7 @@ private function calculateColumnsWidth($rows)
*/
private function getColumnSeparatorWidth()
{
return \strlen(sprintf($this->style->getBorderFormat(), $this->style->getVerticalBorderChar()));
return Helper::strlen(sprintf($this->style->getBorderFormat(), $this->style->getVerticalBorderChar()));
}

/**
Expand Down
36 changes: 36 additions & 0 deletions src/Symfony/Component/Console/Tests/Helper/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,42 @@ public function testGetStyleDefinition()
Table::getStyleDefinition('absent');
}

public function testBoxedStyleWithColspan()
{
$boxed = new TableStyle();
$boxed
->setHorizontalBorderChar('─')
->setVerticalBorderChar('│')
->setCrossingChar('┼')
;

$table = new Table($output = $this->getOutputStream());
$table->setStyle($boxed);
$table
->setHeaders(array('ISBN', 'Title', 'Author'))
->setRows(array(
array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri'),
new TableSeparator(),
array(new TableCell('This value spans 3 columns.', array('colspan' => 3))),
))
;
$table->render();

$expected =
<<<TABLE
┼───────────────┼───────────────┼─────────────────┼
│ ISBN │ Title │ Author │
┼───────────────┼───────────────┼─────────────────┼
│ 99921-58-10-7 │ Divine Comedy │ Dante Alighieri │
┼───────────────┼───────────────┼─────────────────┼
│ This value spans 3 columns. │
┼───────────────┼───────────────┼─────────────────┼

TABLE;

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

protected function getOutputStream($decorated = false)
{
return new StreamOutput($this->stream, StreamOutput::VERBOSITY_NORMAL, $decorated);
Expand Down
0