Response example

new MockHandler([
                    new RequestException('Error Communicating with Server', new GuzzleRequest('POST', 'test')),
                ]),
                self::IS_INVALID,
                'secret123',
            ],
            'request with server exception' => [
                self::getRequest([
                    GoogleReCaptchaV3::CAPTCHA_REQUEST_PARAMETER => 'something',
                ]),
                new MockHandler([
                    new ServerException('Server Exception', new GuzzleRequest('POST', 'test')new Response()),
                ]),
                self::IS_INVALID,
                'secret123',
            ],
            'request with result false' => [
                self::getRequest([
                    GoogleReCaptchaV3::CAPTCHA_REQUEST_PARAMETER => 'something',
                ]),
                new MockHandler([
                    new Response(200, []json_encode(['success' => false])),
                ]),
                
$this->gateway->tag(['product-1', 'product-2'], '/foo', new SymfonyResponse());

        static::assertSame(['product-1', 'product-2']$parameters);
    }

    public function testInvalidate(): void
    {
        $this->redis->expects(static::once())->method('eval')->willReturn(['/foo']);
        $this->redis->expects(static::once())->method('del')->with('product-1');

        $this->mockHandler->append(new Response(200, [], null));

        $this->gateway->invalidate(['product-1']);

        static::assertNotNull($this->mockHandler->getLastRequest());
        static::assertSame('http://localhost/foo', $this->mockHandler->getLastRequest()->getUri()->__toString());
    }

    public function testInvalidateFails(): void
    {
        $this->redis->expects(static::once())->method('eval')->willReturn(['/foo']);

        
$first = array_shift($pathSegments);

        if (\count($pathSegments) === 0) {
            $definition = $first['definition'];
            $events = $this->executeWriteOperation($definition$payload$context$type);
            /** @var EntityWrittenEvent $event */
            $event = $events->getEventByEntityName($definition->getEntityName());
            $eventIds = $event->getIds();
            $entityId = array_pop($eventIds);

            if ($definition instanceof MappingEntityDefinition) {
                return new Response(null, Response::HTTP_NO_CONTENT);
            }

            if ($noContent) {
                return $responseFactory->createRedirectResponse($definition$entityId$request$context);
            }

            $repository = $this->definitionRegistry->getRepository($definition->getEntityName());
            $criteria = new Criteria($event->getIds());
            $entities = $repository->search($criteria$context);
            $entity = $entities->first();
            \assert($entity instanceof Entity);

            
 {
    }

    #[Route(path: '/api/oauth/authorize', name: 'api.oauth.authorize', defaults: ['auth_required' => false], methods: ['POST'])]     public function authorize(Request $request): void
    {
    }

    #[Route(path: '/api/oauth/token', name: 'api.oauth.token', defaults: ['auth_required' => false], methods: ['POST'])]     public function token(Request $request): Response
    {
        $response = new Response();

        try {
            $cacheKey = $request->get('username') . '-' . $request->getClientIp();

            $this->rateLimiter->ensureAccepted(RateLimiter::OAUTH, $cacheKey);
        } catch (RateLimitExceededException $exception) {
            throw new AuthThrottledException($exception->getWaitTime()$exception);
        }

        $psr7Request = $this->psrHttpFactory->createRequest($request);
        $psr7Response = $this->psrHttpFactory->createResponse($response);

        


            return $this->redirectToRoute('frontend.home.page', $params);
        }

        if ($request->get('forwardTo')) {
            $params = $this->decodeParam($request, 'forwardParameters');

            return $this->forwardToRoute($request->get('forwardTo')[]$params);
        }

        return new Response();
    }

    /** * @param array<string, mixed> $attributes * @param array<string, mixed> $routeParameters */
    protected function forwardToRoute(string $routeName, array $attributes = [], array $routeParameters = []): Response
    {
        $router = $this->container->get('router');

        $url = $this->generateUrl($routeName$routeParameters, Router::PATH_INFO);

        
$collector = new DataCollector(
            true,
            true,
            $client,
            $client
        );

        static::assertSame('elasticsearch', $collector->getName());

        $collector->collect(
            new Request(),
            new Response()
        );

        static::assertEquals(600, $collector->getTime());
        static::assertEquals(3, $collector->getRequestAmount());
        static::assertCount(3, $collector->getRequests());
        static::assertEquals(['status' => 'green']$collector->getClusterInfo());
        static::assertEquals(['indices' => ['index1' => ['status' => 'green'], 'index2' => ['status' => 'green']]]$collector->getIndices());
    }

    public function testReset(): void
    {
        

    public function testValidation(bool $isValid, Request $request, Response $response): void
    {
        $validator = new CacheStateValidator([]);
        static::assertSame($isValid$validator->isValid($request$response));
    }

    public static function cases(): array
    {
        return [
            [true, new Request()new Response()],
            [false, self::createRequest('logged-in'), self::createResponse('logged-in')],
            [true, self::createRequest('logged-in'), self::createResponse()],
            [true, self::createRequest(), self::createResponse('cart-filled')],
            [false, self::createRequest('logged-in'), self::createResponse('cart-filled', 'logged-in')],
            [false, self::createRequest('cart-filled', 'logged-in'), self::createResponse('cart-filled', 'logged-in')],
        ];
    }

    private static function createRequest(string ...$states): Request
    {
        $request = new Request();
        

class StoreApiExceptionTest extends TestCase
{
    public function testGetErrorCode(): void
    {
        $clientException = new ClientException(
            'message',
            new Request('GET', 'https://example.com'),
            new \GuzzleHttp\Psr7\Response()
        );

        static::assertSame(
            'FRAMEWORK__STORE_ERROR',
            (new StoreApiException($clientException))->getErrorCode()
        );
    }

    public function testGetStatusCode(): void
    {
        $clientException = new ClientException(
            
public function testThrowsIfSbpRespondsWithUnauthorized(): void
    {
        $storeClient = $this->createMock(StoreClient::class);
        $json = \json_encode(['code' => 'ShopwarePlatformException-1']);

        static::assertNotFalse($json);

        $storeClient->method('signPayloadWithAppSecret')
            ->willThrowException(new ClientException(
                '',
                new Request('POST', 'app_generate_signature'),
                new Response(401, []$json)
            ));

        $handshake = new StoreHandshake(
            'http://shop.url',
            'http://app.url',
            'TestApp',
            'my-shop-id',
            $storeClient,
            Kernel::SHOPWARE_FALLBACK_VERSION
        );

        
$request1,
            $request2,
        );

        $this->cacheTagCollection->expects(static::exactly(2))
            ->method('reset');

        $this->kernel->expects(static::exactly(2))
            ->method('handle')
            ->willReturnCallback(static function DRequest $request) {
                if ($request->getRequestUri() === '/product/list?page=1' || $request->getRequestUri() === '/product/list?page=2') {
                    return new Response();
                }

                throw new \RuntimeException('Unexpected request');
            });

        $this->kernel->expects(static::once())
            ->method('reboot')
            ->with(null, null, 'cacheId');

        $container = new Container();
        $container->set(CacheStore::class$this->createMock(CacheStore::class));

        
$this->assertDefaultPaymentMethods($appEntity->getId());
        $this->assertDefaultCmsBlocks($appEntity->getId());
        $this->assertAssetExists($appEntity->getName());
        $this->assertFlowActionExists($appEntity->getId());
        $this->assertDefaultHosts($appEntity);
    }

    public function testInstallRollbacksRegistrationFailure(): void
    {
        $manifest = Manifest::createFromXmlFile(__DIR__ . '/../Manifest/_fixtures/test/manifest.xml');

        $this->appendNewResponse(new Response(500));

        $wasThrown = false;

        try {
            $this->appLifecycle->install($manifest, true, $this->context);
        } catch (AppRegistrationException) {
            $wasThrown = true;
        }

        static::assertTrue($wasThrown);
        $apps = $this->appRepository->search(new Criteria()$this->context)->getTotal();

        
use Symfony\Component\HttpFoundation\RequestStack;

/** * @internal */
class StoreSessionExpiredMiddlewareTest extends TestCase
{
    use IntegrationTestBehaviour;

    public function testReturnsResponseIfStatusCodeIsNotUnauthorized(): void
    {
        $response = new Response(200, [], '{"payload":"data"}');

        $middleware = new StoreSessionExpiredMiddleware(
            $this->getContainer()->get(Connection::class),
            new RequestStack()
        );

        $handledResponse = $middleware($response);

        static::assertSame($response$handledResponse);
    }

    
public function testGetCart(): void
    {
        $cart = new CheckoutCartPage();
        $cart->setCart(new Cart(Uuid::randomHex()));
        $this->cartPageLoaderMock->method('load')->willReturn(
            $cart
        );

        $response = $this->controller->cartPage(new Request()$this->createMock(SalesChannelContext::class));

        static::assertEquals(new Response()$response);
    }

    public function testGetCartRedirectNotOnNoErrors(): void
    {
        $cart = new CheckoutCartPage();
        $cart->setCart(new Cart(Uuid::randomHex()));
        $this->cartPageLoaderMock->method('load')->willReturn(
            $cart
        );

        $request = new Request();
        
return json_decode($responseContent, true, flags: \JSON_THROW_ON_ERROR);
    }

    private function createContext(): Context
    {
        return Context::createDefaultContext();
    }

    private function createClientException(string $message): ClientException
    {
        return new ClientException($message$this->createMock(GuzzleRequest::class)new Response(400));
    }

    /** * @param array<string, mixed>[] $data */
    private function createPluginCollection(array $data): PluginCollection
    {
        $collection = new PluginCollection();
        $counter = \count($data);
        for ($i = 0; $i < $counter; ++$i) {
            if (!\array_key_exists('id', $data[$i])) {
                
use Symfony\Component\HttpFoundation\Response;

#[Package('core')] abstract class JsonFactoryBase implements ResponseFactoryInterface
{
    public function createRedirectResponse(EntityDefinition $definition, string $id, Request $request, Context $context): Response
    {
        $headers = [
            'Location' => $this->getEntityBaseUrl($request$definition) . '/' . $id,
        ];

        return new Response(null, Response::HTTP_NO_CONTENT, $headers);
    }

    abstract protected function getApiBaseUrl(Request $request): string;

    protected function getEntityBaseUrl(Request $request, EntityDefinition $definition): string
    {
        $apiCase = $this->getApiBaseUrl($request);

        return $apiCase . '/' . $this->camelCaseToSnailCase($definition->getEntityName());
    }

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