8000 [Console] ConsoleOuput::isDecorated is detected from STDOUT and STDERR by giosh94mhz · Pull Request #13449 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] ConsoleOuput::isDecorated is detected from STDOUT and STDERR #13449

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
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
11 changes: 11 additions & 0 deletions src/Symfony/Component/Console/Output/ConsoleOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,21 @@ public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = nu
if (!$this->hasStdoutSupport()) {
$outputStream = 'php://output';
}
$autodetection = null === $decorated;

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

// remember autodetected value for stdout and reset
$stdoutIsDecorated = $this->isDecorated();
if ($autodetection) {
$this->getFormatter()->setDecorated(null);
}

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

if ($this->stderr->isDecorated() !== $stdoutIsDecorated) {
$this->setDecorated(false);
}
}

/**
Expand Down
37 changes: 37 additions & 0 deletions src/Symfony/Component/Console/Tests/Output/ConsoleOutputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@

use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\Output;
use Symfony\Component\Console\Formatter\OutputFormatter;

class ConsoleOutputWithMixedDecoratedSupport extends ConsoleOutput
{
protected function hasColorSupport()
{
// emulate posix_isatty(STDOUT) !== posix_isatty(STDERR)
return !parent::hasColorSupport();
}
}

class ConsoleOutputTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -22,4 +32,31 @@ public function testConstructor()
$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');
}

public function testIsDecorated()
{
$output = new ConsoleOutput(Output::VERBOSITY_QUIET, true);

$this->assertTrue($output->isDecorated());
$this->assertTrue($output->getErrorOutput()->isDecorated());

$output = new ConsoleOutput(Output::VERBOSITY_QUIET, false);

$this->assertFalse($output->isDecorated());
$this->assertFalse($output->getErrorOutput()->isDecorated());
}

public function testMixedDecoratedSupportDetection()
{
$formatter = new OutputFormatter();
$output = new ConsoleOutputWithMixedDecoratedSupport(Output::VERBOSITY_QUIET, null, $formatter);

$this->assertFalse($formatter->isDecorated());
$this->assertFalse($output->isDecorated());
$this->assertFalse($output->getErrorOutput()->isDecorated());

$output = new ConsoleOutputWithMixedDecoratedSupport(Output::VERBOSITY_QUIET);
$this->assertFalse($output->isDecorated());
$this->assertFalse($output->getErrorOutput()->isDecorated());
}
}
0