1
- <?php
1
+ <?php declare (strict_types= 1 );
2
2
3
- $ baseDir = dirname (__DIR__ );
4
- $ vendorDir = $ baseDir . '/vendor ' ;
5
- $ extraDir = $ baseDir . '/extra ' ;
6
-
7
- require_once $ vendorDir . '/autoload.php ' ;
3
+ require_once dirname (__DIR__ ) . '/vendor/autoload.php ' ;
8
4
9
5
use Bartlett \LoggerTestListenerTrait ;
10
6
7
+ use PHPUnit \Framework \TestListener ;
8
+ use PHPUnit \Framework \TestResult ;
9
+ use PHPUnit \Runner \Version ;
10
+ use PHPUnit \Util \Getopt as GetOptUtil ;
11
+ use PHPUnit \Util \Printer ;
12
+
11
13
use Psr \Log \LoggerAwareTrait ;
12
14
use Psr \Log \AbstractLogger ;
13
15
use Psr \Log \LogLevel ;
14
16
15
- use PHPUnit \Framework \TestListener ;
16
- use PHPUnit \Util \Getopt as GetOptUtil ;
17
- use PHPUnit \Util \Printer as PrinterUtil ;
17
+ use SebastianBergmann \CliParser \Parser as CliParser ;
18
18
19
19
/**
20
20
* Helper to detect phpunit switches, due to lack of implementation in custom printer classes
21
21
* @see https://github.com/sebastianbergmann/phpunit/issues/1674
22
22
*/
23
23
trait GetOpt
24
24
{
25
- public function isVerbose ()
25
+ public function isVerbose (): bool
26
26
{
27
- list ($ opts , $ non_opts ) = GetOptUtil::getopt (
28
- $ _SERVER ['argv ' ],
29
- 'd:c:hv '
30
- );
27
+ list ($ opts , $ non_opts ) = $ this ->parseCliArguments ();
28
+
31
29
$ key = array_search ('--verbose ' , $ non_opts );
32
30
if ($ key === false ) {
33
31
foreach ($ opts as $ opt ) {
@@ -41,15 +39,23 @@ public function isVerbose()
41
39
return is_int ($ key );
42
40
}
43
41
44
- public function isDebug ()
42
+ public function isDebug (): bool
45
43
{
46
- list ($ opts , $ non_opts ) = GetOptUtil::getopt (
47
- $ _SERVER ['argv ' ],
48
- 'd:c:hv '
49
- );
44
+ list ($ opts , $ non_opts ) = $ this ->parseCliArguments ();
45
+
50
46
$ key = array_search ('--debug ' , $ non_opts );
51
47
return is_int ($ key );
52
48
}
49
+
50
+ private function parseCliArguments (): array
51
+ {
52
+ $ parameters = $ _SERVER ['argv ' ];
53
+ $ shortOptions = 'd:c:hv ' ;
54
+ if (version_compare (Version::id (), '9.3.8 ' , 'ge ' )) {
55
+ return (new CliParser )->parse ($ parameters , $ shortOptions );
56
+ }
57
+ return GetOptUtil::parse ($ parameters , $ shortOptions );
58
+ }
53
59
}
54
60
55
61
class Psr3ConsoleLogger extends AbstractLogger
@@ -96,12 +102,10 @@ public function log($level, $message, array $context = array())
96
102
}
97
103
}
98
104
99
- class ResultPrinter extends PrinterUtil implements TestListener
105
+ abstract class BaseResultPrinter extends Printer
100
106
{
101
107
use LoggerTestListenerTrait, LoggerAwareTrait, GetOpt;
102
108
103
- protected $ numAssertions = 0 ;
104
-
105
109
/**
106
110
* {@inheritDoc}
107
111
*/
@@ -116,6 +120,24 @@ public function __construct($out = null)
116
120
} else {
117
121
$ level = LogLevel::NOTICE ;
118
122
}
119
- $ this ->setLogger (new \Psr3ConsoleLogger ('PHPUnitPrinterLogger ' , $ level ));
123
+ $ this ->setLogger (new Psr3ConsoleLogger ('PHPUnitPrinterLogger ' , $ level ));
124
+ }
125
+ }
126
+
127
+ /**
128
+ * Since PHPUnit 9.0.0, PHPUnit\TextUI\ResultPrinter became an interface
129
+ * [#4024](https://github.com/sebastianbergmann/phpunit/issues/4024)
130
+ */
131
+ if (version_compare (Version::id (), '9.0.0 ' , 'ge ' )) {
132
+ final class ResultPrinter extends BaseResultPrinter implements \PHPUnit \TextUI \ResultPrinter
133
+ {
134
+ public function printResult (TestResult $ result ): void
135
+ {
136
+ // none implementation to avoid default printing behavior
137
+ }
138
+ }
139
+ } else {
140
+ final class ResultPrinter extends BaseResultPrinter implements TestListener
141
+ {
120
142
}
121
143
}
0 commit comments