class CronCommandTest

Same name and namespace in other branches
  1. 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

Expanded class hierarchy of CronCommandTest

File

core/modules/system/tests/src/Functional/Command/CronCommandTest.php, line 18

Namespace

Drupal\Tests\system\Functional\Command
View 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.