Commit 7dd1b2f3 authored by catch's avatar catch
Browse files

Issue #3319170 by longwave, effulgentsia: Change the http_kernel.basic service...

Issue #3319170 by longwave, effulgentsia: Change the http_kernel.basic service to use Symfony 6.2's default of catching all throwables

(cherry picked from commit 37c60ccb)
parent 6f855794
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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']]
+1 −14
Original line number Diff line number Diff line
@@ -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);
  }

}
+24 −0
Original line number Diff line number Diff line
@@ -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.
   */
+0 −21
Original line number Diff line number Diff line
@@ -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.
   */