Skip to content

Commit

Permalink
Merge branch '4.4' into 5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Nov 5, 2020
2 parents e2c7b6b + 95f70e6 commit ae80d52
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Output/ConsoleOutput.php
Expand Up @@ -41,6 +41,13 @@ public function __construct(int $verbosity = self::VERBOSITY_NORMAL, bool $decor
{
parent::__construct($this->openOutputStream(), $verbosity, $decorated, $formatter);

if (null === $formatter) {
// for BC reasons, stdErr has it own Formatter only when user don't inject a specific formatter.
$this->stderr = new StreamOutput($this->openErrorStream(), $verbosity, $decorated);

return;
}

$actualDecorated = $this->isDecorated();
$this->stderr = new StreamOutput($this->openErrorStream(), $verbosity, $decorated, $this->getFormatter());

Expand Down
13 changes: 11 additions & 2 deletions Tests/Output/ConsoleOutputTest.php
Expand Up @@ -18,11 +18,19 @@

class ConsoleOutputTest extends TestCase
{
public function testConstructor()
public function testConstructorWithoutFormatter()
{
$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(), 'ErrorOutput should use it own formatter');
}

public function testConstructorWithFormatter()
{
$output = new ConsoleOutput(Output::VERBOSITY_QUIET, true, $formatter = new OutputFormatter());
$this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '__construct() takes the verbosity as its first argument');
$this->assertSame($formatter, $output->getFormatter());
$this->assertSame($formatter, $output->getErrorOutput()->getFormatter(), 'Output and ErrorOutput should use the same provided formatter');
}

public function testSetFormatter()
Expand All @@ -31,6 +39,7 @@ public function testSetFormatter()
$outputFormatter = new OutputFormatter();
$output->setFormatter($outputFormatter);
$this->assertSame($outputFormatter, $output->getFormatter());
$this->assertSame($outputFormatter, $output->getErrorOutput()->getFormatter());
}

public function testSetVerbosity()
Expand Down

0 comments on commit ae80d52

Please sign in to comment.