9
9
*/
10
10
namespace PHPUnit \Runner ;
11
11
12
+ use const E_COMPILE_ERROR ;
13
+ use const E_COMPILE_WARNING ;
14
+ use const E_CORE_ERROR ;
15
+ use const E_CORE_WARNING ;
12
16
use const E_DEPRECATED ;
17
+ use const E_ERROR ;
13
18
use const E_NOTICE ;
19
+ use const E_PARSE ;
14
20
use const E_STRICT ;
15
21
use const E_USER_DEPRECATED ;
16
22
use const E_USER_NOTICE ;
30
36
*/
31
37
final class ErrorHandler
32
38
{
33
- private static ?self $ instance = null ;
34
- private ?Baseline $ baseline = null ;
35
- private bool $ enabled = false ;
39
+ private const UNHANDLEABLE_LEVELS = E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING ;
40
+ private static ?self $ instance = null ;
41
+ private ?Baseline $ baseline = null ;
42
+ private bool $ enabled = false ;
43
+ private ?int $ originalErrorReportingLevel = null ;
36
44
37
45
public static function instance (): self
38
46
{
@@ -146,7 +154,7 @@ public function __invoke(int $errorNumber, string $errorString, string $errorFil
146
154
return false ;
147
155
}
148
156
149
- return true ;
157
+ return false ;
150
158
}
151
159
152
160
public function enable (): void
@@ -164,6 +172,9 @@ public function enable(): void
164
172
}
165
173
166
174
$ this ->enabled = true ;
175
+
176
+ $ this ->originalErrorReportingLevel = error_reporting ();
177
+ error_reporting ($ this ->originalErrorReportingLevel & self ::UNHANDLEABLE_LEVELS );
167
178
}
168
179
169
180
public function disable (): void
@@ -175,6 +186,9 @@ public function disable(): void
175
186
restore_error_handler ();
176
187
177
188
$ this ->enabled = false ;
189
+
190
+ error_reporting (error_reporting () | $ this ->originalErrorReportingLevel );
191
+ $ this ->originalErrorReportingLevel = null ;
178
192
}
179
193
180
194
public function use (Baseline $ baseline ): void
0 commit comments