You are here

protected function UncaughtExceptionTest::assertErrorLogged in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php \Drupal\FunctionalTests\Bootstrap\UncaughtExceptionTest::assertErrorLogged()
  2. 9 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.

@internal

Parameters

string $error_message: The expected error message.

See also

\Drupal\Core\Test\FunctionalTestSetupTrait::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 284

Class

UncaughtExceptionTest
Tests kernel panic when things are really messed up.

Namespace

Drupal\FunctionalTests\Bootstrap

Code

protected function assertErrorLogged(string $error_message) : void {
  $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));
}