You are here

public function NagiosCheckTest::testCronCheck in Nagios Monitoring 8

File

tests/src/Kernel/NagiosCheckTest.php, line 46

Class

NagiosCheckTest
Tests the functionality to monitor cron.

Namespace

Drupal\Tests\nagios\Kernel

Code

public function testCronCheck() {

  // set last run to an old date
  \Drupal::state()
    ->set('system.cron_last', 0);

  // run check function, expect warning
  $result1 = nagios_check_cron();
  self::assertSame(2, $result1['data']['status'], "Check critical response");

  // run cron

  /** @var \Drupal\Core\CronInterface $cron */
  $cron = \Drupal::service('cron');
  $cron
    ->run();

  // run check function, expect no warning
  $result2 = nagios_check_cron();
  self::assertSame(0, $result2['data']['status'], "Check ok response");
}