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:
commit
ab6400790b
@ -142,6 +142,7 @@ class OutputFormatter implements OutputFormatterInterface
|
|||||||
*/
|
*/
|
||||||
public function format($message)
|
public function format($message)
|
||||||
{
|
{
|
||||||
|
$message = (string) $message;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
$output = '';
|
$output = '';
|
||||||
$tagRegex = '[a-z][a-z0-9_=;-]*';
|
$tagRegex = '[a-z][a-z0-9_=;-]*';
|
||||||
|
@ -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));
|
$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()
|
public function testNotDecoratedFormatter()
|
||||||
{
|
{
|
||||||
$formatter = new OutputFormatter(false);
|
$formatter = new OutputFormatter(false);
|
||||||
@ -255,3 +263,11 @@ EOF
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TableCell
|
||||||
|
{
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return '<info>some info</info>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user