Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 85ee007

Browse filesBrowse files
author
Amrouche Hamza
committed
[Console] Provide a bugfix where an array could be passed
1 parent 77104a1 commit 85ee007
Copy full SHA for 85ee007

File tree

2 files changed

+23
-1
lines changed
Filter options

2 files changed

+23
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Helper/Table.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,11 +454,16 @@ private function buildTableRows($rows)
454454
* @param int $line
455455
*
456456
* @return array
457+
*
458+
* @throws InvalidArgumentException
457459
*/
458460
private function fillNextRows(array $rows, $line)
459461
{
460462
$unmergedRows = array();
461463
foreach ($rows[$line] as $column => $cell) {
464+
if (!is_string($cell) && !$cell instanceof TableCell) {
465+
throw new InvalidArgumentException('The cell should always be a string or a TableCell, array given.');
466+
}
462467
if ($cell instanceof TableCell && $cell->getRowspan() > 1) {
463468
$nbLines = $cell->getRowspan() - 1;
464469
$lines = array($cell);

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Helper/TableTest.php
+18-1Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Console\Tests\Helper;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Console\Exception\InvalidArgumentException;
1516
use Symfony\Component\Console\Helper\Table;
1617
use Symfony\Component\Console\Helper\TableStyle;
1718
use Symfony\Component\Console\Helper\TableSeparator;
@@ -552,7 +553,7 @@ public function testRenderMultiByte()
552553
$table = new Table($output = $this->getOutputStream());
553554
$table
554555
->setHeaders(array('■■'))
555-
->setRows(array(array(1234)))
556+
->setRows(array(array(new TableCell(1234))))
556557
->setStyle('default')
557558
;
558559
$table->render();
@@ -726,6 +727,22 @@ public function testColumnStyle()
726727
$this->assertEquals($expected, $this->getOutputContent($output));
727728
}
728729

730+
/**
731+
* @expectedException InvalidArgumentException
732+
* @expectedExceptionMessage The cell should always be a string or a TableCell, array given.
733+
*/
734+
public function testThrowsWhenTheCellInAnArray()
735+
{
736+
$table = new Table($output = $this->getOutputStream());
737+
$table
738+
->setHeaders(array('ISBN', 'Title', 'Author', 'Price'))
739+
->setRows(array(
740+
array('99921-58-10-7', array(), 'Dante Alighieri', '9.95'),
741+
));
742+
743+
$table->render();
744+
}
745+
729746
public function testColumnWith()
730747
{
731748
$table = new Table($output = $this->getOutputStream());

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.