diff --git a/core/modules/system/src/Tests/System/UncaughtExceptionTest.php b/core/modules/system/src/Tests/System/UncaughtExceptionTest.php
index 3460125..fe8cdf8 100644
--- a/core/modules/system/src/Tests/System/UncaughtExceptionTest.php
+++ b/core/modules/system/src/Tests/System/UncaughtExceptionTest.php
@@ -137,6 +137,7 @@ public function testMissingDependencyCustomErrorHandler() {
     $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 @@ public function testLoggerException() {
     $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 ef874e5..c2a5633 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 f780d29..f31af5a 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 @@ public function handle(Request $request, $type = self::MASTER_REQUEST, $catch =
       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;
   }
 
 }
