ParameterBag example

private MockObject&MessageBusInterface $messageBus;

    private TaskScheduler $scheduler;

    private Connection $connection;

    protected function setUp(): void
    {
        $this->scheduledTaskRepo = $this->getContainer()->get('scheduled_task.repository');
        $this->messageBus = $this->createMock(MessageBusInterface::class);

        $this->scheduler = new TaskScheduler($this->scheduledTaskRepo, $this->messageBus, new ParameterBag());

        $this->connection = $this->getContainer()->get(Connection::class);
    }

    public function testScheduleTasks(): void
    {
        $this->connection->executeStatement('DELETE FROM scheduled_task');

        $taskId = Uuid::randomHex();
        $this->scheduledTaskRepo->create([
            [
                
/** * @throws IllegalTransitionException * @throws StateMachineException */
    private function transitState(string $machine, string $orderId, string $toPlace, Context $context): void
    {
        if (!$toPlace) {
            return;
        }

        $data = new ParameterBag();
        $machineId = $machine === self::ORDER ? $orderId : $this->getMachineId($machine$orderId);
        if (!$machineId) {
            throw StateMachineException::stateMachineNotFound($machine);
        }

        $actionName = $this->getAvailableActionName($machine$machineId$toPlace);
        if (!$actionName) {
            $actionName = $toPlace;
        }

        switch ($machine) {
            
$handler = $this->findComponentHandler($element);

        if (!$handler) {
            return;
        }

        if (!isset($presetData['syncData']['importedAssets'])) {
            $presetData['syncData']['importedAssets'] = [];
        }

        $syncData = new ParameterBag($presetData['syncData']);

        $this->setAssetPaths($syncData);

        try {
            $element = $handler->import($element$syncData);
        } catch (Exception $e) {
            throw new PresetAssetImportException($e->getMessage());
        }

        $presetData['syncData'] = $syncData->all();
        $preset->setPresetData(json_encode($presetData));

        

    public function testGetNextExecutionTime(array $aggregationResult, ?\DateTime $time): void
    {
        $scheduledTaskRepository = $this->createMock(EntityRepository::class);
        $scheduledTaskRepository->method('aggregate')->willReturn(new AggregationResultCollection($aggregationResult));

        $scheduler = new TaskScheduler(
            $scheduledTaskRepository,
            $this->createMock(MessageBusInterface::class),
            new ParameterBag()
        );

        static::assertEquals(
            $time,
            $scheduler->getNextExecutionTime()
        );
    }

    /** * @return iterable<array<AggregationResult[]|\DateTime|null>> */
    
private TaskRegistry $registry;

    protected function setUp(): void
    {
        $this->scheduledTaskRepo = $this->getContainer()->get('scheduled_task.repository');

        $this->registry = new TaskRegistry(
            [
                new TestTask(),
            ],
            $this->scheduledTaskRepo,
            new ParameterBag()
        );
    }

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

        $this->registry->registerTasks();

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

        
static::assertEquals($event$actualEvents[0]);
        }
    }

    public function testBundlePaths(): void
    {
        $kernelMock = $this->createMock(Kernel::class);
        $packagesMock = $this->createMock(Packages::class);
        $eventCollector = $this->createMock(FlowActionCollector::class);
        $infoController = new InfoController(
            $this->createMock(DefinitionService::class),
            new ParameterBag([
                'kernel.shopware_version' => 'shopware-version',
                'kernel.shopware_version_revision' => 'shopware-version-revision',
                'shopware.admin_worker.enable_admin_worker' => 'enable-admin-worker',
                'shopware.admin_worker.enable_queue_stats_worker' => 'enable-queue-stats-worker',
                'shopware.admin_worker.enable_notification_worker' => 'enable-notification-worker',
                'shopware.admin_worker.transports' => 'transports',
                'shopware.filesystem.private_allowed_extensions' => ['png'],
                'shopware.html_sanitizer.enabled' => true,
            ]),
            $kernelMock,
            $packagesMock,
            

    }

    /** * Gets a new ContainerBuilder instance used to build the service container. * * @return ContainerBuilder */
    protected function getContainerBuilder()
    {
        return new ContainerBuilder(
            new ParameterBag(
                $this->getKernelParameters()
            )
        );
    }

    /** * Returns the kernel parameters. * * @return array An array of kernel parameters */
    protected function getKernelParameters()
    {
$this->orderService->createOrder($data$this->salesChannelContext);

        $dispatcher->removeListener(MailSentEvent::class$listenerClosure);

        static::assertTrue($eventDidRun, 'The mail.sent Event did not run');
    }

    public function testOrderStateTransition(): void
    {
        $orderId = $this->performOrder();

        $this->orderService->orderStateTransition($orderId, 'cancel', new ParameterBag()$this->salesChannelContext->getContext());

        $criteria = new Criteria([$orderId]);

        $criteria->addAssociation('stateMachineState');

        /** @var OrderEntity $cancelledOrder */
        $cancelledOrder = $this->orderRepository->search($criteria$this->salesChannelContext->getContext())->first();
        $state = $cancelledOrder->getStateMachineState();

        static::assertNotNull($state);
        static::assertSame('cancelled', $state->getTechnicalName());
    }
$orderId = $request->get('orderId', null);

        if ($orderId === null) {
            throw RoutingException::invalidRequestParameter('orderId');
        }

        $this->verify($orderId$context);

        $newState = $this->orderService->orderStateTransition(
            $orderId,
            'cancel',
            new ParameterBag(),
            $context->getContext()
        );

        return new CancelOrderRouteResponse($newState);
    }

    private function verify(string $orderId, SalesChannelContext $context): void
    {
        if ($context->getCustomer() === null) {
            throw OrderException::customerNotLoggedIn();
        }

        
$emotionData = $this->extractEmotionArchive($filePath$extractPath);

        if (!$emotionData['presetData']) {
            throw new EmotionImportException('No emotion data available');
        }

        if ($emotionData['requiredPlugins']) {
            $this->checkRequiredPlugins($emotionData['requiredPlugins']);
        }

        $presetData = json_decode($emotionData['presetData'], true);
        $syncData = new ParameterBag($presetData['syncData']);

        $this->setFilePaths($syncData$extractPath);

        $presetData['syncData'] = $syncData->all();

        $presetData = json_encode($presetData);

        $preset = $this->presetResource->create([
            'name' => pathinfo($filePath, PATHINFO_FILENAME),
            'presetData' => $presetData,
            'hidden' => true,
            

    private EntityRepository $scheduleTaskRepository;

    protected function setUp(): void
    {
        $this->scheduleTaskRepository = $this->createMock(EntityRepository::class);
    }

    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);
        
private static function getRequest(ParameterBag $attributes): Request
    {
        return new Request([][]$attributes->all()[][][]);
    }

    private function getRequestAttributes(bool $isCheckEnabled): ParameterBag
    {
        $param = [
            '_captcha' => $isCheckEnabled ? true : null,
        ];

        return new ParameterBag($isCheckEnabled ? $param : []);
    }
}

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());
    }
}
foreach ($transactions as $transaction) {
            if ($transaction->getPaymentMethodId() === $paymentMethodId && $lastTransaction->getId() === $transaction->getId()) {
                $initialState = $this->initialStateIdLoader->get(OrderTransactionStates::STATE_MACHINE);
                if ($transaction->getStateId() === $initialState) {
                    return true;
                }

                try {
                    $this->orderService->orderTransactionStateTransition(
                        $transaction->getId(),
                        StateMachineTransitionActions::ACTION_REOPEN,
                        new ParameterBag(),
                        $context
                    );

                    return true;
                } catch (IllegalTransitionException) {
                    // if we can't reopen the last transaction with a matching payment method                     // we have to create a new transaction and cancel the previous one                 }
            }

            if ($transaction->getStateMachineState() !== null
                
if ($zip->open($filename, ZipArchive::CREATE) !== true) {
            throw new Exception(sprintf('Could not create zip file "%s"!', $filename));
        }

        $emotionData = $this->transformer->transform($emotionId, true);

        $preset = $this->createHiddenPreset($emotionData);
        $preset = $this->synchronizer->prepareAssetExport($preset);

        $presetData = json_decode($preset->getPresetData(), true);
        $syncData = new ParameterBag($presetData['syncData']);
        $assets = $syncData->get('assets', []);

        $zip->addEmptyDir('images');

        foreach ($assets as &$path) {
            $fileContent = $this->mediaService->read($path);
            if ($fileContent === false) {
                continue;
            }

            $zipPath = 'images/' . basename($path);

            
Home | Imprint | This part of the site doesn't use cookies.