From a67ff2a2d6ad9deb33a23ee8327632417adeac56 Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Fri, 21 Sep 2018 21:54:01 +0200 Subject: [PATCH] [Console] Fixed boxed table style with colspan --- .../Component/Console/Helper/Table.php | 4 +-- .../Console/Tests/Helper/TableTest.php | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Console/Helper/Table.php b/src/Symfony/Component/Console/Helper/Table.php index f3fc3b0b0a..b5c0e91a3c 100644 --- a/src/Symfony/Component/Console/Helper/Table.php +++ b/src/Symfony/Component/Console/Helper/Table.php @@ -570,7 +570,7 @@ class Table $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; } } @@ -581,7 +581,7 @@ class Table */ private function getColumnSeparatorWidth() { - return \strlen(sprintf($this->style->getBorderFormat(), $this->style->getVerticalBorderChar())); + return Helper::strlen(sprintf($this->style->getBorderFormat(), $this->style->getVerticalBorderChar())); } /** diff --git a/src/Symfony/Component/Console/Tests/Helper/TableTest.php b/src/Symfony/Component/Console/Tests/Helper/TableTest.php index 58c620953e..1dadc27258 100644 --- a/src/Symfony/Component/Console/Tests/Helper/TableTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/TableTest.php @@ -745,6 +745,42 @@ TABLE; 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 = + <<assertSame($expected, $this->getOutputContent($output)); + } + protected function getOutputStream($decorated = false) { return new StreamOutput($this->stream, StreamOutput::VERBOSITY_NORMAL, $decorated);