2010-03-18 07:48:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2010-04-25 16:06:54 +01:00
|
|
|
* This file is part of the Symfony package.
|
2011-01-15 13:29:43 +00:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-03-18 07:48:03 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
namespace Symfony\Tests\Component\Console\Output;
|
2010-03-18 07:48:03 +00:00
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Component\Console\Output\Output;
|
|
|
|
use Symfony\Component\Console\Output\StreamOutput;
|
2010-03-18 07:48:03 +00:00
|
|
|
|
|
|
|
class StreamOutputTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
protected $stream;
|
2010-03-18 07:48:03 +00:00
|
|
|
|
2010-12-06 14:45:37 +00:00
|
|
|
protected function setUp()
|
2010-05-06 12:25:53 +01:00
|
|
|
{
|
|
|
|
$this->stream = fopen('php://memory', 'a', false);
|
|
|
|
}
|
2010-03-18 07:48:03 +00:00
|
|
|
|
2011-06-14 09:44:38 +01:00
|
|
|
protected function tearDown()
|
|
|
|
{
|
|
|
|
$this->stream = null;
|
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
public function testConstructor()
|
2010-03-18 07:48:03 +00:00
|
|
|
{
|
2010-05-07 15:09:11 +01:00
|
|
|
try {
|
2010-05-06 12:25:53 +01:00
|
|
|
$output = new StreamOutput('foo');
|
|
|
|
$this->fail('__construct() throws an \InvalidArgumentException if the first argument is not a stream');
|
2010-05-07 15:09:11 +01:00
|
|
|
} catch (\Exception $e) {
|
2010-05-06 12:25:53 +01:00
|
|
|
$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');
|
2010-03-18 07:48:03 +00:00
|
|
|
}
|
2010-05-06 12:25:53 +01:00
|
|
|
|
|
|
|
public function testGetStream()
|
2010-03-18 07:48:03 +00:00
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
$output = new StreamOutput($this->stream);
|
|
|
|
$this->assertEquals($this->stream, $output->getStream(), '->getStream() returns the current stream');
|
2010-03-18 07:48:03 +00:00
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
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');
|
|
|
|
}
|
2010-03-18 07:48:03 +00:00
|
|
|
}
|