8000 [Console] Separate formatter for stdout/stderr by alcohol · Pull Request #13661 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Separate formatter for stdout/stderr #13661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
[Console] Separate formatter for stdout/stderr
  • Loading branch information
alcohol committed Feb 11, 2015
commit 5c2a6642a59701bb2a57d7f9c5ed00e6c653a054
4 changes: 2 additions & 2 deletions src/Symfony/Component/Console/Output/ConsoleOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = nu

parent::__construct(fopen($outputStream, 'w'), $verbosity, $decorated, $formatter);

$this->stderr = new StreamOutput(fopen('php://stderr', 'w'), $verbosity, $decorated, $this->getFormatter());
$this->stderr = new StreamOutput(fopen('php://stderr', 'w'), $verbosity, $decorated, clone $this->getFormatter());
}

/**
Expand All @@ -68,7 +68,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');
}
}
0