Skip to content

Commit 1e5707f

Browse files
jaydiablofabpot
authored andcommitted
Casting TableCell value to string.
1 parent a35986f commit 1e5707f

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/Symfony/Component/Console/Helper/TableCell.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class TableCell
3535
*/
3636
public function __construct($value = '', array $options = array())
3737
{
38+
if (is_numeric($value) && !is_string($value)) {
39+
$value = (string) $value;
40+
}
41+
3842
$this->value = $value;
3943

4044
// check option names

src/Symfony/Component/Console/Tests/Helper/TableTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,42 @@ public function testRenderMultiByte()
509509
| 1234 |
510510
+------+
511511

512+
TABLE;
513+
514+
$this->assertEquals($expected, $this->getOutputContent($output));
515+
}
516+
517+
public function testTableCellWithNumericIntValue()
518+
{
519+
$table = new Table($output = $this->getOutputStream());
520+
521+
$table->setRows(array(array(new TableCell(12345))));
522+
$table->render();
523+
524+
$expected =
525+
<<<'TABLE'
526+
+-------+
527+
| 12345 |
528+
+-------+
529+
530+
TABLE;
531+
532+
$this->assertEquals($expected, $this->getOutputContent($output));
533+
}
534+
535+
public function testTableCellWithNumericFloatValue()
536+
{
537+
$table = new Table($output = $this->getOutputStream());
538+
539+
$table->setRows(array(array(new TableCell(12345.01))));
540+
$table->render();
541+
542+
$expected =
543+
<<<'TABLE'
544+
+----------+
545+
| 12345.01 |
546+
+----------+
547+
512548
TABLE;
513549

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy