From 76f1d3d5cc59102bdb26f0ff8f1df0f64d393be9 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Mon, 6 Oct 2014 10:07:39 +0200 Subject: [PATCH 1/3] add --nocolor option to override configuration --- src/TextUI/Command.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/TextUI/Command.php b/src/TextUI/Command.php index 929ca366482..430f31484a0 100644 --- a/src/TextUI/Command.php +++ b/src/TextUI/Command.php @@ -283,6 +283,11 @@ protected function handleArguments(array $argv) } break; + case '--nocolor': { + $this->arguments['colors'] = false; + } + break; + case '--bootstrap': { $this->arguments['bootstrap'] = $option[1]; } From 2d979585ab34c205c270a39165dd7dd29e00072c Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Mon, 6 Oct 2014 10:08:50 +0200 Subject: [PATCH 2/3] declare nocolor option --- src/TextUI/Command.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/TextUI/Command.php b/src/TextUI/Command.php index 430f31484a0..36863dc3db1 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, From cd0a4dc583f54ea985c37836d5b3e2bfb0e1032d Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Mon, 6 Oct 2014 10:10:22 +0200 Subject: [PATCH 3/3] only enable colors when output to a terminal (not to a file) --- src/TextUI/Command.php | 7 +++++-- src/Util/Configuration.php | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/TextUI/Command.php b/src/TextUI/Command.php index 36863dc3db1..363d1b363ac 100644 --- a/src/TextUI/Command.php +++ b/src/TextUI/Command.php @@ -279,8 +279,11 @@ 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; 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; + } } /**