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
stloyd edf4b87dcb Add missing "tearDown" functions, and some missing variable declaration (this saves for me almost 20MB when run all tests)
Force AsseticBundle tests to use TestCase
Fix test for DoctrineBundle to use TestCase
2011-06-16 15:06:36 +02:00

60 lines
2.0 KiB
PHP

<?php
/*
* 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);
}
protected function tearDown()
{
$this->stream = null;
}
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');
}
}