function DbLogTest::testDbLogCron

Same name in other branches
  1. 9 core/modules/dblog/tests/src/Kernel/DbLogTest.php \Drupal\Tests\dblog\Kernel\DbLogTest::testDbLogCron()
  2. 8.9.x core/modules/dblog/tests/src/Kernel/DbLogTest.php \Drupal\Tests\dblog\Kernel\DbLogTest::testDbLogCron()
  3. 11.x core/modules/dblog/tests/src/Kernel/DbLogTest.php \Drupal\Tests\dblog\Kernel\DbLogTest::testDbLogCron()

Tests that cron correctly applies the database log row limit.

File

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

Class

DbLogTest
Generate events and verify dblog entries.

Namespace

Drupal\Tests\dblog\Kernel

Code

public function testDbLogCron() : void {
    $row_limit = 100;
    // Generate additional log entries.
    $this->generateLogEntries($row_limit + 10);
    // Verify that the database log row count exceeds the row limit.
    $count = Database::getConnection()->select('watchdog')
        ->countQuery()
        ->execute()
        ->fetchField();
    $this->assertGreaterThan($row_limit, $count, "Dblog row count of {$count} exceeds row limit of {$row_limit}");
    // Get the number of enabled modules. Cron adds a log entry for each module.
    $implementation_count = 0;
    \Drupal::moduleHandler()->invokeAllWith('cron', function (callable $hook, string $module) use (&$implementation_count) {
        $implementation_count++;
    });
    $cron_detailed_count = $this->runCron();
    $expected_count = $implementation_count + 2;
    $this->assertEquals($expected_count, $cron_detailed_count, "Cron added {$cron_detailed_count} of {$expected_count} new log entries");
    // Test disabling of detailed cron logging.
    $this->config('system.cron')
        ->set('logging', FALSE)
        ->save();
    $cron_count = $this->runCron();
    $this->assertEquals(1, $cron_count, "Cron added {$cron_count} of 1 new log entries");
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.