From 5b5b2c81c46e42fc2771e4cf60f20fbe4ddfcafe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Wed, 11 Apr 2012 08:04:59 +0200 Subject: [PATCH] [Console] Fixed and added formatter tests. --- .../Tests/Formatter/OutputFormatterTest.php | 53 +++++++++++-------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php b/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php index e90a85897c..0d1bf4104a 100644 --- a/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php +++ b/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php @@ -12,9 +12,16 @@ namespace Symfony\Component\Console\Tests\Formatter; use Symfony\Component\Console\Formatter\OutputFormatter; +use Symfony\Component\Console\Formatter\OutputFormatterStyle; class FormatterStyleTest extends \PHPUnit_Framework_TestCase { + public function testEmptyTag() + { + $formatter = new OutputFormatter(true); + $this->assertEquals("foo<>bar", $formatter->format('foo<>bar')); + } + public function testBundledStyles() { $formatter = new OutputFormatter(true); @@ -25,16 +32,20 @@ class FormatterStyleTest extends \PHPUnit_Framework_TestCase $this->assertTrue($formatter->hasStyle('question')); $this->assertEquals( - "\033[37;41msome error\033[0m", $formatter->format('some error') + "\033[37;41msome error\033[0m", + $formatter->format('some error') ); $this->assertEquals( - "\033[32msome info\033[0m", $formatter->format('some info') + "\033[32msome info\033[0m", + $formatter->format('some info') ); $this->assertEquals( - "\033[33msome comment\033[0m", $formatter->format('some comment') + "\033[33msome comment\033[0m", + $formatter->format('some comment') ); $this->assertEquals( - "\033[30;46msome question\033[0m", $formatter->format('some question') + "\033[30;46msome question\033[0m", + $formatter->format('some question') ); } @@ -43,7 +54,18 @@ class FormatterStyleTest extends \PHPUnit_Framework_TestCase $formatter = new OutputFormatter(true); $this->assertEquals( - "\033[37;41msome \033[32msome info\033[0m error\033[0m", $formatter->format('some some info error') + "\033[37;41msome \033[0m\033[32msome info\033[0m\033[37;41m error\033[0m", + $formatter->format('some some info error') + ); + } + + public function testDeepNestedStyles() + { + $formatter = new OutputFormatter(true); + + $this->assertEquals( + "\033[37;41merror\033[0m\033[32minfo\033[0m\033[33mcomment\033[0m\033[37;41merror\033[0m", + $formatter->format('errorinfocommenterror') ); } @@ -51,36 +73,23 @@ class FormatterStyleTest extends \PHPUnit_Framework_TestCase { $formatter = new OutputFormatter(true); - $style = $this->getMockBuilder('Symfony\Component\Console\Formatter\OutputFormatterStyleInterface')->getMock(); + $style = new OutputFormatterStyle('blue', 'white'); $formatter->setStyle('test', $style); $this->assertEquals($style, $formatter->getStyle('test')); $this->assertNotEquals($style, $formatter->getStyle('info')); - $style - ->expects($this->once()) - ->method('apply') - ->will($this->returnValue('[STYLE_BEG]some custom msg[STYLE_END]')); - - $this->assertEquals("[STYLE_BEG]some custom msg[STYLE_END]", $formatter->format('some custom msg')); + $this->assertEquals("\033[34;47msome custom msg\033[0m", $formatter->format('some custom msg')); } public function testRedefineStyle() { $formatter = new OutputFormatter(true); - $style = $this->getMockBuilder('Symfony\Component\Console\Formatter\OutputFormatterStyleInterface') - ->getMock(); + $style = new OutputFormatterStyle('blue', 'white'); $formatter->setStyle('info', $style); - $style - ->expects($this->once()) - ->method('apply') - ->will($this->returnValue('[STYLE_BEG]some custom msg[STYLE_END]')); - - $this->assertEquals( - "[STYLE_BEG]some custom msg[STYLE_END]", $formatter->format('some custom msg') - ); + $this->assertEquals("\033[34;47msome custom msg\033[0m", $formatter->format('some custom msg')); } public function testInlineStyle()