You are here

protected function UncaughtExceptionTest::assertErrorLogged in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php \Drupal\FunctionalTests\Bootstrap\UncaughtExceptionTest::assertErrorLogged()

Asserts that a specific error has been logged to the PHP error log.

Parameters

string $error_message: The expected error message.

See also

\Drupal\simpletest\TestBase::prepareEnvironment()

\Drupal\Core\DrupalKernel::bootConfiguration()

5 calls to UncaughtExceptionTest::assertErrorLogged()
UncaughtExceptionTest::testErrorContainer in core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php
Tests a container which has an error.
UncaughtExceptionTest::testExceptionContainer in core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php
Tests a container which has an exception really early.
UncaughtExceptionTest::testLostDatabaseConnection in core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php
Tests the case when the database connection is gone.
UncaughtExceptionTest::testMissingDependency in core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php
Tests a missing dependency on a service.
UncaughtExceptionTest::testUncaughtException in core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php
Tests uncaught exception handling when system is in a bad state.

File

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

Class

UncaughtExceptionTest
Tests kernel panic when things are really messed up.

Namespace

Drupal\FunctionalTests\Bootstrap

Code

protected function assertErrorLogged($error_message) {
  $error_log_filename = DRUPAL_ROOT . '/' . $this->siteDirectory . '/error.log';
  $this
    ->assertFileExists($error_log_filename);
  $content = file_get_contents($error_log_filename);
  $rows = explode(PHP_EOL, $content);

  // We iterate over the rows in order to be able to remove the logged error
  // afterwards.
  $found = FALSE;
  foreach ($rows as $row_index => $row) {
    if (strpos($content, $error_message) !== FALSE) {
      $found = TRUE;
      unset($rows[$row_index]);
    }
  }
  file_put_contents($error_log_filename, implode("\n", $rows));
  $this
    ->assertTrue($found, sprintf('The %s error message was logged.', $error_message));
}