Skip to content

Commit

Permalink
Merge pull request #19 from zf2timo/hotfix/ci-env
Browse files Browse the repository at this point in the history
Fix for #17
  • Loading branch information
zf2timo committed Jan 14, 2016
2 parents 93a3f10 + ba9e789 commit 95339d8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This Result Printer for PHPUnit shows more information in a more readable format

Installation is provided via composer and can be done with the following command:
```bash
$ composer require --dev zf2timo/phpunit-pretty-result-printer:1.0.0
$ composer require --dev zf2timo/phpunit-pretty-result-printer:^1.0
```

To activate the Printer for PHPUnit, just add it to your configuration XML:
Expand All @@ -16,3 +16,11 @@ To activate the Printer for PHPUnit, just add it to your configuration XML:
// ....
</phpunit>
```
# Configuration

In some Environments like Travis, Jenkins or some old Bash Console the UTF-8 Characters ✘ and ✔ are not supported.
You can enable the default PHPUnit symbols by exporting an environment variable:
```bash
$ export PHP_CI=true
$ php vendor/bin/phpunit
```
25 changes: 25 additions & 0 deletions src/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ private function printTestCaseStatus($color, $buffer)
echo str_pad(' ', $padding) . "\t";
}

if ($this->isCIEnvironment()) {
echo $buffer;
$this->column++;
return;
}

switch (strtoupper($buffer)) {
case '.':
$color = 'fg-green,bold';
Expand Down Expand Up @@ -156,4 +162,23 @@ private function fillWithWhitespace($className)
{
return str_pad($className, $this->maxClassNameLength);
}

/**
* Detects if PHPUnit is executed in a CI Environment - in this case the UTF-8 Symbols are
* deactivated because they are not correct displayed in the report.
*
* At the moment only travis is support and when its manually disabled
*
* @return bool
*/
private function isCIEnvironment()
{
if (isset($_SERVER['USER']) && $_SERVER['USER'] === 'travis') {
return true;
} elseif (isset($_SERVER['PHP_CI']) && $_SERVER['PHP_CI'] === 'true') {
return true;
}

return false;
}
}

0 comments on commit 95339d8

Please sign in to comment.