You are here

public function MonitoringCronErrorPluginTest::testUltimateCronErrorsSensorPlugin in Monitoring 8

Tests ultimate cron errors sensor.

File

tests/src/Kernel/MonitoringCronErrorPluginTest.php, line 44

Class

MonitoringCronErrorPluginTest
Kernel test for ultimate cron errors sensor plugin.

Namespace

Drupal\Tests\monitoring\Kernel

Code

public function testUltimateCronErrorsSensorPlugin() {

  // Run sensor and make sure there are no errors.
  $result = $this
    ->runSensor('ultimate_cron_errors');
  $this
    ->assertEquals(0, $result
    ->getValue());

  // Set 1 error and run cron.
  \Drupal::state()
    ->set('ultimate_cron_logger_test_cron_action', 'exception');
  \Drupal::service('cron')
    ->run();

  // Run sensor and assert an error.
  $result = $this
    ->runSensor('ultimate_cron_errors');
  $this
    ->assertEquals(1, $result
    ->getValue());

  // Assert verbose output and error message.
  $verbose_output = $result
    ->getVerboseOutput()['log_entries']['#rows'][0];
  $this
    ->assertTrue($result
    ->isOk());
  $this
    ->assertEquals('Default cron handler (Ultimate Cron Logger Test)', $verbose_output['name']);
  $this
    ->assertStringContainsString('Test cron exception', $verbose_output['message']);
}