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 Symfony\Component\Console\Output\Output;
15 use Symfony\Component\Console\Output\StreamOutput;
17 class StreamOutputTest extends \PHPUnit_Framework_TestCase
21 protected function setUp()
23 $this->stream = fopen('php://memory', 'a', false);
26 protected function tearDown()
31 public function testConstructor()
34 $output = new StreamOutput('foo');
35 $this->fail('__construct() throws an \InvalidArgumentException if the first argument is not a stream');
36 } catch (\Exception $e) {
37 $this->assertInstanceOf('\InvalidArgumentException', $e, '__construct() throws an \InvalidArgumentException if the first argument is not a stream');
38 $this->assertEquals('The StreamOutput class needs a stream as its first argument.', $e->getMessage());
41 $output = new StreamOutput($this->stream, Output::VERBOSITY_QUIET, true);
42 $this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '__construct() takes the verbosity as its first argument');
43 $this->assertTrue($output->isDecorated(), '__construct() takes the decorated flag as its second argument');
46 public function testGetStream()
48 $output = new StreamOutput($this->stream);
49 $this->assertEquals($this->stream, $output->getStream(), '->getStream() returns the current stream');
52 public function testDoWrite()
54 $output = new StreamOutput($this->stream);
55 $output->writeln('foo');
56 rewind($output->getStream());
57 $this->assertEquals('foo'.PHP_EOL, stream_get_contents($output->getStream()), '->doWrite() writes to the stream');