You are here

function LoggerPluginTest::testCacheLogger in Ultimate Cron 8.2

Tests cache logger.

File

tests/src/Kernel/LoggerPluginTest.php, line 102

Class

LoggerPluginTest
Tests the default scheduler plugins.

Namespace

Drupal\Tests\ultimate_cron\Kernel

Code

function testCacheLogger() {

  // @todo Set default logger and do not enable the log table.
  $this
    ->installSchema('ultimate_cron', [
    'ultimate_cron_log',
    'ultimate_cron_lock',
  ]);
  \Drupal::service('ultimate_cron.discovery')
    ->discoverCronJobs();
  $job = CronJob::load('ultimate_cron_logger_test_cron');
  $job
    ->setLoggerId('cache');
  $job
    ->save();

  // Launch the job twice.
  $job
    ->getPlugin('launcher')
    ->launch($job);
  $job
    ->getPlugin('launcher')
    ->launch($job);

  // There is only one log entry.
  $log_entries = $job
    ->getLogEntries(ULTIMATE_CRON_LOG_TYPE_ALL, 3);
  $this
    ->assertCount(1, $log_entries);
  $log_entry = reset($log_entries);
  $this
    ->assertTrue($log_entry instanceof LogEntry);
  $this
    ->assertEquals('ultimate_cron_logger_test_cron', $log_entry->name);
  $this
    ->assertEquals('Launched manually by anonymous (0)', (string) $log_entry
    ->formatInitMessage());
}