Skip to content

Commit f4a060f

Browse files
authored
Merge pull request #14158 from cakephp/issue-14147
Add support for NO_COLOR environment variable.
2 parents f5f74e8 + 6885023 commit f4a060f

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

‎src/Console/ConsoleOutput.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ public function __construct(string $stream = 'php://stdout')
175175
(
176176
function_exists('posix_isatty') &&
177177
!posix_isatty($this->_output)
178+
) ||
179+
(
180+
env('NO_COLOR') !== null
178181
)
179182
) {
180183
$this->_outputAs = self::PLAIN;

‎tests/TestCase/Console/ConsoleOutputTest.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ public function tearDown(): void
5656
unset($this->output);
5757
}
5858

59+
public function testNoColorEnvironmentVariable()
60+
{
61+
$_SERVER['NO_COLOR'] = '1';
62+
$output = new ConsoleOutput();
63+
$this->assertSame(ConsoleOutput::PLAIN, $output->getOutputAs());
64+
65+
unset($_SERVER['NO_COLOR']);
66+
}
67+
5968
/**
6069
* test writing with no new line
6170
*

0 commit comments

Comments
 (0)