Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / symfony / console / Symfony / Component / Console / Tests / Output / OutputTest.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\Output;
13
14 use Symfony\Component\Console\Output\Output;
15 use Symfony\Component\Console\Formatter\OutputFormatterStyle;
16
17 class OutputTest extends \PHPUnit_Framework_TestCase
18 {
19     public function testConstructor()
20     {
21         $output = new TestOutput(Output::VERBOSITY_QUIET, true);
22         $this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '__construct() takes the verbosity as its first argument');
23         $this->assertTrue($output->isDecorated(), '__construct() takes the decorated flag as its second argument');
24     }
25
26     public function testSetIsDecorated()
27     {
28         $output = new TestOutput();
29         $output->setDecorated(true);
30         $this->assertTrue($output->isDecorated(), 'setDecorated() sets the decorated flag');
31     }
32
33     public function testSetGetVerbosity()
34     {
35         $output = new TestOutput();
36         $output->setVerbosity(Output::VERBOSITY_QUIET);
37         $this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '->setVerbosity() sets the verbosity');
38     }
39
40     public function testWrite()
41     {
42         $fooStyle = new OutputFormatterStyle('yellow', 'red', array('blink'));
43         $output = new TestOutput(Output::VERBOSITY_QUIET);
44         $output->writeln('foo');
45         $this->assertEquals('', $output->output, '->writeln() outputs nothing if verbosity is set to VERBOSITY_QUIET');
46
47         $output = new TestOutput();
48         $output->writeln(array('foo', 'bar'));
49         $this->assertEquals("foo\nbar\n", $output->output, '->writeln() can take an array of messages to output');
50
51         $output = new TestOutput();
52         $output->writeln('<info>foo</info>', Output::OUTPUT_RAW);
53         $this->assertEquals("<info>foo</info>\n", $output->output, '->writeln() outputs the raw message if OUTPUT_RAW is specified');
54
55         $output = new TestOutput();
56         $output->writeln('<info>foo</info>', Output::OUTPUT_PLAIN);
57         $this->assertEquals("foo\n", $output->output, '->writeln() strips decoration tags if OUTPUT_PLAIN is specified');
58
59         $output = new TestOutput();
60         $output->setDecorated(false);
61         $output->writeln('<info>foo</info>');
62         $this->assertEquals("foo\n", $output->output, '->writeln() strips decoration tags if decoration is set to false');
63
64         $output = new TestOutput();
65         $output->getFormatter()->setStyle('FOO', $fooStyle);
66         $output->setDecorated(true);
67         $output->writeln('<foo>foo</foo>');
68         $this->assertEquals("\033[33;41;5mfoo\033[0m\n", $output->output, '->writeln() decorates the output');
69
70         try {
71             $output->writeln('<foo>foo</foo>', 24);
72             $this->fail('->writeln() throws an \InvalidArgumentException when the type does not exist');
73         } catch (\Exception $e) {
74             $this->assertInstanceOf('\InvalidArgumentException', $e, '->writeln() throws an \InvalidArgumentException when the type does not exist');
75             $this->assertEquals('Unknown output type given (24)', $e->getMessage());
76         }
77
78         $output->clear();
79         $output->write('<bar>foo</bar>');
80         $this->assertEquals('<bar>foo</bar>', $output->output, '->write() do nothing when a style does not exist');
81
82         $output->clear();
83         $output->writeln('<bar>foo</bar>');
84         $this->assertEquals("<bar>foo</bar>\n", $output->output, '->writeln() do nothing when a style does not exist');
85     }
86 }
87
88 class TestOutput extends Output
89 {
90     public $output = '';
91
92     public function clear()
93     {
94         $this->output = '';
95     }
96
97     protected function doWrite($message, $newline)
98     {
99         $this->output .= $message.($newline ? "\n" : '');
100     }
101 }