You are here

private function DbLogTest::runCron in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/dblog/tests/src/Kernel/DbLogTest.php \Drupal\Tests\dblog\Kernel\DbLogTest::runCron()
  2. 9 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.

File

core/modules/dblog/tests/src/Kernel/DbLogTest.php, line 70

Class

DbLogTest
Generate events and verify dblog entries.

Namespace

Drupal\Tests\dblog\Kernel

Code

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;
}