function 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 264  
Class
- UncaughtExceptionTest
 - Tests kernel panic when things are really messed up.
 
Namespace
Drupal\FunctionalTests\BootstrapCode
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 (str_contains($content, $error_message)) {
      $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));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.