class AutomatedCronTest
Tests for automated_cron.
@group automated_cron
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \PHPUnit\Framework\TestCase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait
- class \Drupal\Tests\automated_cron\Kernel\AutomatedCronTest extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of AutomatedCronTest
File
-
core/
modules/ automated_cron/ tests/ src/ Kernel/ AutomatedCronTest.php, line 16
Namespace
Drupal\Tests\automated_cron\KernelView source
class AutomatedCronTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'automated_cron',
];
/**
* Tests that automated cron runs cron on an HTTP request.
*
* @covers \Drupal\automated_cron\EventSubscriber\AutomatedCron::onTerminate
*/
public function testRunsCronOnHttpRequest() : void {
// Set automated_cron interval and times.
// Any interval > 0 should work.
$this->config('automated_cron.settings')
->set('interval', 10800)
->save();
$request = new Request();
// Cron uses `$_SERVER['REQUEST_TIME']` to set `system.cron_last`
// because there is no request stack, so we set the request time
// to the same.
$expected = $_SERVER['REQUEST_TIME'];
$request->server
->set('REQUEST_TIME', $expected);
// Invoke `AutomatedCron::onTerminate` and check result.
$this->assertNull($this->container
->get('state')
->get('system.cron_last'));
$this->container
->get('kernel')
->terminate($request, new Response());
$this->assertEquals($expected, $this->container
->get('state')
->get('system.cron_last'));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.