Skip to content

Commit 7565f82

Browse files
committed
Fix #137
1 parent efac638 commit 7565f82

7 files changed

+32
-19
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ NOTES.md
1212
tickets/*
1313
vendor/
1414
sandbox/
15-
scripts/
15+
scripts/
16+
*.taskpaper

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codedungeon/phpunit-result-printer",
3-
"version": "0.24.1",
3+
"version": "0.25.0",
44
"description": "PHPUnit Pretty Result Printer",
55
"keywords": [
66
"phpunit",

phpunit.ci.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit backupGLobals="false"
3-
colors="true"
3+
colors="false"
44
bootstrap="vendor/autoload.php"
55
failOnRisky="false"
66
processIsolation="false"

src/PrinterInit.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ public function __construct()
1515
{
1616
}
1717

18-
public function init()
18+
public function init($use_colors = "never")
1919
{
20+
2021
$phpunit_xml_file = './phpunit.xml';
2122
if (!file_exists($phpunit_xml_file)) {
2223
$phpunit_xml_file = './phpunit.xml.dist';

src/PrinterTrait.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ public function __construct(
9595
$this->maxClassNameLength = 32;
9696
}
9797

98-
$this->init();
98+
99+
$this->init($colors);
99100
}
100101

101102
/**
@@ -151,22 +152,33 @@ public function packageName()
151152
return '<unknown>';
152153
}
153154

154-
protected function init()
155+
protected function init($use_color = "always")
155156
{
156157
if (!self::$init) {
157158
$version = $this->version();
158159
$name = $this->packageName();
159160
echo PHP_EOL;
160-
echo $this->colorsTool->green() . "${name} ${version} by Codedungeon and contributors." . PHP_EOL;
161-
echo $this->colorsTool->reset();
161+
if($use_color !== "never") {
162+
echo $this->colorsTool->green() . "${name} ${version} by Codedungeon and contributors." . PHP_EOL;
163+
echo $this->colorsTool->reset();
164+
} else {
165+
echo "${name} ${version} by Codedungeon and contributors." . PHP_EOL;
166+
}
167+
162168

163169
if ($this->showConfig) {
164170
$home = getenv('HOME');
165171
$filename = str_replace($home, '~', $this->configFileName);
166172

167-
echo $this->colorsTool->yellow() . '==> Configuration: ';
168-
echo $this->colorsTool->yellow() . $filename;
169-
echo $this->colorsTool->reset();
173+
if($use_color !== "never")
174+
{
175+
echo $this->colorsTool->yellow() . '==> Configuration: ';
176+
echo $this->colorsTool->yellow() . $filename;
177+
echo $this->colorsTool->reset();
178+
} else {
179+
echo "'==> Configuration: '";
180+
echo $filename;
181+
}
170182
echo PHP_EOL . PHP_EOL;
171183
}
172184

src/ResultPrinter71.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ protected function writeProgressWithColor(string $progress, string $buffer): voi
3939
protected function printFooter(TestResult $result): void
4040
{
4141
parent::printFooter($result);
42-
4342
if ($this->anyBarEnabled) {
4443
$phanyBar = new Phanybar();
4544
if (sizeof($result->failures())) {
@@ -69,7 +68,6 @@ protected function formatExceptionMsg($exceptionMessage): string
6968
$exceptionMessage = $this->setMessageColor('risky', 'This test did not perform any assertions.');
7069
} else {
7170
$marker = $this->markers['fail'];
72-
7371
if ($this->colors) {
7472
$exceptionMessage = preg_replace('/^(Exception.*)$/m', "\033[01;31m$1\033[0m", $exceptionMessage);
7573
$exceptionMessage = preg_replace('/(Failed.*)$/m', "\033[01;31m %1\$s$1\033[0m", $exceptionMessage);
@@ -82,7 +80,7 @@ protected function formatExceptionMsg($exceptionMessage): string
8280

8381
$exceptionMessage = ' ' . $exceptionMessage;
8482

85-
return $exceptionMessage;
83+
return "$exceptionMessage";
8684
}
8785

8886
protected function printDefectTrace(TestFailure $defect):void
@@ -169,13 +167,14 @@ protected function setMessageColor(string $type, $msg): string
169167
$marker = 'skipped';
170168
}
171169

172-
// if user turned off colors, reset to white
170+
// if user turned off colors, return msg as we are down
173171
if (!$this->colors) {
174-
$color = '37';
172+
return $msg;
175173
}
176-
$testMarker = $this->markers[$marker] ?? '';
177174

178-
return "\033[01;{$color}m{$testMarker}{$msg}\033[0m";
175+
// otherwise, we have colors enabled and time to make it pretty
176+
$testMarker = $this->markers[$marker] ?? '';
177+
return "\033[01;{$color}m{$testMarker}{$msg}\033[0m";
179178
}
180179
}
181180
}

src/init.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
require_once 'PrinterInit.php';
44

55
$init = new PrinterInit();
6-
$init->init();
6+
$init->init("always");

0 commit comments

Comments
 (0)