You are here

protected function CronQueueTest::setUp in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Kernel/System/CronQueueTest.php \Drupal\Tests\system\Kernel\System\CronQueueTest::setUp()
  2. 9 core/modules/system/tests/src/Kernel/System/CronQueueTest.php \Drupal\Tests\system\Kernel\System\CronQueueTest::setUp()

Overrides KernelTestBase::setUp

File

core/modules/system/tests/src/Kernel/System/CronQueueTest.php, line 53

Class

CronQueueTest
Tests the Cron Queue runner.

Namespace

Drupal\Tests\system\Kernel\System

Code

protected function setUp() : void {
  parent::setUp();
  $this->connection = Database::getConnection();
  $this->cron = \Drupal::service('cron');
  $time = $this
    ->prophesize('Drupal\\Component\\Datetime\\TimeInterface');
  $time
    ->getCurrentTime()
    ->willReturn($this->currentTime);
  $time
    ->getRequestTime()
    ->willReturn($this->currentTime);
  \Drupal::getContainer()
    ->set('datetime.time', $time
    ->reveal());
  $this
    ->assertEquals($this->currentTime, \Drupal::time()
    ->getCurrentTime());
  $this
    ->assertEquals($this->currentTime, \Drupal::time()
    ->getRequestTime());
  $realQueueFactory = $this->container
    ->get('queue');
  $queue_factory = $this
    ->prophesize(get_class($realQueueFactory));
  $database = new DatabaseQueue('cron_queue_test_database_delay_exception', $this->connection);
  $memory = new Memory('cron_queue_test_memory_delay_exception');
  $queue_factory
    ->get('cron_queue_test_database_delay_exception', Argument::cetera())
    ->willReturn($database);
  $queue_factory
    ->get('cron_queue_test_memory_delay_exception', Argument::cetera())
    ->willReturn($memory);
  $queue_factory
    ->get(Argument::any(), Argument::cetera())
    ->will(function ($args) use ($realQueueFactory) {
    return $realQueueFactory
      ->get($args[0], $args[1] ?? FALSE);
  });
  $this->container
    ->set('queue', $queue_factory
    ->reveal());
}