Skip to content

Commit

Permalink
Casting TableCell value to string.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydiablo authored and fabpot committed Feb 3, 2017
1 parent a35986f commit 1e5707f
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 @@ -509,6 +509,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 1e5707f

Please sign in to comment.