setScheduledTaskClass example

static::assertTrue($handler->called);
        static::assertFalse($handler2->called);
    }

    /** * @return StaticEntityRepository<ScheduledTaskCollection> */
    private function getRepository(): StaticEntityRepository
    {
        $task = new ScheduledTaskEntity();
        $task->setId('task-id');
        $task->setScheduledTaskClass(TestTask::class);

        // @phpstan-ignore-next-line         return new StaticEntityRepository([new ScheduledTaskCollection([$task])]);
    }
}

/** * @internal */
class TestTask extends ScheduledTask
{
    

        $scheduledTaskRepository = $this->createMock(EntityRepository::class);

        $scheduledTask = new ScheduledTaskEntity();

        $nextExecutionTime = new \DateTimeImmutable();
        $nextExecutionTime = $nextExecutionTime->modify(sprintf('-%d seconds', InvalidateCacheTask::getDefaultInterval() + 100));

        $scheduledTask->setId('1');
        $scheduledTask->setRunInterval(InvalidateCacheTask::getDefaultInterval());
        $scheduledTask->setNextExecutionTime($nextExecutionTime);
        $scheduledTask->setScheduledTaskClass(InvalidateCacheTask::class);
        $result = $this->createMock(EntitySearchResult::class);
        $result->method('getEntities')->willReturn(new ScheduledTaskCollection([$scheduledTask]));
        $scheduledTaskRepository->expects(static::once())->method('search')->willReturn($result);
        $scheduledTaskRepository->expects(static::once())->method('update')->willReturnCallback(function Darray $data, Context $context) {
            static::assertCount(1, $data);
            $data = $data[0];
            static::assertArrayHasKey('id', $data);
            static::assertArrayHasKey('nextExecutionTime', $data);
            static::assertArrayHasKey('status', $data);
            static::assertEquals('1', $data['id']);
            static::assertEquals(ScheduledTaskDefinition::STATUS_SKIPPED, $data['status']);

            
'elasticsearch.enabled' => false,
        ]);

        $registeredTask = new ScheduledTaskEntity();

        $registeredTask->setId('1');
        $registeredTask->setName(CleanupCartTask::getTaskName());
        $registeredTask->setRunInterval(CleanupCartTask::getDefaultInterval());
        $registeredTask->setDefaultRunInterval(CleanupCartTask::getDefaultInterval());
        $registeredTask->setStatus(ScheduledTaskDefinition::STATUS_SCHEDULED);
        $registeredTask->setNextExecutionTime(new \DateTimeImmutable());
        $registeredTask->setScheduledTaskClass(CleanupCartTask::class);

        /** @var StaticEntityRepository<ScheduledTaskCollection> $staticRepository */
        $staticRepository = new StaticEntityRepository([
            new ScheduledTaskCollection([$registeredTask]),
        ]);

        (new TaskRegistry($tasks$staticRepository$parameterBag))->registerTasks();

        static::assertSame(
            [
                [
                    [
Home | Imprint | This part of the site doesn't use cookies.