This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/tests/Symfony/Tests/Component/Console/Output/StreamOutputTest.php

55 lines
1.9 KiB
PHP
Raw Normal View History

<?php
/*
2010-04-25 16:06:54 +01:00
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Tests\Component\Console\Output;
use Symfony\Component\Console\Output\Output;
use Symfony\Component\Console\Output\StreamOutput;
class StreamOutputTest extends \PHPUnit_Framework_TestCase
{
protected $stream;
protected function setUp()
{
$this->stream = fopen('php://memory', 'a', false);
}
public function testConstructor()
{
try {
$output = new StreamOutput('foo');
$this->fail('__construct() throws an \InvalidArgumentException if the first argument is not a stream');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '__construct() throws an \InvalidArgumentException if the first argument is not a stream');
$this->assertEquals('The StreamOutput class needs a stream as its first argument.', $e->getMessage());
}
$output = new StreamOutput($this->stream, Output::VERBOSITY_QUIET, true);
$this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '__construct() takes the verbosity as its first argument');
$this->assertTrue($output->isDecorated(), '__construct() takes the decorated flag as its second argument');
}
public function testGetStream()
{
$output = new StreamOutput($this->stream);
$this->assertEquals($this->stream, $output->getStream(), '->getStream() returns the current stream');
}
public function testDoWrite()
{
$output = new StreamOutput($this->stream);
$output->writeln('foo');
rewind($output->getStream());
$this->assertEquals('foo'.PHP_EOL, stream_get_contents($output->getStream()), '->doWrite() writes to the stream');
}
}