From d618180a5f709e7e13bed4eeceb903dc86f26ef9 Mon Sep 17 00:00:00 2001 From: Tom Mitchelmore Date: Tue, 24 Mar 2026 13:48:33 +0000 Subject: [PATCH] Include E_NOTICE and E_WARNING in default report-only error levels --- .../RegisterExceptionHandler.php | 2 + .../RegisterExceptionHandlerTest.php | 46 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/Bootstrappers/RegisterExceptionHandler.php b/src/Bootstrappers/RegisterExceptionHandler.php index 64e946d..bb9e93f 100644 --- a/src/Bootstrappers/RegisterExceptionHandler.php +++ b/src/Bootstrappers/RegisterExceptionHandler.php @@ -97,6 +97,8 @@ public function handleError($level, $message, $file = '', $line = 0, $context = $exception = new ErrorException($message, 0, $level, $file, $line); $errorsToReportOnly = $this->app->get('config')->get('app.errors.reportOnly') ?: [ + E_NOTICE, + E_WARNING, E_USER_NOTICE, E_USER_DEPRECATED, E_DEPRECATED diff --git a/tests/Unit/Bootstrappers/RegisterExceptionHandlerTest.php b/tests/Unit/Bootstrappers/RegisterExceptionHandlerTest.php index ff38c42..4f35695 100644 --- a/tests/Unit/Bootstrappers/RegisterExceptionHandlerTest.php +++ b/tests/Unit/Bootstrappers/RegisterExceptionHandlerTest.php @@ -42,6 +42,52 @@ public function errors_are_converted_to_exceptions() $bootstrapper->handleError(E_USER_ERROR, 'Test Error'); } + /** + * @test + */ + public function E_NOTICE_errors_are_not_converted_to_exceptions() + { + Functions\expect('is_admin')->once()->andReturn(false); + + $app = new Application; + $handler = Mockery::mock(HandlerInterface::class); + $app->bind(HandlerInterface::class, $handler); + $config = new Config(); + $app->bind('config', $config); + $app->bind(Config::class, $config); + + $handler->shouldReceive('report')->once()->with(Mockery::on(function ($e) { + return $e->getSeverity() === E_NOTICE && $e->getMessage() === 'Test Error'; + })); + + $bootstrapper = new RegisterExceptionHandler(); + $bootstrapper->bootstrap($app); + $bootstrapper->handleError(E_NOTICE, 'Test Error'); + } + + /** + * @test + */ + public function E_WARNING_errors_are_not_converted_to_exceptions() + { + Functions\expect('is_admin')->once()->andReturn(false); + + $app = new Application; + $handler = Mockery::mock(HandlerInterface::class); + $app->bind(HandlerInterface::class, $handler); + $config = new Config(); + $app->bind('config', $config); + $app->bind(Config::class, $config); + + $handler->shouldReceive('report')->once()->with(Mockery::on(function ($e) { + return $e->getSeverity() === E_WARNING && $e->getMessage() === 'Test Error'; + })); + + $bootstrapper = new RegisterExceptionHandler(); + $bootstrapper->bootstrap($app); + $bootstrapper->handleError(E_WARNING, 'Test Error'); + } + /** * @test */