Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2c8c6f7

Browse files
bug #28548 [Console] Fixed boxed table style with colspan (ro0NL)
This PR was merged into the 2.8 branch. Discussion ---------- [Console] Fixed boxed table style with colspan | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #28532 | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Commits ------- a67ff2a [Console] Fixed boxed table style with colspan
2 parents 76c2de0 + a67ff2a commit 2c8c6f7

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ private function calculateColumnsWidth($rows)
570570
$lengths[] = $this->getCellWidth($row, $column);
571571
}
572572

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

@@ -581,7 +581,7 @@ private function calculateColumnsWidth($rows)
581581
*/
582582
private function getColumnSeparatorWidth()
583583
{
584-
return \strlen(sprintf($this->style->getBorderFormat(), $this->style->getVerticalBorderChar()));
584+
return Helper::strlen(sprintf($this->style->getBorderFormat(), $this->style->getVerticalBorderChar()));
585585
}
586586

587587
/**

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,42 @@ public function testGetStyleDefinition()
745745
Table::getStyleDefinition('absent');
746746
}
747747

748+
public function testBoxedStyleWithColspan()
749+
{
750+
$boxed = new TableStyle();
751+
$boxed
752+
->setHorizontalBorderChar('')
753+
->setVerticalBorderChar('')
754+
->setCrossingChar('')
755+
;
756+
757+
$table = new Table($output = $this->getOutputStream());
758+
$table->setStyle($boxed);
759+
$table
760+
->setHeaders(array('ISBN', 'Title', 'Author'))
761+
->setRows(array(
762+
array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri'),
763+
new TableSeparator(),
764+
array(new TableCell('This value spans 3 columns.', array('colspan' => 3))),
765+
))
766+
;
767+
$table->render();
768+
769+
$expected =
770+
<<<TABLE
771+
┼───────────────┼───────────────┼─────────────────┼
772+
│ ISBN │ Title │ Author │
773+
┼───────────────┼───────────────┼─────────────────┼
774+
│ 99921-58-10-7 │ Divine Comedy │ Dante Alighieri │
775+
┼───────────────┼───────────────┼─────────────────┼
776+
│ This value spans 3 columns. │
777+
┼───────────────┼───────────────┼─────────────────┼
778+
779+
TABLE;
780+
781+
$this->assertSame($expected, $this->getOutputContent($output));
782+
}
783+
748784
protected function getOutputStream($decorated = false)
749785
{
750786
return new StreamOutput($this->stream, StreamOutput::VERBOSITY_NORMAL, $decorated);

0 commit comments

Comments
 (0)