You are here

public function UncaughtExceptionTest::testUncaughtException 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::testUncaughtException()

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

File

core/modules/system/src/Tests/System/UncaughtExceptionTest.php, line 57
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 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);
}