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\Output;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Console\Output\Output;
16 use Symfony\Component\Console\Output\StreamOutput;
18 class StreamOutputTest extends TestCase
22 protected function setUp()
24 $this->stream = fopen('php://memory', 'a', false);
27 protected function tearDown()
32 public function testConstructor()
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');
40 * @expectedException \InvalidArgumentException
41 * @expectedExceptionMessage The StreamOutput class needs a stream as its first argument.
43 public function testStreamIsRequired()
45 new StreamOutput('foo');
48 public function testGetStream()
50 $output = new StreamOutput($this->stream);
51 $this->assertEquals($this->stream, $output->getStream(), '->getStream() returns the current stream');
54 public function testDoWrite()
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');