bug #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 #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.
This commit is contained in:
Christophe Coevoet 2015-05-20 11:08:20 +02:00
commit ab6400790b
2 changed files with 17 additions and 0 deletions

View File

@ -142,6 +142,7 @@ class OutputFormatter implements OutputFormatterInterface
*/
public function format($message)
{
$message = (string) $message;
$offset = 0;
$output = '';
$tagRegex = '[a-z][a-z0-9_=;-]*';

View File

@ -166,6 +166,14 @@ class OutputFormatterTest extends \PHPUnit_Framework_TestCase
$this->assertEquals("\033[37;41msome error\033[0m".$long, $formatter->format('<error>some error</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 '<info>some info</info>';
}
}