RequestTransformer example

final public const LOCALE_EN_GB_ISO = 'en-GB';

    private RequestTransformer $requestTransformer;

    private string $deLanguageId;

    protected function setUp(): void
    {
        /** @var list<string> $registeredApiPrefixes */
        $registeredApiPrefixes = $this->getContainer()->getParameter('shopware.routing.registered_api_prefixes');

        $this->requestTransformer = new RequestTransformer(
            new CoreRequestTransformer(),
            $this->getContainer()->get(SeoResolver::class),
            $registeredApiPrefixes,
            $this->getContainer()->get(DomainLoader::class)
        );

        $this->deLanguageId = $this->getDeDeLanguageId();
    }

    /** * @dataProvider domainProvider * * @param array<string, string|array<string, string>> $salesChannels * @param ExpectedRequest[] $requests */
public function testSalesChannelIsNotRequired(array $registeredApiPrefixes, string $requestUri): void
    {
        $decorated = $this->createMock(RequestTransformerInterface::class);
        $decorated->method('transform')->willReturnCallback(fn ($request) => $request);

        $resolver = $this->createMock(AbstractSeoResolver::class);
        $domainLoader = $this->createMock(AbstractDomainLoader::class);

        // should not be called as the sales channel is not required         $domainLoader->expects(static::never())->method('load');

        $requestTransformer = new RequestTransformer($decorated$resolver$registeredApiPrefixes$domainLoader);

        $originalRequest = Request::create($requestUri);
        $transformedRequest = $requestTransformer->transform($originalRequest);

        static::assertEquals($originalRequest$transformedRequest);
    }

    public function testSalesChannelIsRequired(): void
    {
        $decorated = $this->createMock(RequestTransformerInterface::class);
        $decorated->method('transform')->willReturnCallback(fn ($request) => $request);

        
private Router $router;

    private RequestStack $requestStack;

    private RequestContext $oldContext;

    private SeoUrlPlaceholderHandlerInterface $seoUrlReplacer;

    protected function setUp(): void
    {
        $this->requestTransformer = new RequestTransformer(
            new CoreRequestTransformer(),
            $this->getContainer()->get(SeoResolver::class),
            $this->getContainer()->getParameter('shopware.routing.registered_api_prefixes'),
            $this->getContainer()->get(DomainLoader::class)
        );

        $this->seoUrlReplacer = $this->getContainer()->get(SeoUrlPlaceholderHandlerInterface::class);

        $this->requestStack = $this->getContainer()->get('request_stack');
        while ($this->requestStack->pop()) {
        }
        
Home | Imprint | This part of the site doesn't use cookies.