function CronSuspendQueueDelayTest::setUp

Same name in other branches
  1. 11.x 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 = [
        'module_handler' => $this->createMock(ModuleHandlerInterface::class),
        'lock' => $lock,
        'queue_factory' => $this->createMock(QueueFactory::class),
        'state' => $this->createMock(StateInterface::class),
        'account_switcher' => $this->createMock(AccountSwitcherInterface::class),
        'logger' => $this->createMock(LoggerInterface::class),
        'queue_manager' => $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.