function UncaughtExceptionTest::testUncaughtException

Same name in other branches
  1. 9 core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php \Drupal\FunctionalTests\Bootstrap\UncaughtExceptionTest::testUncaughtException()
  2. 10 core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php \Drupal\FunctionalTests\Bootstrap\UncaughtExceptionTest::testUncaughtException()
  3. 11.x core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php \Drupal\FunctionalTests\Bootstrap\UncaughtExceptionTest::testUncaughtException()

Tests uncaught exception handling when system is in a bad state.

File

core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php, line 72

Class

UncaughtExceptionTest
Tests kernel panic when things are really messed up.

Namespace

Drupal\FunctionalTests\Bootstrap

Code

public function testUncaughtException() {
    $this->expectedExceptionMessage = 'Oh oh, bananas in the instruments.';
    \Drupal::state()->set('error_service_test.break_bare_html_renderer', TRUE);
    $this->config('system.logging')
        ->set('error_level', ERROR_REPORTING_HIDE)
        ->save();
    $settings = [];
    $settings['config']['system.logging']['error_level'] = (object) [
        'value' => ERROR_REPORTING_HIDE,
        'required' => TRUE,
    ];
    $this->writeSettings($settings);
    $this->drupalGet('');
    $this->assertResponse(500);
    $this->assertText('The website encountered an unexpected error. Please try again later.');
    $this->assertNoText($this->expectedExceptionMessage);
    $this->config('system.logging')
        ->set('error_level', ERROR_REPORTING_DISPLAY_ALL)
        ->save();
    $settings = [];
    $settings['config']['system.logging']['error_level'] = (object) [
        'value' => ERROR_REPORTING_DISPLAY_ALL,
        'required' => TRUE,
    ];
    $this->writeSettings($settings);
    $this->drupalGet('');
    $this->assertResponse(500);
    $this->assertText('The website encountered an unexpected error. Please try again later.');
    $this->assertText($this->expectedExceptionMessage);
    $this->assertErrorLogged($this->expectedExceptionMessage);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.