getAvailableStrategies example

$this->firstStrategy->expects(static::once())
            ->method('getDescription')
            ->willReturn('first description');

        $this->secondStrategy->expects(static::once())
            ->method('getDescription')
            ->willReturn('second description');

        static::assertEquals([
            'FirstStrategy' => 'first description',
            'SecondStrategy' => 'second description',
        ]$this->appUrlChangedResolverStrategy->getAvailableStrategies());
    }
}

    public function __construct(
        private readonly Resolver $appUrlChangeResolver,
        private readonly ShopIdProvider $shopIdProvider
    ) {
    }

    #[Route(path: 'api/app-system/app-url-change/strategies', name: 'api.app_system.app-url-change-strategies', methods: ['GET'])]     public function getAvailableStrategies(): JsonResponse
    {
        return new JsonResponse(
            $this->appUrlChangeResolver->getAvailableStrategies()
        );
    }

    #[Route(path: 'api/app-system/app-url-change/resolve', name: 'api.app_system.app-url-change-resolve', methods: ['POST'])]     public function resolve(Request $request, Context $context): Response
    {
        $strategy = $request->get('strategy');

        if (!$strategy) {
            throw RoutingException::missingRequestParameter('strategy');
        }

        


    protected function configure(): void
    {
        $this->addArgument('strategy', InputArgument::OPTIONAL, 'The strategy that should be applied');
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new ShopwareStyle($input$output);

        $availableStrategies = $this->appUrlChangeResolver->getAvailableStrategies();
        $strategy = $input->getArgument('strategy');

        if ($strategy === null || !\array_key_exists($strategy$availableStrategies)) {
            if ($strategy !== null) {
                $io->note(sprintf('Strategy with name: "%s" not found.', $strategy));
            }

            $strategy = $io->choice(
                'Choose what strategy should be applied, to resolve the app url change?',
                $availableStrategies
            );
        }
public function testGetAvailableStrategies(): void
    {
        $url = '/api/app-system/app-url-change/strategies';
        $this->getBrowser()->request('GET', $url);
        static::assertNotFalse($this->getBrowser()->getResponse()->getContent());

        $response = \json_decode($this->getBrowser()->getResponse()->getContent(), true, 512, \JSON_THROW_ON_ERROR);

        static::assertEquals(200, $this->getBrowser()->getResponse()->getStatusCode());

        $appUrlChangeResolver = $this->getContainer()->get(Resolver::class);
        static::assertEquals($appUrlChangeResolver->getAvailableStrategies()$response);
    }

    public function testResolveWithExistingStrategy(): void
    {
        $url = '/api/app-system/app-url-change/resolve';
        $json = \json_encode(['strategy' => UninstallAppsStrategy::STRATEGY_NAME]);
        static::assertNotFalse($json);
        static::assertJson($json);

        $this->getBrowser()->request(
            'POST',
            
Home | Imprint | This part of the site doesn't use cookies.