You are here

public function UncaughtExceptionTest::testUncaughtExceptionCustomExceptionHandler in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/System/UncaughtExceptionTest.php \Drupal\system\Tests\System\UncaughtExceptionTest::testUncaughtExceptionCustomExceptionHandler()

Tests uncaught exception handling with custom exception handler.

File

core/modules/system/src/Tests/System/UncaughtExceptionTest.php, line 96
Contains \Drupal\system\Tests\System\UncaughtExceptionTest.

Class

UncaughtExceptionTest
Tests kernel panic when things are really messed up.

Namespace

Drupal\system\Tests\System

Code

public function testUncaughtExceptionCustomExceptionHandler() {
  $settings_filename = $this->siteDirectory . '/settings.php';
  chmod($settings_filename, 0777);
  $settings_php = file_get_contents($settings_filename);
  $settings_php .= "\n";
  $settings_php .= "set_exception_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 .= "});\n";
  file_put_contents($settings_filename, $settings_php);
  \Drupal::state()
    ->set('error_service_test.break_bare_html_renderer', TRUE);
  $this
    ->drupalGet('');
  $this
    ->assertResponse(418);
  $this
    ->assertNoText('The website encountered an unexpected error. Please try again later.');
  $this
    ->assertNoText('Oh oh, bananas in the instruments');
  $this
    ->assertText('Oh oh, flying teapots');
}