2
2
/**
3
3
* This file is part of the leanphp/phpspec-code-coverage package
4
4
*
5
+
6
+ * @license MIT
7
+ *
5
8
* For the full copyright and license information, please see the LICENSE file
6
9
* that was distributed with this source code.
7
10
*
8
- * @license MIT
9
11
*/
10
12
namespace LeanPHP \PhpSpec \CodeCoverage \Listener ;
11
13
@@ -26,6 +28,7 @@ class CodeCoverageListener implements EventSubscriberInterface
26
28
private $ io ;
27
29
private $ options ;
28
30
private $ enabled ;
31
+ private $ skipCoverage ;
29
32
30
33
/**
31
34
* @param ConsoleIO $io
@@ -47,7 +50,8 @@ public function __construct(ConsoleIO $io, CodeCoverage $coverage, array $report
47
50
'format ' => array ('html ' ),
48
51
);
49
52
50
- $ this ->enabled = !$ skipCoverage && (extension_loaded ('xdebug ' ) || (PHP_SAPI === 'phpdbg ' ));
53
+ $ this ->enabled = extension_loaded ('xdebug ' ) || (PHP_SAPI === 'phpdbg ' );
54
+ $ this ->skipCoverage = $ skipCoverage ;
51
55
}
52
56
53
57
/**
@@ -58,7 +62,7 @@ public function __construct(ConsoleIO $io, CodeCoverage $coverage, array $report
58
62
*/
59
63
public function beforeSuite (SuiteEvent $ event )
60
64
{
61
- if (!$ this ->enabled ) {
65
+ if (!$ this ->enabled || $ this -> skipCoverage ) {
62
66
return ;
63
67
}
64
68
@@ -87,7 +91,7 @@ public function beforeSuite(SuiteEvent $event)
87
91
*/
88
92
public function beforeExample (ExampleEvent $ event )
89
93
{
90
- if (!$ this ->enabled ) {
94
+ if (!$ this ->enabled || $ this -> skipCoverage ) {
91
95
return ;
92
96
}
93
97
@@ -106,7 +110,7 @@ public function beforeExample(ExampleEvent $event)
106
110
*/
107
111
public function afterExample (ExampleEvent $ event )
108
112
{
109
- if (!$ this ->enabled ) {
113
+ if (!$ this ->enabled || $ this -> skipCoverage ) {
110
114
return ;
111
115
}
112
116
@@ -118,9 +122,13 @@ public function afterExample(ExampleEvent $event)
118
122
*/
119
123
public function afterSuite (SuiteEvent $ event )
120
124
{
121
- if (!$ this ->enabled ) {
125
+ if (!$ this ->enabled || $ this -> skipCoverage ) {
122
126
if ($ this ->io && $ this ->io ->isVerbose ()) {
123
- $ this ->io ->writeln ('Did not detect Xdebug extension or phpdbg. No code coverage will be generated. ' );
127
+ if (!$ this ->enabled ) {
128
+ $ this ->io ->writeln ('No code coverage will be generated as neither Xdebug nor phpdbg was detected. ' );
129
+ } elseif ($ this ->skipCoverage ) {
130
+ $ this ->io ->writeln ('Skipping code coverage generation ' );
131
+ }
124
132
}
125
133
126
134
return ;
@@ -155,13 +163,13 @@ public function setOptions(array $options)
155
163
/**
156
164
* {@inheritDoc}
157
165
*/
158
- public static function getSubscribedEvents ()
166
+ public static function getSubscribedEvents (): array
159
167
{
160
- return array (
161
- 'beforeExample ' => array ( 'beforeExample ' , -10 ) ,
162
- 'afterExample ' => array ( 'afterExample ' , -10 ) ,
163
- 'beforeSuite ' => array ( 'beforeSuite ' , -10 ) ,
164
- 'afterSuite ' => array ( 'afterSuite ' , -10 ) ,
165
- ) ;
168
+ return [
169
+ 'beforeExample ' => [ 'beforeExample ' , -10 ] ,
170
+ 'afterExample ' => [ 'afterExample ' , -10 ] ,
171
+ 'beforeSuite ' => [ 'beforeSuite ' , -10 ] ,
172
+ 'afterSuite ' => [ 'afterSuite ' , -10 ] ,
173
+ ] ;
166
174
}
167
175
}
0 commit comments