TYPO3  7.6
OutputFormatterStyleTest.php
Go to the documentation of this file.
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 
15 
16 class OutputFormatterStyleTest extends \PHPUnit_Framework_TestCase
17 {
18  public function testConstructor()
19  {
20  $style = new OutputFormatterStyle('green', 'black', array('bold', 'underscore'));
21  $this->assertEquals("\033[32;40;1;4mfoo\033[39;49;22;24m", $style->apply('foo'));
22 
23  $style = new OutputFormatterStyle('red', null, array('blink'));
24  $this->assertEquals("\033[31;5mfoo\033[39;25m", $style->apply('foo'));
25 
26  $style = new OutputFormatterStyle(null, 'white');
27  $this->assertEquals("\033[47mfoo\033[49m", $style->apply('foo'));
28  }
29 
30  public function testForeground()
31  {
32  $style = new OutputFormatterStyle();
33 
34  $style->setForeground('black');
35  $this->assertEquals("\033[30mfoo\033[39m", $style->apply('foo'));
36 
37  $style->setForeground('blue');
38  $this->assertEquals("\033[34mfoo\033[39m", $style->apply('foo'));
39 
40  $style->setForeground('default');
41  $this->assertEquals("\033[39mfoo\033[39m", $style->apply('foo'));
42 
43  $this->setExpectedException('InvalidArgumentException');
44  $style->setForeground('undefined-color');
45  }
46 
47  public function testBackground()
48  {
49  $style = new OutputFormatterStyle();
50 
51  $style->setBackground('black');
52  $this->assertEquals("\033[40mfoo\033[49m", $style->apply('foo'));
53 
54  $style->setBackground('yellow');
55  $this->assertEquals("\033[43mfoo\033[49m", $style->apply('foo'));
56 
57  $style->setBackground('default');
58  $this->assertEquals("\033[49mfoo\033[49m", $style->apply('foo'));
59 
60  $this->setExpectedException('InvalidArgumentException');
61  $style->setBackground('undefined-color');
62  }
63 
64  public function testOptions()
65  {
66  $style = new OutputFormatterStyle();
67 
68  $style->setOptions(array('reverse', 'conceal'));
69  $this->assertEquals("\033[7;8mfoo\033[27;28m", $style->apply('foo'));
70 
71  $style->setOption('bold');
72  $this->assertEquals("\033[7;8;1mfoo\033[27;28;22m", $style->apply('foo'));
73 
74  $style->unsetOption('reverse');
75  $this->assertEquals("\033[8;1mfoo\033[28;22m", $style->apply('foo'));
76 
77  $style->setOption('bold');
78  $this->assertEquals("\033[8;1mfoo\033[28;22m", $style->apply('foo'));
79 
80  $style->setOptions(array('bold'));
81  $this->assertEquals("\033[1mfoo\033[22m", $style->apply('foo'));
82 
83  try {
84  $style->setOption('foo');
85  $this->fail('->setOption() throws an \InvalidArgumentException when the option does not exist in the available options');
86  } catch (\Exception $e) {
87  $this->assertInstanceOf('\InvalidArgumentException', $e, '->setOption() throws an \InvalidArgumentException when the option does not exist in the available options');
88  $this->assertContains('Invalid option specified: "foo"', $e->getMessage(), '->setOption() throws an \InvalidArgumentException when the option does not exist in the available options');
89  }
90 
91  try {
92  $style->unsetOption('foo');
93  $this->fail('->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options');
94  } catch (\Exception $e) {
95  $this->assertInstanceOf('\InvalidArgumentException', $e, '->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options');
96  $this->assertContains('Invalid option specified: "foo"', $e->getMessage(), '->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options');
97  }
98  }
99 }