Yaffs site version 1.1
[yaffs-website] / vendor / symfony / console / Tests / Formatter / OutputFormatterStyleTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Console\Tests\Formatter;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Console\Formatter\OutputFormatterStyle;
16
17 class OutputFormatterStyleTest extends TestCase
18 {
19     public function testConstructor()
20     {
21         $style = new OutputFormatterStyle('green', 'black', array('bold', 'underscore'));
22         $this->assertEquals("\033[32;40;1;4mfoo\033[39;49;22;24m", $style->apply('foo'));
23
24         $style = new OutputFormatterStyle('red', null, array('blink'));
25         $this->assertEquals("\033[31;5mfoo\033[39;25m", $style->apply('foo'));
26
27         $style = new OutputFormatterStyle(null, 'white');
28         $this->assertEquals("\033[47mfoo\033[49m", $style->apply('foo'));
29     }
30
31     public function testForeground()
32     {
33         $style = new OutputFormatterStyle();
34
35         $style->setForeground('black');
36         $this->assertEquals("\033[30mfoo\033[39m", $style->apply('foo'));
37
38         $style->setForeground('blue');
39         $this->assertEquals("\033[34mfoo\033[39m", $style->apply('foo'));
40
41         $style->setForeground('default');
42         $this->assertEquals("\033[39mfoo\033[39m", $style->apply('foo'));
43
44         $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException');
45         $style->setForeground('undefined-color');
46     }
47
48     public function testBackground()
49     {
50         $style = new OutputFormatterStyle();
51
52         $style->setBackground('black');
53         $this->assertEquals("\033[40mfoo\033[49m", $style->apply('foo'));
54
55         $style->setBackground('yellow');
56         $this->assertEquals("\033[43mfoo\033[49m", $style->apply('foo'));
57
58         $style->setBackground('default');
59         $this->assertEquals("\033[49mfoo\033[49m", $style->apply('foo'));
60
61         $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException');
62         $style->setBackground('undefined-color');
63     }
64
65     public function testOptions()
66     {
67         $style = new OutputFormatterStyle();
68
69         $style->setOptions(array('reverse', 'conceal'));
70         $this->assertEquals("\033[7;8mfoo\033[27;28m", $style->apply('foo'));
71
72         $style->setOption('bold');
73         $this->assertEquals("\033[7;8;1mfoo\033[27;28;22m", $style->apply('foo'));
74
75         $style->unsetOption('reverse');
76         $this->assertEquals("\033[8;1mfoo\033[28;22m", $style->apply('foo'));
77
78         $style->setOption('bold');
79         $this->assertEquals("\033[8;1mfoo\033[28;22m", $style->apply('foo'));
80
81         $style->setOptions(array('bold'));
82         $this->assertEquals("\033[1mfoo\033[22m", $style->apply('foo'));
83
84         try {
85             $style->setOption('foo');
86             $this->fail('->setOption() throws an \InvalidArgumentException when the option does not exist in the available options');
87         } catch (\Exception $e) {
88             $this->assertInstanceOf('\InvalidArgumentException', $e, '->setOption() throws an \InvalidArgumentException when the option does not exist in the available options');
89             $this->assertContains('Invalid option specified: "foo"', $e->getMessage(), '->setOption() throws an \InvalidArgumentException when the option does not exist in the available options');
90         }
91
92         try {
93             $style->unsetOption('foo');
94             $this->fail('->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options');
95         } catch (\Exception $e) {
96             $this->assertInstanceOf('\InvalidArgumentException', $e, '->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options');
97             $this->assertContains('Invalid option specified: "foo"', $e->getMessage(), '->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options');
98         }
99     }
100 }