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/Console/Output/OutputTest.php

101 lines
3.3 KiB
PHP
Raw Normal View History

2010-01-04 14:42:28 +00:00
<?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';
2010-01-09 11:57:15 +00:00
use Symfony\Components\Console\Output\Output;
2010-01-04 14:42:28 +00:00
$t = new LimeTest(13);
class TestOutput extends Output
{
public $output = '';
static public function getStyle($name)
{
return static::$styles[$name];
}
public function doWrite($message, $newline)
2010-01-04 14:42:28 +00:00
{
$this->output .= $message.($newline ? "\n" : '');
2010-01-04 14:42:28 +00:00
}
}
// __construct()
$t->diag('__construct()');
$output = new TestOutput(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');
// ->setDecorated() ->isDecorated()
$t->diag('->setDecorated() ->isDecorated()');
$output = new TestOutput();
$output->setDecorated(true);
$t->is($output->isDecorated(), true, 'setDecorated() sets the decorated flag');
// ->setVerbosity() ->getVerbosity()
$t->diag('->setVerbosity() ->getVerbosity()');
$output->setVerbosity(Output::VERBOSITY_QUIET);
$t->is($output->getVerbosity(), Output::VERBOSITY_QUIET, '->setVerbosity() sets the verbosity');
// ::setStyle()
$t->diag('::setStyle()');
Output::setStyle('FOO', array('bg' => 'red', 'fg' => 'yellow', 'blink' => true));
$t->is(TestOutput::getStyle('foo'), array('bg' => 'red', 'fg' => 'yellow', 'blink' => true), '::setStyle() sets a new style');
// ->writeln()
$t->diag('->writeln()');
2010-01-04 14:42:28 +00:00
$output = new TestOutput(Output::VERBOSITY_QUIET);
$output->writeln('foo');
$t->is($output->output, '', '->writeln() outputs nothing if verbosity is set to VERBOSITY_QUIET');
2010-01-04 14:42:28 +00:00
$output = new TestOutput();
$output->writeln(array('foo', 'bar'));
$t->is($output->output, "foo\nbar\n", '->writeln() can take an array of messages to output');
2010-01-04 14:42:28 +00:00
$output = new TestOutput();
$output->writeln('<info>foo</info>', Output::OUTPUT_RAW);
$t->is($output->output, "<info>foo</info>\n", '->writeln() outputs the raw message if OUTPUT_RAW is specified');
2010-01-04 14:42:28 +00:00
$output = new TestOutput();
$output->writeln('<info>foo</info>', Output::OUTPUT_PLAIN);
$t->is($output->output, "foo\n", '->writeln() strips decoration tags if OUTPUT_PLAIN is specified');
2010-01-04 14:42:28 +00:00
$output = new TestOutput();
$output->setDecorated(false);
$output->writeln('<info>foo</info>');
$t->is($output->output, "foo\n", '->writeln() strips decoration tags if decoration is set to false');
2010-01-04 14:42:28 +00:00
$output = new TestOutput();
$output->setDecorated(true);
$output->writeln('<foo>foo</foo>');
$t->is($output->output, "\033[33;41;5mfoo\033[0m\n", '->writeln() decorates the output');
2010-01-04 14:42:28 +00:00
try
{
$output->writeln('<foo>foo</foo>', 24);
$t->fail('->writeln() throws an \InvalidArgumentException when the type does not exist');
2010-01-04 14:42:28 +00:00
}
catch (\InvalidArgumentException $e)
{
$t->pass('->writeln() throws an \InvalidArgumentException when the type does not exist');
2010-01-04 14:42:28 +00:00
}
try
{
$output->writeln('<bar>foo</bar>');
$t->fail('->writeln() throws an \InvalidArgumentException when a style does not exist');
2010-01-04 14:42:28 +00:00
}
catch (\InvalidArgumentException $e)
{
$t->pass('->writeln() throws an \InvalidArgumentException when a style does not exist');
2010-01-04 14:42:28 +00:00
}