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
This commit is contained in:
Robin Chalas 2018-01-25 10:33:05 +01:00
commit 05e9682868
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());