protected function TestBase::assertErrorLogged in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/simpletest/src/TestBase.php \Drupal\simpletest\TestBase::assertErrorLogged()
Asserts that a specific error has been logged to the PHP error log.
Parameters
string $error_message: The expected error message.
Return value
bool TRUE if the assertion succeeded, FALSE otherwise.
See also
\Drupal\simpletest\TestBase::prepareEnvironment()
\Drupal\Core\DrupalKernel::bootConfiguration()
7 calls to TestBase::assertErrorLogged()
- ConfigInstallProfileUnmetDependenciesTest::testInstalled in core/
modules/ config/ src/ Tests/ ConfigInstallProfileUnmetDependenciesTest.php - Confirms that the installation succeeded.
- ErrorHandlerTest::testErrorHandler in core/
modules/ system/ src/ Tests/ System/ ErrorHandlerTest.php - Test the error handler.
- UncaughtExceptionTest::testErrorContainer in core/
modules/ system/ src/ Tests/ System/ UncaughtExceptionTest.php - Tests a container which has an error.
- UncaughtExceptionTest::testExceptionContainer in core/
modules/ system/ src/ Tests/ System/ UncaughtExceptionTest.php - Tests a container which has an exception really early.
- UncaughtExceptionTest::testLostDatabaseConnection in core/
modules/ system/ src/ Tests/ System/ UncaughtExceptionTest.php - Tests the case when the database connection is gone.
File
- core/
modules/ simpletest/ src/ TestBase.php, line 845 - Contains \Drupal\simpletest\TestBase.
Class
- TestBase
- Base class for Drupal tests.
Namespace
Drupal\simpletestCode
protected function assertErrorLogged($error_message) {
$error_log_filename = DRUPAL_ROOT . '/' . $this->siteDirectory . '/error.log';
if (!file_exists($error_log_filename)) {
$this
->error('No error logged yet.');
}
$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));
return $this
->assertTrue($found, sprintf('The %s error message was logged.', $error_message));
}