Skip to content

Commit a7ae68d

Browse files
mvoriseksebastianbergmann
authored andcommitted
Fix ErrorHandler to not silent error_get_last() results
1 parent 870d925 commit a7ae68d

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/Runner/ErrorHandler.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@
99
*/
1010
namespace PHPUnit\Runner;
1111

12+
use const E_COMPILE_ERROR;
13+
use const E_COMPILE_WARNING;
14+
use const E_CORE_ERROR;
15+
use const E_CORE_WARNING;
1216
use const E_DEPRECATED;
17+
use const E_ERROR;
1318
use const E_NOTICE;
19+
use const E_PARSE;
1420
use const E_STRICT;
1521
use const E_USER_DEPRECATED;
1622
use const E_USER_NOTICE;
@@ -30,9 +36,11 @@
3036
*/
3137
final class ErrorHandler
3238
{
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;
3644

3745
public static function instance(): self
3846
{
@@ -146,7 +154,7 @@ public function __invoke(int $errorNumber, string $errorString, string $errorFil
146154
return false;
147155
}
148156

149-
return true;
157+
return false;
150158
}
151159

152160
public function enable(): void
@@ -164,6 +172,9 @@ public function enable(): void
164172
}
165173

166174
$this->enabled = true;
175+
176+
$this->originalErrorReportingLevel = error_reporting();
177+
error_reporting($this->originalErrorReportingLevel & self::UNHANDLEABLE_LEVELS);
167178
}
168179

169180
public function disable(): void
@@ -175,6 +186,9 @@ public function disable(): void
175186
restore_error_handler();
176187

177188
$this->enabled = false;
189+
190+
error_reporting(error_reporting() | $this->originalErrorReportingLevel);
191+
$this->originalErrorReportingLevel = null;
178192
}
179193

180194
public function use(Baseline $baseline): void

0 commit comments

Comments
 (0)