You are here

private function DbLogTest::runCron in Drupal 9

Same name and namespace in other branches
  1. 8 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 64

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