Yaffs site version 1.1
[yaffs-website] / vendor / symfony / console / Tests / Output / StreamOutputTest.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 PHPUnit\Framework\TestCase;
15 use Symfony\Component\Console\Output\Output;
16 use Symfony\Component\Console\Output\StreamOutput;
17
18 class StreamOutputTest extends TestCase
19 {
20     protected $stream;
21
22     protected function setUp()
23     {
24         $this->stream = fopen('php://memory', 'a', false);
25     }
26
27     protected function tearDown()
28     {
29         $this->stream = null;
30     }
31
32     public function testConstructor()
33     {
34         $output = new StreamOutput($this->stream, Output::VERBOSITY_QUIET, true);
35         $this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '__construct() takes the verbosity as its first argument');
36         $this->assertTrue($output->isDecorated(), '__construct() takes the decorated flag as its second argument');
37     }
38
39     /**
40      * @expectedException        \InvalidArgumentException
41      * @expectedExceptionMessage The StreamOutput class needs a stream as its first argument.
42      */
43     public function testStreamIsRequired()
44     {
45         new StreamOutput('foo');
46     }
47
48     public function testGetStream()
49     {
50         $output = new StreamOutput($this->stream);
51         $this->assertEquals($this->stream, $output->getStream(), '->getStream() returns the current stream');
52     }
53
54     public function testDoWrite()
55     {
56         $output = new StreamOutput($this->stream);
57         $output->writeln('foo');
58         rewind($output->getStream());
59         $this->assertEquals('foo'.PHP_EOL, stream_get_contents($output->getStream()), '->doWrite() writes to the stream');
60     }
61 }