diff --git a/src/Symfony/Component/Console/Helper/TableCell.php b/src/Symfony/Component/Console/Helper/TableCell.php index aa0d318079..1b34774f26 100644 --- a/src/Symfony/Component/Console/Helper/TableCell.php +++ b/src/Symfony/Component/Console/Helper/TableCell.php @@ -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 diff --git a/src/Symfony/Component/Console/Tests/Helper/TableTest.php b/src/Symfony/Component/Console/Tests/Helper/TableTest.php index 583777b3ca..9d6fb6f163 100644 --- a/src/Symfony/Component/Console/Tests/Helper/TableTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/TableTest.php @@ -538,6 +538,42 @@ TABLE | 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));