setNextExecutionTime example

public function testScheduleShouldNotRunTask(): void
    {
        $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']);
            

class ListScheduledTaskCommandTest extends TestCase
{
    public function testListTasks(): void
    {
        $entity = new ScheduledTaskEntity();
        $entity->setId('test');
        $entity->setName('TestTask.ID');
        $entity->setNextExecutionTime(new \DateTime());
        $entity->setRunInterval(100);
        $entity->setStatus(ScheduledTaskDefinition::STATUS_QUEUED);

        $taskRegistry = $this->createMock(TaskRegistry::class);
        $taskRegistry
            ->method('getAllTasks')
            ->willReturn(new ScheduledTaskCollection([$entity]));

        $command = new ListScheduledTaskCommand($taskRegistry);

        $tester = new CommandTester($command);
        
'shopware.cache.invalidation.delay' => 10,
            '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.