From 70b4964e4e9431fc135638682b375bce0c5619a5 Mon Sep 17 00:00:00 2001 From: Abdellatif Ait boudad Date: Wed, 20 May 2015 07:26:55 +0000 Subject: [PATCH] [console][formater] allow format toString object. --- .../Console/Formatter/OutputFormatter.php | 1 + .../Tests/Formatter/OutputFormatterTest.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/Symfony/Component/Console/Formatter/OutputFormatter.php b/src/Symfony/Component/Console/Formatter/OutputFormatter.php index 90b1970f4b..a053ac6ba0 100644 --- a/src/Symfony/Component/Console/Formatter/OutputFormatter.php +++ b/src/Symfony/Component/Console/Formatter/OutputFormatter.php @@ -142,6 +142,7 @@ class OutputFormatter implements OutputFormatterInterface */ public function format($message) { + $message = (string) $message; $offset = 0; $output = ''; $tagRegex = '[a-z][a-z0-9_=;-]*'; diff --git a/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php b/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php index 3542680a88..03b789402b 100644 --- a/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php +++ b/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php @@ -166,6 +166,14 @@ class OutputFormatterTest extends \PHPUnit_Framework_TestCase $this->assertEquals("\033[37;41msome error\033[0m".$long, $formatter->format('some error'.$long)); } + public function testFormatToStringObject() + { + $formatter = new OutputFormatter(false); + $this->assertEquals( + 'some info', $formatter->format(new TableCell()) + ); + } + public function testNotDecoratedFormatter() { $formatter = new OutputFormatter(false); @@ -255,3 +263,11 @@ EOF )); } } + +class TableCell +{ + public function __toString() + { + return 'some info'; + } +}