Skip to content

Commit a3f8ba9

Browse files
Fixed issue where class names not being displayed
1 parent e7468ee commit a3f8ba9

File tree

2 files changed

+79
-18
lines changed

2 files changed

+79
-18
lines changed

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.12.1",
3+
"version": "0.12.2",
44
"description": "PHPUnit Pretty Result Printer",
55
"keywords": ["phpunit", "printer", "result-printer", "composer", "package", "testing"],
66
"license": "MIT",

src/Printer.php

Lines changed: 78 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,71 @@
33
namespace Codedungeon\PHPUnitPrettyResultPrinter;
44

55
use Noodlehaus\Config;
6-
use PHPUnit\TextUI\ResultPrinter;
6+
use PHPUnit\Runner\Version;
77
use Codedungeon\PHPCliColors\Color;
88

9+
// use this entry point for PHPUnit 5.x
10+
if (class_exists('\PHPUnit_TextUI_ResultPrinter')) {
11+
class _ResultPrinter extends \PHPUnit_TextUI_ResultPrinter
12+
{
13+
public function startTest(\PHPUnit_Framework_Test $test)
14+
{
15+
$this->className = \get_class($test);
16+
parent::startTest($test);
17+
}
18+
}
19+
}
20+
21+
// use this entrypoint for PHPUnit 6.x and 7.x
22+
if (class_exists('\PHPUnit\TextUI\ResultPrinter')) {
23+
if (strpos(Version::id(), '7.1') == 0) {
24+
class _ResultPrinter extends \PHPUnit\TextUI\ResultPrinter
25+
{
26+
public function startTest(\PHPUnit\Framework\Test $test): void
27+
{
28+
29+
$this->className = get_class($test);
30+
parent::startTest($test);
31+
}
32+
33+
protected function writeProgress(string $progress): void
34+
{
35+
$this->writeProgressEx($progress);
36+
}
37+
38+
protected function writeProgressWithColor(string $progress, string $buffer): void
39+
{
40+
$this->writeProgressWithColorEx($progress, $buffer);
41+
}
42+
}
43+
} else {
44+
class _ResultPrinter extends \PHPUnit\TextUI\ResultPrinter
45+
{
46+
public function startTest(\PHPUnit\Framework\Test $test)
47+
{
48+
$this->className = get_class($test);
49+
parent::startTest($test);
50+
}
51+
52+
protected function writeProgress($progress)
53+
{
54+
$this->writeProgressEx($progress);
55+
}
56+
57+
protected function writeProgressWithColor($progress, $buffer)
58+
{
59+
$this->writeProgressWithColorEx($progress, $buffer);
60+
}
61+
}
62+
}
63+
}
64+
965
/**
1066
* Class Printer.
1167
*
1268
* @license MIT
1369
*/
14-
class Printer extends ResultPrinter
70+
class Printer extends _ResultPrinter
1571
{
1672
/**
1773
* @var string
@@ -80,7 +136,7 @@ public function __construct(
80136
$this->configuration = new Config($this->configFileName);
81137

82138
$this->maxNumberOfColumns = $this->getWidth();
83-
$this->maxClassNameLength = min((int) ($this->maxNumberOfColumns / 2), $this->maxClassNameLength);
139+
$this->maxClassNameLength = min((int)($this->maxNumberOfColumns / 2), $this->maxClassNameLength);
84140

85141
// setup module options
86142
$this->printerOptions = $this->configuration->all();
@@ -94,7 +150,7 @@ public function __construct(
94150
$this->init();
95151
}
96152

97-
protected function init(): void
153+
protected function init()
98154
{
99155
if (!self::$init) {
100156
$version = $this->version();
@@ -117,7 +173,7 @@ protected function init(): void
117173
/**
118174
* @return string
119175
*/
120-
public function packageName(): string
176+
public function packageName()
121177
{
122178
$content = file_get_contents($this->getPackageRoot() . DIRECTORY_SEPARATOR . 'composer.json');
123179
if ($content) {
@@ -129,7 +185,7 @@ public function packageName(): string
129185
return 'n/a';
130186
}
131187

132-
protected function writeProgress(string $progress): void
188+
protected function writeProgressEx($progress)
133189
{
134190
if (!$this->debug) {
135191
$this->printClassName();
@@ -140,7 +196,7 @@ protected function writeProgress(string $progress): void
140196
/**
141197
* {@inheritdoc}
142198
*/
143-
protected function writeProgressWithColor(string $color, string $buffer): void
199+
protected function writeProgressWithColorEx($color, $buffer)
144200
{
145201
if (!$this->debug) {
146202
$this->printClassName();
@@ -153,7 +209,7 @@ protected function writeProgressWithColor(string $color, string $buffer): void
153209
* @param string $color
154210
* @param string $buffer Result of the Test Case => . F S I R
155211
*/
156-
private function printTestCaseStatus(string $color, string $buffer): void
212+
private function printTestCaseStatus($color, $buffer)
157213
{
158214
if ($this->column >= $this->maxNumberOfColumns) {
159215
$this->writeNewLine();
@@ -201,7 +257,7 @@ private function printTestCaseStatus(string $color, string $buffer): void
201257
/**
202258
* Prints the Class Name if it has changed.
203259
*/
204-
protected function printClassName(): void
260+
protected function printClassName()
205261
{
206262
if ($this->hideClassName) {
207263
return;
@@ -222,7 +278,7 @@ protected function printClassName(): void
222278
*
223279
* @return string
224280
*/
225-
private function formatClassName(string $className): string
281+
private function formatClassName($className)
226282
{
227283
$prefix = ' ==> ';
228284
$ellipsis = '...';
@@ -241,7 +297,12 @@ private function formatClassName(string $className): string
241297
return $prefix . $ellipsis . substr($className, \strlen($className) - $maxLength, $maxLength) . $suffix;
242298
}
243299

244-
private function fillWithWhitespace(string $className): string
300+
/**
301+
* @param string $className
302+
*
303+
* @return string;
304+
*/
305+
private function fillWithWhitespace($className)
245306
{
246307
return str_pad($className, $this->maxClassNameLength);
247308
}
@@ -251,7 +312,7 @@ private function fillWithWhitespace(string $className): string
251312
*
252313
* @return string
253314
*/
254-
public function getConfigurationFile(string $configFileName = 'phpunit-printer.yml'): string
315+
public function getConfigurationFile($configFileName = 'phpunit-printer.yml')
255316
{
256317
$defaultConfigFilename = $this->getPackageRoot() . DIRECTORY_SEPARATOR . $configFileName;
257318

@@ -274,15 +335,15 @@ public function getConfigurationFile(string $configFileName = 'phpunit-printer.y
274335
/**
275336
* @return bool
276337
*/
277-
private function isWindows(): bool
338+
private function isWindows()
278339
{
279340
return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
280341
}
281342

282343
/**
283344
* @return string | returns package root
284345
*/
285-
private function getPackageRoot(): string
346+
private function getPackageRoot()
286347
{
287348
return \dirname(__FILE__, 2);
288349
}
@@ -292,7 +353,7 @@ private function getPackageRoot(): string
292353
*
293354
* @return int
294355
*/
295-
private function getWidth(): int
356+
private function getWidth()
296357
{
297358
$width = 0;
298359
if ($this->isWindows()) {
@@ -303,7 +364,7 @@ private function getWidth(): int
303364

304365
// 'stty size' output example: 36 120
305366
if (\count($out) > 0) {
306-
$width = (int) explode(' ', array_pop($out))[1];
367+
$width = (int)explode(' ', array_pop($out))[1];
307368
}
308369

309370
// handle CircleCI case (probably the same with TravisCI as well)
@@ -314,7 +375,7 @@ private function getWidth(): int
314375
return $width;
315376
}
316377

317-
public function version(): string
378+
public function version()
318379
{
319380
$content = file_get_contents($this->getPackageRoot() . DIRECTORY_SEPARATOR . 'composer.json');
320381
if ($content) {

0 commit comments

Comments
 (0)