Skip to content

Commit ab64007

Browse files
committed
bug symfony#14513 [console][formater] allow format toString object. (aitboudad)
This PR was submitted for the 2.7 branch but it was merged into the 2.3 branch instead (closes symfony#14513). Discussion ---------- [console][formater] allow format toString object. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Fixed tickets | ~ | Tests pass? | yes | License | MIT reported by @micayael ( https://twitter.com/juanardissone/status/593859683502325761 ) Commits ------- 70b4964 [console][formater] allow format toString object.
2 parents 905bbbd + 70b4964 commit ab64007

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)