class CronCommandTest
Same name and namespace in other branches
- 11.x core/modules/system/tests/src/Functional/Command/CronCommandTest.php \Drupal\Tests\system\Functional\Command\CronCommandTest
Tests cron runs as a console command.
Attributes
#[Group('system')]
#[RunTestsInSeparateProcesses]
#[CoversClass(CronCommand::class)]
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\system\Functional\Command\CronCommandTest extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of CronCommandTest
File
-
core/
modules/ system/ tests/ src/ Functional/ Command/ CronCommandTest.php, line 18
Namespace
Drupal\Tests\system\Functional\CommandView source
class CronCommandTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'common_test',
'common_test_cron_helper',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests cron runs.
*/
public function testCronRun() : void {
$command = new CronCommand($this->container
->get('cron'));
$tester = new CommandTester($command);
$code = $tester->execute([]);
$this->assertStringContainsString('Cron ran successfully.', $tester->getDisplay());
$this->assertEquals(Command::SUCCESS, $code);
}
/**
* Make sure exceptions thrown on hook_cron() don't affect other modules.
*/
public function testCronExceptions() : void {
\Drupal::state()->delete('common_test.cron');
$command = new CronCommand($this->container
->get('cron'));
$tester = new CommandTester($command);
$code = $tester->execute([]);
$this->assertStringContainsString('Cron ran successfully.', $tester->getDisplay());
$this->assertEquals(Command::SUCCESS, $code);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.