From ee0cc40c87b698480550ebe359534bb833c8622e Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Tue, 14 May 2013 17:58:06 +0200 Subject: [PATCH] [Console] fix NullOutput It should not extend from abstract Output class because than it inherits the useless constructor arguments and applies formatting in write() needlessly. --- .../Component/Console/Output/NullOutput.php | 71 +++++++++++++++++-- .../Console/Tests/Output/NullOutputTest.php | 1 + 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Console/Output/NullOutput.php b/src/Symfony/Component/Console/Output/NullOutput.php index 783d42b656..301b7f5f6a 100644 --- a/src/Symfony/Component/Console/Output/NullOutput.php +++ b/src/Symfony/Component/Console/Output/NullOutput.php @@ -11,24 +11,83 @@ namespace Symfony\Component\Console\Output; +use Symfony\Component\Console\Formatter\OutputFormatter; +use Symfony\Component\Console\Formatter\OutputFormatterInterface; + /** * NullOutput suppresses all output. * * $output = new NullOutput(); * * @author Fabien Potencier + * @author Tobias Schultze * * @api */ -class NullOutput extends Output +class NullOutput implements OutputInterface { /** - * Writes a message to the output. - * - * @param string $message A message to write to the output - * @param Boolean $newline Whether to add a newline or not + * {@inheritdoc} */ - protected function doWrite($message, $newline) + public function setFormatter(OutputFormatterInterface $formatter) { + // do nothing + } + + /** + * {@inheritdoc} + */ + public function getFormatter() + { + // to comply with the interface we must return a OutputFormatterInterface + return new OutputFormatter(); + } + + /** + * {@inheritdoc} + */ + public function setDecorated($decorated) + { + // do nothing + } + + /** + * {@inheritdoc} + */ + public function isDecorated() + { + return false; + } + + /** + * {@inheritdoc} + */ + public function setVerbosity($level) + { + // do nothing + } + + /** + * {@inheritdoc} + */ + public function getVerbosity() + { + return self::VERBOSITY_QUIET; + } + + /** + * {@inheritdoc} + */ + public function writeln($messages, $type = 0) + { + // do nothing + } + + /** + * {@inheritdoc} + */ + public function write($messages, $newline = false, $type = 0) + { + // do nothing } } diff --git a/src/Symfony/Component/Console/Tests/Output/NullOutputTest.php b/src/Symfony/Component/Console/Tests/Output/NullOutputTest.php index b24b7a1f4d..b20ae4e8d0 100644 --- a/src/Symfony/Component/Console/Tests/Output/NullOutputTest.php +++ b/src/Symfony/Component/Console/Tests/Output/NullOutputTest.php @@ -25,6 +25,7 @@ class NullOutputTest extends \PHPUnit_Framework_TestCase $buffer = ob_get_clean(); $this->assertSame('', $buffer, '->write() does nothing (at least nothing is printed)'); + $this->assertFalse($output->isDecorated(), '->isDecorated() returns false'); } public function testVerbosity()