8000 Fix ANSI when stdErr is not a tty · symfony/symfony@f3a398b · GitHub
[go: up one dir, main page]

Skip to content

Commit f3a398b

Browse files
committed
Fix ANSI when stdErr is not a tty
1 parent e5ec204 commit f3a398b

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/Symfony/Component/Console/Output/ConsoleOutput.php

Lines changed: 7 additions & 0 deletions
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

src/Symfony/Component/Console/Tests/Output/ConsoleOutputTest.php

Lines changed: 11 additions & 2 deletions
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)
0