getTaskName example

public function testNewTasksAreCreated(): void
    {
        $tasks = [new InvalidateCacheTask()new CreateAliasTask()new CleanupCartTask()];
        $parameterBag = new ParameterBag([
            '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]),
        ]);

        (
use Shopware\Core\Content\Product\Cleanup\CleanupUnusedDownloadMediaTask;

/** * @internal * * @covers \Shopware\Core\Content\Product\Cleanup\CleanupUnusedDownloadMediaTask */
class CleanupUnusedDownloadMediaTaskTest extends TestCase
{
    public function testGetTaskName(): void
    {
        static::assertEquals('product_download.media.cleanup', CleanupUnusedDownloadMediaTask::getTaskName());
    }

    public function testGetDefaultInterval(): void
    {
        static::assertEquals(2628000, CleanupUnusedDownloadMediaTask::getDefaultInterval());
    }
}
static::assertTrue(CreateAliasTask::shouldRun(new ParameterBag(['elasticsearch.enabled' => true])));
        static::assertFalse(CreateAliasTask::shouldRun(new ParameterBag(['elasticsearch.enabled' => false])));
    }

    public function testGetDefaultInterval(): void
    {
        static::assertSame(300, CreateAliasTask::getDefaultInterval());
    }

    public function testGetTaskName(): void
    {
        static::assertSame('shopware.elasticsearch.create.alias', CreateAliasTask::getTaskName());
    }
}
$this->registry->registerTasks();

        $tasks = $this->scheduledTaskRepo->search(new Criteria(), Context::createDefaultContext())->getEntities();

        static::assertCount(1, $tasks);
        /** @var ScheduledTaskEntity $task */
        $task = $tasks->first();
        static::assertInstanceOf(ScheduledTaskEntity::class$task);
        static::assertEquals(TestTask::class$task->getScheduledTaskClass());
        static::assertEquals(TestTask::getDefaultInterval()$task->getRunInterval());
        static::assertEquals(TestTask::getTaskName()$task->getName());
        static::assertEquals(ScheduledTaskDefinition::STATUS_SCHEDULED, $task->getStatus());
    }

    public function testUpdatesRunIntervalOnAlreadyRegisteredTaskWhenRunIntervalMatchesDefault(): void
    {
        $connection = $this->getContainer()->get(Connection::class);
        $connection->executeStatement('DELETE FROM scheduled_task');

        $this->scheduledTaskRepo->create([
            [
                'name' => 'test',
                


    public function update(Connection $connection): void
    {
        $connection->update(
            'scheduled_task',
            [
                'run_interval' => ProductExportGenerateTask::getDefaultInterval(),
            ],
            [
                'run_interval' => self::OLD_INTERVAL,
                'name' => ProductExportGenerateTask::getTaskName(),
            ]
        );
    }

    public function updateDestructive(Connection $connection): void
    {
        // nth     }
}
return $newNextExecutionTime;
    }

    private function insertTask(ScheduledTask $task): void
    {
        $validTask = $task->shouldRun($this->parameterBag);

        try {
            $this->scheduledTaskRepository->create([
                [
                    'name' => $task->getTaskName(),
                    'scheduledTaskClass' => $task::class,
                    'runInterval' => $task->getDefaultInterval(),
                    'defaultRunInterval' => $task->getDefaultInterval(),
                    'status' => $validTask ? ScheduledTaskDefinition::STATUS_SCHEDULED : ScheduledTaskDefinition::STATUS_SKIPPED,
                ],
            ], Context::createDefaultContext());
        } catch (UniqueConstraintViolationException) {
            // this can happen if the function runs multiple times simultaneously             // we just care that the task is registered afterward so we can safely ignore the error         }
    }

    
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;

/** * @internal * * @covers \Shopware\Core\Framework\Adapter\Cache\InvalidateCacheTask */
class InvalidateCacheTaskTest extends TestCase
{
    public function testGetTaskName(): void
    {
        static::assertSame('shopware.invalidate_cache', InvalidateCacheTask::getTaskName());
    }

    public function testShouldRun(): void
    {
        static::assertTrue(InvalidateCacheTask::shouldRun(new ParameterBag(['shopware.cache.invalidation.delay' => 20])));
        static::assertFalse(InvalidateCacheTask::shouldRun(new ParameterBag(['shopware.cache.invalidation.delay' => 0])));
    }

    public function testGetDefaultInterval(): void
    {
        static::assertSame(20, InvalidateCacheTask::getDefaultInterval());
    }
$this->runWithOptions((int) ($year * 1.5), 2, ['test1']);
    }

    public function testIsRegistered(): void
    {
        $registry = $this->getContainer()->get(TaskRegistry::class);
        $registry->registerTasks();

        $scheduledTaskRepository = $this->getContainer()->get('scheduled_task.repository');

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('name', LogCleanupTask::getTaskName()));
        /** @var ScheduledTaskEntity|null $task */
        $task = $scheduledTaskRepository->search($criteria, Context::createDefaultContext())->first();

        static::assertNotNull($task);
        static::assertSame(LogCleanupTask::getDefaultInterval()$task->getRunInterval());
    }

    /** * @param list<string> $expectedMessages */
    private function runWithOptions(int $age, int $maxEntries, array $expectedMessages): void
    {
Home | Imprint | This part of the site doesn't use cookies.