public function UncaughtExceptionTest::testLoggerException in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/System/UncaughtExceptionTest.php \Drupal\system\Tests\System\UncaughtExceptionTest::testLoggerException()
Tests fallback to PHP error log when an exception is thrown while logging.
File
- core/
modules/ system/ src/ Tests/ System/ UncaughtExceptionTest.php, line 246 - Contains \Drupal\system\Tests\System\UncaughtExceptionTest.
Class
- UncaughtExceptionTest
- Tests kernel panic when things are really messed up.
Namespace
Drupal\system\Tests\SystemCode
public function testLoggerException() {
// Ensure the test error log is empty before these tests.
$this
->assertNoErrorsLogged();
$this->expectedExceptionMessage = 'Deforestation';
\Drupal::state()
->set('error_service_test.break_logger', TRUE);
$this
->drupalGet('');
$this
->assertResponse(500);
$this
->assertText('The website encountered an unexpected error. Please try again later.');
$this
->assertRaw($this->expectedExceptionMessage);
// Find fatal error logged to the simpletest error.log
$errors = file(\Drupal::root() . '/' . $this->siteDirectory . '/error.log');
$this
->assertIdentical(count($errors), 2, 'The error + the error that the logging service is broken has been written to the error log.');
$this
->assertTrue(strpos($errors[0], 'Failed to log error') !== FALSE, 'The error handling logs when an error could not be logged to the logger.');
$expected_path = \Drupal::root() . '/core/modules/system/tests/modules/error_service_test/src/MonkeysInTheControlRoom.php';
$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');
// The exception is expected. Do not interpret it as a test failure. Not
// using File API; a potential error must trigger a PHP warning.
unlink(\Drupal::root() . '/' . $this->siteDirectory . '/error.log');
}