diff --git a/core/core.services.yml b/core/core.services.yml index d8a4a5b94e45aafded5adea3818282802a5dc6ad..6b972c88d4ae479ee90a3cca310463dd56084964 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -743,7 +743,7 @@ services: class: Drupal\Core\StackMiddleware\StackedHttpKernel http_kernel.basic: class: Symfony\Component\HttpKernel\HttpKernel - arguments: ['@event_dispatcher', '@controller_resolver', '@request_stack', '@http_kernel.controller.argument_resolver', false] + arguments: ['@event_dispatcher', '@controller_resolver', '@request_stack', '@http_kernel.controller.argument_resolver', true] http_kernel.controller.argument_resolver: class: Symfony\Component\HttpKernel\Controller\ArgumentResolver arguments: ['@http_kernel.controller.argument_metadata_factory', ['@argument_resolver.request_attribute', '@argument_resolver.request', '@argument_resolver.psr7_request', '@argument_resolver.route_match', '@argument_resolver.default']] diff --git a/core/modules/system/tests/modules/error_service_test/src/MonkeysInTheControlRoom.php b/core/modules/system/tests/modules/error_service_test/src/MonkeysInTheControlRoom.php index 2d08efc6fc9e12f5b75ac98f98345b90e28551fc..cef5bb64b81a7a72335491cee2d21979044511b5 100644 --- a/core/modules/system/tests/modules/error_service_test/src/MonkeysInTheControlRoom.php +++ b/core/modules/system/tests/modules/error_service_test/src/MonkeysInTheControlRoom.php @@ -67,20 +67,7 @@ public function handle(Request $request, $type = self::MAIN_REQUEST, $catch = TR throw new \Exception('Deforestation'); } - if ($this->settings->get('teapots', FALSE) && class_exists('\TypeError')) { - try { - $return = $this->app->handle($request, $type, $catch); - } - catch (\TypeError $e) { - header('HTTP/1.1 418 I\'m a teapot'); - print('Oh oh, flying teapots'); - exit; - } - } - else { - $return = $this->app->handle($request, $type, $catch); - } - return $return; + return $this->app->handle($request, $type, $catch); } } diff --git a/core/modules/system/tests/src/Functional/System/ErrorHandlerTest.php b/core/modules/system/tests/src/Functional/System/ErrorHandlerTest.php index 26daf6ec1c9d408239faf662423d1fe875a69096..e9007b51d51f8548a3d64ac5b659b1a9f7f7c322 100644 --- a/core/modules/system/tests/src/Functional/System/ErrorHandlerTest.php +++ b/core/modules/system/tests/src/Functional/System/ErrorHandlerTest.php @@ -92,6 +92,30 @@ public function testErrorHandler() { $this->assertSession()->responseNotContains('<pre class="backtrace">'); } + /** + * Tests a custom error handler set in settings.php. + */ + public function testCustomErrorHandler() { + $settings_filename = $this->siteDirectory . '/settings.php'; + chmod($settings_filename, 0777); + $settings_php = file_get_contents($settings_filename); + $settings_php .= "\n"; + $settings_php .= "set_error_handler(function() {\n"; + $settings_php .= " header('HTTP/1.1 418 I\'m a teapot');\n"; + $settings_php .= " print('Oh oh, flying teapots from a custom error handler');\n"; + $settings_php .= " exit();\n"; + $settings_php .= "});\n"; + file_put_contents($settings_filename, $settings_php); + + // For most types of errors, PHP throws an \Error object that Drupal + // catches, so the error handler is not invoked. To test the error handler, + // generate warnings, which are not thrown/caught. + $this->drupalGet('error-test/generate-warnings'); + + $this->assertSession()->statusCodeEquals(418); + $this->assertSession()->responseContains('Oh oh, flying teapots from a custom error handler'); + } + /** * Tests the exception handler. */ diff --git a/core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php b/core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php index b03e000b48cf4e092fbf9c4853503d4fb6568b38..fbf557fb1b288c3db96f653eaa88c65634013dc0 100644 --- a/core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php +++ b/core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php @@ -143,27 +143,6 @@ public function testMissingDependency() { $this->assertErrorLogged($this->expectedExceptionMessage); } - /** - * Tests a missing dependency on a service with a custom error handler. - */ - public function testMissingDependencyCustomErrorHandler() { - $settings_filename = $this->siteDirectory . '/settings.php'; - chmod($settings_filename, 0777); - $settings_php = file_get_contents($settings_filename); - $settings_php .= "\n"; - $settings_php .= "set_error_handler(function() {\n"; - $settings_php .= " header('HTTP/1.1 418 I\'m a teapot');\n"; - $settings_php .= " print('Oh oh, flying teapots');\n"; - $settings_php .= " exit();\n"; - $settings_php .= "});\n"; - $settings_php .= "\$settings['teapots'] = TRUE;\n"; - file_put_contents($settings_filename, $settings_php); - - $this->drupalGet('broken-service-class'); - $this->assertSession()->statusCodeEquals(418); - $this->assertSession()->responseContains('Oh oh, flying teapots'); - } - /** * Tests a container which has an error. */