8000 [Console] Provide a bugfix where an array could be passed · symfony/symfony@de502f7 · GitHub
[go: up one dir, main page]

Skip to content

Commit de502f7

Browse files
author
Amrouche Hamza
committed
[Console] Provide a bugfix where an array could be passed
1 parent d2a316f commit de502f7

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

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

Lines 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 (null !== $cell && !$cell instanceof TableCell && !is_scalar($cell) && !(is_object($cell) && method_exists($cell, '__toString'))) {
465+
throw new InvalidArgumentException(sprintf('A cell must be a TableCell, a scalar or an object implementing __toString, %s given.', gettype($cell)));
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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,22 @@ public function testColumnStyle()
726726
$this->assertEquals($expected, $this->getOutputContent($output));
727727
}
728728

729+
/**
730+
* @expectedException \Symfony\Component\Console\Exception\InvalidArgumentException
731+
* @expectedExceptionMessage A cell must be a TableCell, a scalar or an object implementing __toString, array given.
732+
*/
733+
public function testThrowsWhenTheCellInAnArray()
734+
{
735+
$table = new Table($output = $this->getOutputStream());
736+
$table
737+
->setHeaders(array('ISBN', 'Title', 'Author', 'Price'))
738+
->setRows(array(
739+
array('99921-58-10-7', array(), 'Dante Alighieri', '9.95'),
740+
));
741+
742+
$table->render();
743+
}
744+
729745
public function testColumnWith()
730746
{
731747
$table = new Table($output = $this->getOutputStream());

0 commit comments

Comments
 (0)
0