function DbLogTest::runCron
Same name in other branches
- 9 core/modules/dblog/tests/src/Kernel/DbLogTest.php \Drupal\Tests\dblog\Kernel\DbLogTest::runCron()
- 8.9.x core/modules/dblog/tests/src/Kernel/DbLogTest.php \Drupal\Tests\dblog\Kernel\DbLogTest::runCron()
- 11.x core/modules/dblog/tests/src/Kernel/DbLogTest.php \Drupal\Tests\dblog\Kernel\DbLogTest::runCron()
Runs cron and returns number of new log entries.
Return value
int Number of new watchdog entries.
1 call to DbLogTest::runCron()
- DbLogTest::testDbLogCron in core/
modules/ dblog/ tests/ src/ Kernel/ DbLogTest.php - Tests that cron correctly applies the database log row limit.
File
-
core/
modules/ dblog/ tests/ src/ Kernel/ DbLogTest.php, line 86
Class
- DbLogTest
- Generate events and verify dblog entries.
Namespace
Drupal\Tests\dblog\KernelCode
private function runCron() {
$connection = Database::getConnection();
// Get last ID to compare against; log entries get deleted, so we can't
// reliably add the number of newly created log entries to the current count
// to measure number of log entries created by cron.
$query = $connection->select('watchdog');
$query->addExpression('MAX([wid])');
$last_id = $query->execute()
->fetchField();
// Run a cron job.
$this->container
->get('cron')
->run();
// Get last ID after cron was run.
$query = $connection->select('watchdog');
$query->addExpression('MAX([wid])');
$current_id = $query->execute()
->fetchField();
return $current_id - $last_id;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.