[Console] Provide a bugfix where an array could be passed

This commit is contained in:
Amrouche Hamza 2017-12-08 13:42:23 +01:00
parent d2a316f0db
commit de502f7d6c
No known key found for this signature in database
GPG Key ID: 6968F2785ED4F012
2 changed files with 21 additions and 0 deletions

View File

@ -454,11 +454,16 @@ class Table
* @param int $line
*
* @return array
*
* @throws InvalidArgumentException
*/
private function fillNextRows(array $rows, $line)
{
$unmergedRows = array();
foreach ($rows[$line] as $column => $cell) {
if (null !== $cell && !$cell instanceof TableCell && !is_scalar($cell) && !(is_object($cell) && method_exists($cell, '__toString'))) {
throw new InvalidArgumentException(sprintf('A cell must be a TableCell, a scalar or an object implementing __toString, %s given.', gettype($cell)));
}
if ($cell instanceof TableCell && $cell->getRowspan() > 1) {
$nbLines = $cell->getRowspan() - 1;
$lines = array($cell);

View File

@ -726,6 +726,22 @@ TABLE;
$this->assertEquals($expected, $this->getOutputContent($output));
}
/**
* @expectedException \Symfony\Component\Console\Exception\InvalidArgumentException
* @expectedExceptionMessage A cell must be a TableCell, a scalar or an object implementing __toString, array given.
*/
public function testThrowsWhenTheCellInAnArray()
{
$table = new Table($output = $this->getOutputStream());
$table
->setHeaders(array('ISBN', 'Title', 'Author', 'Price'))
->setRows(array(
array('99921-58-10-7', array(), 'Dante Alighieri', '9.95'),
));
$table->render();
}
public function testColumnWith()
{
$table = new Table($output = $this->getOutputStream());