4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Console\Tests\Formatter;
14 use Symfony\Component\Console\Formatter\OutputFormatterStyle;
16 class OutputFormatterStyleTest extends \PHPUnit_Framework_TestCase
18 public function testConstructor()
20 $style = new OutputFormatterStyle('green', 'black', array('bold', 'underscore'));
21 $this->assertEquals("\033[32;40;1;4mfoo\033[0m", $style->apply('foo'));
23 $style = new OutputFormatterStyle('red', null, array('blink'));
24 $this->assertEquals("\033[31;5mfoo\033[0m", $style->apply('foo'));
26 $style = new OutputFormatterStyle(null, 'white');
27 $this->assertEquals("\033[47mfoo\033[0m", $style->apply('foo'));
30 public function testForeground()
32 $style = new OutputFormatterStyle();
34 $style->setForeground('black');
35 $this->assertEquals("\033[30mfoo\033[0m", $style->apply('foo'));
37 $style->setForeground('blue');
38 $this->assertEquals("\033[34mfoo\033[0m", $style->apply('foo'));
40 $this->setExpectedException('InvalidArgumentException');
41 $style->setForeground('undefined-color');
44 public function testBackground()
46 $style = new OutputFormatterStyle();
48 $style->setBackground('black');
49 $this->assertEquals("\033[40mfoo\033[0m", $style->apply('foo'));
51 $style->setBackground('yellow');
52 $this->assertEquals("\033[43mfoo\033[0m", $style->apply('foo'));
54 $this->setExpectedException('InvalidArgumentException');
55 $style->setBackground('undefined-color');
58 public function testOptions()
60 $style = new OutputFormatterStyle();
62 $style->setOptions(array('reverse', 'conceal'));
63 $this->assertEquals("\033[7;8mfoo\033[0m", $style->apply('foo'));
65 $style->setOption('bold');
66 $this->assertEquals("\033[7;8;1mfoo\033[0m", $style->apply('foo'));
68 $style->unsetOption('reverse');
69 $this->assertEquals("\033[8;1mfoo\033[0m", $style->apply('foo'));
71 $style->setOption('bold');
72 $this->assertEquals("\033[8;1mfoo\033[0m", $style->apply('foo'));
74 $style->setOptions(array('bold'));
75 $this->assertEquals("\033[1mfoo\033[0m", $style->apply('foo'));