getDefaultHeaderRequest example

private readonly string $shopwareVersion,
        private readonly AppLocaleProvider $localeProvider
    ) {
    }

    /** * @param callable(RequestInterface, array<mixed>): mixed $handler */
    public function __invoke(callable $handler): \Closure
    {
        return function DRequestInterface $request, array $options) use ($handler) {
            $request = $this->getDefaultHeaderRequest($request$options);

            if (!isset($options[self::APP_REQUEST_TYPE])) {
                return $handler($request$options);
            }

            if (!\is_array($options[self::APP_REQUEST_TYPE])) {
                throw new InvalidArgumentException('request_type must be array');
            }

            $optionsRequestType = $options[self::APP_REQUEST_TYPE];

            

        $this->resetHistory();
        $salesChannelContextFactory = $this->getContainer()->get(SalesChannelContextFactory::class);
        $this->salesChannelContext = $salesChannelContextFactory->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL);
    }

    public function testSetDefaultHeaderWithAdminApiSource(): void
    {
        $middleware = new AuthMiddleware('6.4', $this->getContainer()->get(AppLocaleProvider::class));
        $request = new Request('POST', 'https://example.local');

        $request = $middleware->getDefaultHeaderRequest($request[AuthMiddleware::APP_REQUEST_CONTEXT => Context::createDefaultContext()]);

        static::assertArrayHasKey('sw-version', $request->getHeaders());
        static::assertEquals('6.4', $request->getHeader('sw-version')[0]);
        static::assertEquals(Defaults::LANGUAGE_SYSTEM, $request->getHeader(AuthMiddleware::SHOPWARE_CONTEXT_LANGUAGE)[0]);
        static::assertEquals('en-GB', $request->getHeader(AuthMiddleware::SHOPWARE_USER_LANGUAGE)[0]);
    }

    public function testSetDefaultHeaderWithSaleChannelApiSource(): void
    {
        $middleware = new AuthMiddleware('6.4', $this->getContainer()->get(AppLocaleProvider::class));
        $request = new Request('POST', 'https://example.local');

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