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/unit/Symfony/Components/CLI/Output/StreamOutputTest.php
2010-01-04 15:42:28 +01:00

48 lines
1.4 KiB
PHP

<?php
/*
* This file is part of the symfony package.
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
require_once __DIR__.'/../../../../bootstrap.php';
use Symfony\Components\CLI\Output\Output;
use Symfony\Components\CLI\Output\StreamOutput;
$t = new LimeTest(5);
$stream = fopen('php://memory', 'a', false);
// __construct()
$t->diag('__construct()');
try
{
$output = new StreamOutput('foo');
$t->fail('__construct() throws an \InvalidArgumentException if the first argument is not a stream');
}
catch (\InvalidArgumentException $e)
{
$t->pass('__construct() throws an \InvalidArgumentException if the first argument is not a stream');
}
$output = new StreamOutput($stream, Output::VERBOSITY_QUIET, true);
$t->is($output->getVerbosity(), Output::VERBOSITY_QUIET, '__construct() takes the verbosity as its first argument');
$t->is($output->isDecorated(), true, '__construct() takes the decorated flag as its second argument');
// ->getStream()
$t->diag('->getStream()');
$output = new StreamOutput($stream);
$t->is($output->getStream(), $stream, '->getStream() returns the current stream');
// ->doWrite()
$t->diag('->doWrite()');
$output = new StreamOutput($stream);
$output->write('foo');
rewind($output->getStream());
$t->is(stream_get_contents($output->getStream()), "foo\n", '->doWrite() writes to the stream');