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

Skip to content

Commit 05e9682

Browse files
author
Robin Chalas
committed
bug #25397 [Console] Provide a DX where an array could be passed (Simperfit)
This PR was merged into the 3.4 branch. Discussion ---------- [Console] Provide a DX where an array could be passed | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | no <!-- don't forget to update UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | #25394 | License | MIT | Doc PR | none ![img_2941](https://user-images.githubusercontent.com/3451634/33766610-977f77ce-dc1e-11e7-93c1-38dd0038d7f5.jpeg) I think that this is not fixing the root causes that does not appears in 4.1, so maybe there is something better to do. I did not find the root cause So I think it can bo good to fix the problem too. Commits ------- de502f7 [Console] Provide a bugfix where an array could be passed
2 parents f004895 + de502f7 commit 05e9682

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)