3
3
namespace Codedungeon \PHPUnitPrettyResultPrinter ;
4
4
5
5
use Noodlehaus \Config ;
6
- use PHPUnit \TextUI \ ResultPrinter ;
6
+ use PHPUnit \Runner \ Version ;
7
7
use Codedungeon \PHPCliColors \Color ;
8
8
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
+
9
65
/**
10
66
* Class Printer.
11
67
*
12
68
* @license MIT
13
69
*/
14
- class Printer extends ResultPrinter
70
+ class Printer extends _ResultPrinter
15
71
{
16
72
/**
17
73
* @var string
@@ -80,7 +136,7 @@ public function __construct(
80
136
$ this ->configuration = new Config ($ this ->configFileName );
81
137
82
138
$ this ->maxNumberOfColumns = $ this ->getWidth ();
83
- $ this ->maxClassNameLength = min ((int ) ($ this ->maxNumberOfColumns / 2 ), $ this ->maxClassNameLength );
139
+ $ this ->maxClassNameLength = min ((int )($ this ->maxNumberOfColumns / 2 ), $ this ->maxClassNameLength );
84
140
85
141
// setup module options
86
142
$ this ->printerOptions = $ this ->configuration ->all ();
@@ -94,7 +150,7 @@ public function __construct(
94
150
$ this ->init ();
95
151
}
96
152
97
- protected function init (): void
153
+ protected function init ()
98
154
{
99
155
if (!self ::$ init ) {
100
156
$ version = $ this ->version ();
@@ -117,7 +173,7 @@ protected function init(): void
117
173
/**
118
174
* @return string
119
175
*/
120
- public function packageName (): string
176
+ public function packageName ()
121
177
{
122
178
$ content = file_get_contents ($ this ->getPackageRoot () . DIRECTORY_SEPARATOR . 'composer.json ' );
123
179
if ($ content ) {
@@ -129,7 +185,7 @@ public function packageName(): string
129
185
return 'n/a ' ;
130
186
}
131
187
132
- protected function writeProgress ( string $ progress ): void
188
+ protected function writeProgressEx ( $ progress )
133
189
{
134
190
if (!$ this ->debug ) {
135
191
$ this ->printClassName ();
@@ -140,7 +196,7 @@ protected function writeProgress(string $progress): void
140
196
/**
141
197
* {@inheritdoc}
142
198
*/
143
- protected function writeProgressWithColor ( string $ color , string $ buffer ): void
199
+ protected function writeProgressWithColorEx ( $ color , $ buffer )
144
200
{
145
201
if (!$ this ->debug ) {
146
202
$ this ->printClassName ();
@@ -153,7 +209,7 @@ protected function writeProgressWithColor(string $color, string $buffer): void
153
209
* @param string $color
154
210
* @param string $buffer Result of the Test Case => . F S I R
155
211
*/
156
- private function printTestCaseStatus (string $ color , string $ buffer ): void
212
+ private function printTestCaseStatus ($ color , $ buffer )
157
213
{
158
214
if ($ this ->column >= $ this ->maxNumberOfColumns ) {
159
215
$ this ->writeNewLine ();
@@ -201,7 +257,7 @@ private function printTestCaseStatus(string $color, string $buffer): void
201
257
/**
202
258
* Prints the Class Name if it has changed.
203
259
*/
204
- protected function printClassName (): void
260
+ protected function printClassName ()
205
261
{
206
262
if ($ this ->hideClassName ) {
207
263
return ;
@@ -222,7 +278,7 @@ protected function printClassName(): void
222
278
*
223
279
* @return string
224
280
*/
225
- private function formatClassName (string $ className ): string
281
+ private function formatClassName ($ className )
226
282
{
227
283
$ prefix = ' ==> ' ;
228
284
$ ellipsis = '... ' ;
@@ -241,7 +297,12 @@ private function formatClassName(string $className): string
241
297
return $ prefix . $ ellipsis . substr ($ className , \strlen ($ className ) - $ maxLength , $ maxLength ) . $ suffix ;
242
298
}
243
299
244
- private function fillWithWhitespace (string $ className ): string
300
+ /**
301
+ * @param string $className
302
+ *
303
+ * @return string;
304
+ */
305
+ private function fillWithWhitespace ($ className )
245
306
{
246
307
return str_pad ($ className , $ this ->maxClassNameLength );
247
308
}
@@ -251,7 +312,7 @@ private function fillWithWhitespace(string $className): string
251
312
*
252
313
* @return string
253
314
*/
254
- public function getConfigurationFile (string $ configFileName = 'phpunit-printer.yml ' ): string
315
+ public function getConfigurationFile ($ configFileName = 'phpunit-printer.yml ' )
255
316
{
256
317
$ defaultConfigFilename = $ this ->getPackageRoot () . DIRECTORY_SEPARATOR . $ configFileName ;
257
318
@@ -274,15 +335,15 @@ public function getConfigurationFile(string $configFileName = 'phpunit-printer.y
274
335
/**
275
336
* @return bool
276
337
*/
277
- private function isWindows (): bool
338
+ private function isWindows ()
278
339
{
279
340
return strtoupper (substr (PHP_OS , 0 , 3 )) === 'WIN ' ;
280
341
}
281
342
282
343
/**
283
344
* @return string | returns package root
284
345
*/
285
- private function getPackageRoot (): string
346
+ private function getPackageRoot ()
286
347
{
287
348
return \dirname (__FILE__ , 2 );
288
349
}
@@ -292,7 +353,7 @@ private function getPackageRoot(): string
292
353
*
293
354
* @return int
294
355
*/
295
- private function getWidth (): int
356
+ private function getWidth ()
296
357
{
297
358
$ width = 0 ;
298
359
if ($ this ->isWindows ()) {
@@ -303,7 +364,7 @@ private function getWidth(): int
303
364
304
365
// 'stty size' output example: 36 120
305
366
if (\count ($ out ) > 0 ) {
306
- $ width = (int ) explode (' ' , array_pop ($ out ))[1 ];
367
+ $ width = (int )explode (' ' , array_pop ($ out ))[1 ];
307
368
}
308
369
309
370
// handle CircleCI case (probably the same with TravisCI as well)
@@ -314,7 +375,7 @@ private function getWidth(): int
314
375
return $ width ;
315
376
}
316
377
317
- public function version (): string
378
+ public function version ()
318
379
{
319
380
$ content = file_get_contents ($ this ->getPackageRoot () . DIRECTORY_SEPARATOR . 'composer.json ' );
320
381
if ($ content ) {
0 commit comments