Skip to content

Commit 095bca8

Browse files
committed
Prevent E_USER_DEPRECATED errors from being fatal
The upcoming Twig v3 calls `trigger_error()` with a level of E_USER_DEPRECATED which would be caught by the exception handler and treated as a fatal error. This commit ensures that the error is reported but not shown.
1 parent 5c7c892 commit 095bca8

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Bootstrappers/RegisterExceptionHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function handleError($level, $message, $file = '', $line = 0, $context =
9494
{
9595
$exception = new ErrorException($message, 0, $level, $file, $line);
9696

97-
if ($level === E_USER_NOTICE) {
97+
if ($level === E_USER_NOTICE || $level === E_USER_DEPRECATED) {
9898
$this->getExceptionHandler()->report($exception);
9999
return;
100100
}

tests/Unit/Bootstrappers/RegisterExceptionHandlerTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,26 @@ public function E_USER_NOTICE_errors_are_not_converted_to_exceptions()
6262
$bootstrapper->handleError(E_USER_NOTICE, 'Test Error');
6363
}
6464

65+
/**
66+
* @test
67+
*/
68+
public function E_USER_DEPRECATED_errors_are_not_converted_to_exceptions()
69+
{
70+
Functions\expect('is_admin')->once()->andReturn(false);
71+
72+
$app = new Application;
73+
$handler = Mockery::mock(HandlerInterface::class);
74+
$app->bind(HandlerInterface::class, $handler);
75+
76+
$handler->shouldReceive('report')->once()->with(Mockery::on(function ($e) {
77+
return $e->getSeverity() === E_USER_DEPRECATED && $e->getMessage() === 'Test Error';
78+
}));
79+
80+
$bootstrapper = new RegisterExceptionHandler();
81+
$bootstrapper->bootstrap($app);
82+
$bootstrapper->handleError(E_USER_DEPRECATED, 'Test Error');
83+
}
84+
6585
/** @test */
6686
public function handle_exception_should_call_handlers_report_and_render_methods()
6787
{

0 commit comments

Comments
 (0)