Skip to content

Commit d1d8b8f

Browse files
committed
Merge branch '5.1' into 5.x
2 parents 5164210 + ae80d52 commit d1d8b8f

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

Diff for: Output/ConsoleOutput.php

+7
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ public function __construct(int $verbosity = self::VERBOSITY_NORMAL, bool $decor
4141
{
4242
parent::__construct($this->openOutputStream(), $verbosity, $decorated, $formatter);
4343

44+
if (null === $formatter) {
45+
// for BC reasons, stdErr has it own Formatter only when user don't inject a specific formatter.
46+
$this->stderr = new StreamOutput($this->openErrorStream(), $verbosity, $decorated);
47+
48+
return;
49+
}
50+
4451
$actualDecorated = $this->isDecorated();
4552
$this->stderr = new StreamOutput($this->openErrorStream(), $verbosity, $decorated, $this->getFormatter());
4653

Diff for: Tests/Output/ConsoleOutputTest.php

+11-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,19 @@
1818

1919
class ConsoleOutputTest extends TestCase
2020
{
21-
public function testConstructor()
21+
public function testConstructorWithoutFormatter()
2222
{
2323
$output = new ConsoleOutput(Output::VERBOSITY_QUIET, true);
2424
$this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '__construct() takes the verbosity as its first argument');
25-
$this->assertSame($output->getFormatter(), $output->getErrorOutput()->getFormatter(), '__construct() takes a formatter or null as the third argument');
25+
$this->assertNotSame($output->getFormatter(), $output->getErrorOutput()->getFormatter(), 'ErrorOutput should use it own formatter');
26+
}
27+
28+
public function testConstructorWithFormatter()
29+
{
30+
$output = new ConsoleOutput(Output::VERBOSITY_QUIET, true, $formatter = new OutputFormatter());
31+
$this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '__construct() takes the verbosity as its first argument');
32+
$this->assertSame($formatter, $output->getFormatter());
33+
$this->assertSame($formatter, $output->getErrorOutput()->getFormatter(), 'Output and ErrorOutput should use the same provided formatter');
2634
}
2735

2836
public function testSetFormatter()
@@ -31,6 +39,7 @@ public function testSetFormatter()
3139
$outputFormatter = new OutputFormatter();
3240
$output->setFormatter($outputFormatter);
3341
$this->assertSame($outputFormatter, $output->getFormatter());
42+
$this->assertSame($outputFormatter, $output->getErrorOutput()->getFormatter());
3443
}
3544

3645
public function testSetVerbosity()

0 commit comments

Comments
 (0)