diff --git a/src/TextUI/Command.php b/src/TextUI/Command.php index 929ca366482..363d1b363ac 100644 --- a/src/TextUI/Command.php +++ b/src/TextUI/Command.php @@ -76,6 +76,7 @@ class PHPUnit_TextUI_Command */ protected $longOptions = array( 'colors' => null, + 'nocolor' => null, 'bootstrap=' => null, 'configuration=' => null, 'coverage-clover=' => null, @@ -278,8 +279,16 @@ protected function handleArguments(array $argv) foreach ($this->options[0] as $option) { switch ($option[0]) { - case '--colors': { - $this->arguments['colors'] = true; + case '--colors': + if (function_exists("posix_isatty") && !posix_isatty(STDOUT)) { + $this->arguments['colors'] = false; + } else { + $this->arguments['colors'] = true; + } + break; + + case '--nocolor': { + $this->arguments['colors'] = false; } break; diff --git a/src/Util/Configuration.php b/src/Util/Configuration.php index 9ddcfb8de02..0fcc5fb9e2f 100644 --- a/src/Util/Configuration.php +++ b/src/Util/Configuration.php @@ -582,6 +582,9 @@ public function getPHPUnitConfiguration() $result['colors'] = $this->getBoolean( (string) $root->getAttribute('colors'), false ); + if ($result['colors'] && function_exists("posix_isatty") && !posix_isatty(STDOUT)) { + $result['colors'] = false; + } } /**