function CronSuspendQueueDelayTest::setUp

Same name in other branches
  1. 10 core/tests/Drupal/Tests/Core/Cron/CronSuspendQueueDelayTest.php \Drupal\Tests\Core\Cron\CronSuspendQueueDelayTest::setUp()

Overrides UnitTestCase::setUp

File

core/tests/Drupal/Tests/Core/Cron/CronSuspendQueueDelayTest.php, line 57

Class

CronSuspendQueueDelayTest
Test Cron handling of suspended queues with a delay.

Namespace

Drupal\Tests\Core\Cron

Code

protected function setUp() : void {
    parent::setUp();
    $lock = $this->createMock(LockBackendInterface::class);
    $lock->expects($this->any())
        ->method('acquire')
        ->willReturn(TRUE);
    $this->cronConstructorArguments = [
        'moduleHandler' => $this->createMock(ModuleHandlerInterface::class),
        'lock' => $lock,
        'queueFactory' => $this->createMock(QueueFactory::class),
        'state' => $this->createMock(StateInterface::class),
        'accountSwitcher' => $this->createMock(AccountSwitcherInterface::class),
        'logger' => $this->createMock(LoggerInterface::class),
        'queueManager' => $this->createMock(QueueWorkerManagerInterface::class),
        'time' => $this->createMock(TimeInterface::class),
        'queue_config' => [],
    ];
    // Capture error logs.
    $config = $this->createMock(ImmutableConfig::class);
    $config->expects($this->any())
        ->method('get')
        ->with('logging')
        ->willReturn(0);
    $configFactory = $this->createMock(ConfigFactoryInterface::class);
    $configFactory->expects($this->any())
        ->method('get')
        ->with('system.cron')
        ->willReturn($config);
    $container = new ContainerBuilder();
    $container->set('config.factory', $configFactory);
    \Drupal::setContainer($container);
    $this->workerA = $this->createMock(QueueWorkerInterface::class);
    $this->workerA
        ->expects($this->any())
        ->method('getPluginDefinition')
        ->willReturn([
        'cron' => [
            'time' => 300,
        ],
    ]);
    $this->workerB = $this->createMock(QueueWorkerInterface::class);
    $this->workerB
        ->expects($this->any())
        ->method('getPluginDefinition')
        ->willReturn([
        'cron' => [
            'time' => 300,
        ],
    ]);
}

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