From 32a9e1cb2ba0d4bb7234d8c14d7de41fc789bab7 Mon Sep 17 00:00:00 2001 From: effulgentsia Date: Fri, 23 Oct 2015 13:41:55 -0700 Subject: [PATCH] Issue #2599446 by alexpott: UncaughtExceptionTest fails on PHP7 --- .../Tests/System/UncaughtExceptionTest.php | 3 ++- .../error_service_test.services.yml | 1 + .../src/MonkeysInTheControlRoom.php | 19 +++++++++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/core/modules/system/src/Tests/System/UncaughtExceptionTest.php b/core/modules/system/src/Tests/System/UncaughtExceptionTest.php index 3460125aeb1..fe8cdf88f20 100644 --- a/core/modules/system/src/Tests/System/UncaughtExceptionTest.php +++ b/core/modules/system/src/Tests/System/UncaughtExceptionTest.php @@ -137,6 +137,7 @@ class UncaughtExceptionTest extends WebTestBase { $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'); @@ -254,7 +255,7 @@ class UncaughtExceptionTest extends WebTestBase { $this->assertIdentical(count($errors), 1, 'Exactly one line logged to the PHP error log'); $expected_path = \Drupal::root() . '/core/modules/system/tests/modules/error_service_test/src/MonkeysInTheControlRoom.php'; - $expected_line = 61; + $expected_line = 63; $expected_entry = "Failed to log error: Exception: Deforestation in Drupal\\error_service_test\\MonkeysInTheControlRoom->handle() (line ${expected_line} of ${expected_path})"; $this->assert(strpos($errors[0], $expected_entry) !== FALSE, 'Original error logged to the PHP error log when an exception is thrown by a logger'); diff --git a/core/modules/system/tests/modules/error_service_test/error_service_test.services.yml b/core/modules/system/tests/modules/error_service_test/error_service_test.services.yml index ef874e58470..c2a56334caf 100644 --- a/core/modules/system/tests/modules/error_service_test/error_service_test.services.yml +++ b/core/modules/system/tests/modules/error_service_test/error_service_test.services.yml @@ -1,6 +1,7 @@ services: http_middleware.monkeys: class: Drupal\error_service_test\MonkeysInTheControlRoom + arguments: ['@settings'] tags: - { name: http_middleware, priority: 400 } # Set up a service with a missing class dependency. 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 f780d29e05f..f31af5a3766 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 @@ -6,6 +6,7 @@ namespace Drupal\error_service_test; +use Drupal\Core\Site\Settings; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -29,8 +30,9 @@ class MonkeysInTheControlRoom implements HttpKernelInterface { * @param \Symfony\Component\HttpKernel\HttpKernelInterface $app * The wrapper HTTP kernel. */ - public function __construct(HttpKernelInterface $app) { + public function __construct(HttpKernelInterface $app, Settings $settings) { $this->app = $app; + $this->settings = $settings; } /** @@ -61,7 +63,20 @@ class MonkeysInTheControlRoom implements HttpKernelInterface { throw new \Exception('Deforestation'); } - return $this->app->handle($request, $type, $catch); + 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; } }