Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions src/Symfony/Component/Console/Output/ConsoleOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,26 @@ class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
/**
* Constructor.
*
* @param int $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface)
* @param bool|null $decorated Whether to decorate messages (null for auto-guessing)
* @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter)
* @param int $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface)
* @param bool|null $decorated Whether to decorate messages (null for auto-guessing)
* @param OutputFormatterInterface|null $stdoutFormatter Output formatter instance for stdout (null to use default OutputFormatter)
* @param OutputFormatterInterface|null $stderrFormatter Output formatter instance for stderr (null to use stdout OutputFormatter)
*
* @api
*/
public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
{
parent::__construct($this->openOutputStream(), $verbosity, $decorated, $formatter);

$this->stderr = new StreamOutput($this->openErrorStream(), $verbosity, $decorated, $this->getFormatter());
public function __construct(
$verbosity = self::VERBOSITY_NORMAL,
$decorated = null,
OutputFormatterInterface $stdoutFormatter = null,
OutputFormatterInterface $stderrFormatter = null
) {
parent::__construct($this->openOutputStream(), $verbosity, $decorated, $stdoutFormatter);

if (null === $stderrFormatter) {
$stderrFormatter = clone $this->getFormatter();
}

$this->stderr = new StreamOutput($this->openErrorStream(), $verbosity, $decorated, $stderrFormatter);
}

/**
Expand All @@ -66,7 +75,7 @@ public function setDecorated($decorated)
public function setFormatter(OutputFormatterInterface $formatter)
{
parent::setFormatter($formatter);
$this->stderr->setFormatter($formatter);
$this->stderr->setFormatter(clone $formatter);
}

/**
Expand Down
16 changes: 15 additions & 1 deletion src/Symfony/Component/Console/Tests/Output/ConsoleOutputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ public function testConstructor()
{
$output = new ConsoleOutput(Output::VERBOSITY_QUIET, true);
$this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '__construct() takes the verbosity as its first argument');
$this->assertSame($output->getFormatter(), $output->getErrorOutput()->getFormatter(), '__construct() takes a formatter or null as the third argument');
$this->assertNotSame($output->getFormatter(), $output->getErrorOutput()->getFormatter(), '__construct() takes a formatter or null as the third argument');
}

public function testDecorated()
{
$output = new ConsoleOutput(Output::VERBOSITY_QUIET, true);
$this->assertTrue($output->isDecorated(), 'decorate messages if stdout is a tty');
$output->setDecorated(false);
$output->getErrorOutput()->setDecorated(true);
$this->assertTrue(!$output->isDecorated() && $output->getErrorOutput()->isDecorated(), 'if stdout is not a tty, decorate stderr only');

$output = new ConsoleOutput(Output::VERBOSITY_QUIET, true);
$this->assertTrue($output->isDecorated(), 'decorate messages if stdout is a tty');
$output->getErrorOutput()->setDecorated(false);
$this->assertTrue($output->isDecorated() && !$output->getErrorOutput()->isDecorated(), 'if stderr is not a tty, decorate stdout only');
}
}