Skip to content

Commit 70b4964

Browse files
aitboudadstof
authored andcommitted
[console][formater] allow format toString object.
1 parent 905bbbd commit 70b4964

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/Symfony/Component/Console/Formatter/OutputFormatter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public function getStyle($name)
142142
*/
143143
public function format($message)
144144
{
145+
$message = (string) $message;
145146
$offset = 0;
146147
$output = '';
147148
$tagRegex = '[a-z][a-z0-9_=;-]*';

src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,14 @@ public function testFormatLongString()
166166
$this->assertEquals("\033[37;41msome error\033[0m".$long, $formatter->format('<error>some error</error>'.$long));
167167
}
168168

169+
public function testFormatToStringObject()
170+
{
171+
$formatter = new OutputFormatter(false);
172+
$this->assertEquals(
173+
'some info', $formatter->format(new TableCell())
174+
);
175+
}
176+
169177
public function testNotDecoratedFormatter()
170178
{
171179
$formatter = new OutputFormatter(false);
@@ -255,3 +263,11 @@ public function testContentWithLineBreaks()
255263
));
256264
}
257265
}
266+
267+
class TableCell
268+
{
269+
public function __toString()
270+
{
271+
return '<info>some info</info>';
272+
}
273+
}

0 commit comments

Comments
 (0)