function CronQueueTest::setUp

Same name in other branches
  1. 9 core/modules/system/tests/src/Kernel/System/CronQueueTest.php \Drupal\Tests\system\Kernel\System\CronQueueTest::setUp()
  2. 8.9.x core/modules/system/tests/src/Kernel/System/CronQueueTest.php \Drupal\Tests\system\Kernel\System\CronQueueTest::setUp()
  3. 11.x 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 67

Class

CronQueueTest
Tests the Cron Queue runner.

Namespace

Drupal\Tests\system\Kernel\System

Code

protected function setUp() : void {
    // Setup logger before register() is called.
    $this->logger = $this->prophesize(LoggerInterface::class);
    parent::setUp();
    $this->connection = Database::getConnection();
    $this->cron = \Drupal::service('cron');
    $time = $this->prophesize('Drupal\\Component\\Datetime\\TimeInterface');
    $time->getCurrentTime()
        ->willReturn($this->currentTime);
    $time->getCurrentMicroTime()
        ->willReturn(100.0);
    $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());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.