Skip to content

Commit

Permalink
bug #21430 Casting TableCell value to string. (jaydiablo)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 2.7 branch (closes #21430).

Discussion
----------

Casting TableCell value to string.

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #21429
| License       | MIT
| Doc PR        |

PHP throws a catchable fatal error when the value from this method is
used in strstr in the Table class. This fixes the error by casting to a string before returning the value.

Commits
-------

1e5707f Casting TableCell value to string.
  • Loading branch information
fabpot committed Feb 3, 2017
2 parents ff33768 + 1e5707f commit f0d13f4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Symfony/Component/Console/Helper/TableCell.php
Expand Up @@ -35,6 +35,10 @@ class TableCell
*/
public function __construct($value = '', array $options = array())
{
if (is_numeric($value) && !is_string($value)) {
$value = (string) $value;
}

$this->value = $value;

// check option names
Expand Down
36 changes: 36 additions & 0 deletions src/Symfony/Component/Console/Tests/Helper/TableTest.php
Expand Up @@ -538,6 +538,42 @@ public function testRenderMultiByte()
| 1234 |
+------+
TABLE;

$this->assertEquals($expected, $this->getOutputContent($output));
}

public function testTableCellWithNumericIntValue()
{
$table = new Table($output = $this->getOutputStream());

$table->setRows(array(array(new TableCell(12345))));
$table->render();

$expected =
<<<'TABLE'
+-------+
| 12345 |
+-------+
TABLE;

$this->assertEquals($expected, $this->getOutputContent($output));
}

public function testTableCellWithNumericFloatValue()
{
$table = new Table($output = $this->getOutputStream());

$table->setRows(array(array(new TableCell(12345.01))));
$table->render();

$expected =
<<<'TABLE'
+----------+
| 12345.01 |
+----------+
TABLE;

$this->assertEquals($expected, $this->getOutputContent($output));
Expand Down

0 comments on commit f0d13f4

Please sign in to comment.