getLastRequest example

'source' => [
                    'url' => 'https://example.com',
                    'appVersion' => $webhookEntity->getApp()?->getVersion(),
                    'shopId' => 'foobar',
                    'action' => $event->getName(),
                ],
            ], \JSON_THROW_ON_ERROR)
        );

        $this->getWebhookDispatcher(true)->dispatch($event$event->getName());

        $request = $this->clientMock->getLastRequest();

        static::assertInstanceOf(RequestInterface::class$request);
        static::assertEquals('foo.bar', $request->getUri()->getHost());

        $headers = $request->getHeaders();
        static::assertArrayHasKey(RequestSigner::SHOPWARE_SHOP_SIGNATURE, $headers);
        unset($headers[RequestSigner::SHOPWARE_SHOP_SIGNATURE]$headers['Content-Length']$headers['User-Agent']);
        static::assertEquals($expectedRequest->getHeaders()$headers);

        $expectedContents = json_decode($expectedRequest->getBody()->getContents(), true);
        $contents = json_decode($request->getBody()->getContents(), true);
        
'eventName' => 'order',
            'appVersion' => '0.0.1',
            'url' => 'https://test.com',
            'serializedWebhookMessage' => serialize($webhookEventMessage),
        ]], Context::createDefaultContext());

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

        ($this->webhookEventMessageHandler)($webhookEventMessage);

        $timestamp = time();
        $request = $this->getLastRequest();
        static::assertInstanceOf(RequestInterface::class$request);
        $payload = $request->getBody()->getContents();
        $body = json_decode($payload, true, 512, \JSON_THROW_ON_ERROR);

        static::assertEquals('POST', $request->getMethod());
        static::assertEquals($body['body'], 'payload');
        static::assertGreaterThanOrEqual($body['timestamp']$timestamp);
        static::assertTrue($request->hasHeader('sw-version'));
        static::assertEquals($request->getHeaderLine('sw-version'), '6.4');
        static::assertEquals($request->getHeaderLine(AuthMiddleware::SHOPWARE_USER_LANGUAGE), 'en-GB');
        static::assertEquals($request->getHeaderLine(AuthMiddleware::SHOPWARE_CONTEXT_LANGUAGE), Defaults::LANGUAGE_SYSTEM);
        


    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']);

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

        static::expectException(\RuntimeException::class);
        static::expectExceptionMessage('BAN request failed to http://localhost/foo failed with error: Server error: `BAN http://localhost/foo` resulted in a `500 Internal Server Error` response');
        
$this->setLicenseDomain('shopware-test');

        $this->storeContext = $this->createAdminStoreContext();
    }

    public function testSignPayloadWithAppSecret(): void
    {
        $this->getRequestHandler()->append(new Response(200, [], '{"signature": "signed"}'));

        static::assertEquals('signed', $this->storeClient->signPayloadWithAppSecret('[this can be anything]', 'testApp'));

        $lastRequest = $this->getRequestHandler()->getLastRequest();
        static::assertInstanceOf(RequestInterface::class$lastRequest);

        static::assertEquals('/swplatform/generatesignature', $lastRequest->getUri()->getPath());

        static::assertEquals([
            'shopwareVersion' => $this->getShopwareVersion(),
            'language' => 'en-GB',
            'domain' => 'shopware-test',
        ], Query::parse($lastRequest->getUri()->getQuery()));

        static::assertEquals([
            
$this->getContainer()->get(HookableEventFactory::class),
            Kernel::SHOPWARE_FALLBACK_VERSION,
            $this->bus,
            true
        );

        // check that event wasn't replaced         $returnedEvent = $webhookDispatcher->dispatch($event);
        static::assertSame($event$returnedEvent);

        /** @var Request $request */
        $request = $this->getLastRequest();

        static::assertEquals('POST', $request->getMethod());
        $body = $request->getBody()->getContents();
        static::assertJson($body);

        $payload = json_decode($body, true, 512, \JSON_THROW_ON_ERROR);
        static::assertArrayHasKey('timestamp', $payload);
        static::assertArrayHasKey('eventId', $payload['source']);
        unset($payload['timestamp']$payload['source']['eventId']);

        static::assertEquals([
            
$mockHandler->reset();
        /** @var TestAppServer $testServer */
        $testServer = $this->getContainer()->get(TestAppServer::class);
        $testServer->reset();
    }

    public function getLastRequest(): ?RequestInterface
    {
        /** @var MockHandler $mockHandler */
        $mockHandler = $this->getContainer()->get(MockHandler::class);

        return $mockHandler->getLastRequest();
    }

    public function getPastRequest(int $index): RequestInterface
    {
        /** @var GuzzleHistoryCollector $historyCollector */
        $historyCollector = $this->getContainer()->get(GuzzleHistoryCollector::class);

        return $historyCollector->getHistory()[$index]['request'];
    }

    public function getRequestCount(): int
    {


    public function testCancelSubscriptionNotInstalled(): void
    {
        $this->getContainer()->get(SystemConfigService::class)->set(StoreService::CONFIG_KEY_STORE_LICENSE_DOMAIN, 'localhost');
        $context = $this->getContextWithStoreToken();

        $this->setCancelationResponses();

        $this->extensionLicensesService->cancelSubscription(1, $context);

        $lastRequest = $this->getRequestHandler()->getLastRequest();
        static::assertEquals(
            '/swplatform/pluginlicenses/1/cancel',
            $lastRequest->getUri()->getPath()
        );

        static::assertEquals(
            [
                'shopwareVersion' => '___VERSION___',
                'language' => 'en-GB',
                'domain' => 'localhost',
            ],
            
'http://localhost'],
            ['method' => 'BAN', 'headers' => []],
            ['method' => 'PURGE', 'headers' => [], 'urls' => ['/']],
            3,
            $this->createMock(\Redis::class),
            $this->client
        );

        $clearer = new ReverseProxyCacheClearer($this->gateway);
        $clearer->clear('noop');

        static::assertInstanceOf(RequestInterface::class$this->mockHandler->getLastRequest());

        static::assertSame('PURGE', $this->mockHandler->getLastRequest()->getMethod());
        static::assertSame('/', $this->mockHandler->getLastRequest()->getRequestTarget());
        static::assertFalse($this->mockHandler->getLastRequest()->hasHeader('foo'));
    }

    public function testClearWithHeader(): void
    {
        $this->mockHandler->append(new Response(200));

        $clearer = new ReverseProxyCacheClearer($this->gateway);
        
$orderId = $this->createOrder($paymentMethodId);
        $transactionId = $this->createTransaction($orderId$paymentMethodId);
        $salesChannelContext = $this->getSalesChannelContext($paymentMethodId);

        $response = new SyncPayResponse();
        $this->appendNewResponse($this->signResponse($response->jsonSerialize()));

        $data = new RequestDataBag(['foo' => 'bar']);
        $this->paymentService->handlePaymentByOrder($orderId$data$salesChannelContext);

        /** @var Request $request */
        $request = $this->getLastRequest();
        $body = $request->getBody()->getContents();

        $appSecret = $this->app->getAppSecret();
        static::assertNotNull($appSecret);

        static::assertTrue($request->hasHeader('shopware-shop-signature'));
        static::assertSame(\hash_hmac('sha256', $body$appSecret)$request->getHeaderLine('shopware-shop-signature'));
        static::assertNotEmpty($request->getHeaderLine('sw-version'));
        static::assertNotEmpty($request->getHeaderLine(AuthMiddleware::SHOPWARE_USER_LANGUAGE));
        static::assertNotEmpty($request->getHeaderLine(AuthMiddleware::SHOPWARE_CONTEXT_LANGUAGE));
        static::assertSame('POST', $request->getMethod());
        
static::assertSame('tag-1 tag-2', $response->headers->get('xkey'));
    }

    public function testInvalidate(): void
    {
        $gateway = new VarnishReverseProxyGateway(['http://localhost'], 0, $this->client);

        $this->mockHandler->append(new GuzzleResponse(200, [], ''));

        $gateway->invalidate(['tag-1', 'tag-2']);

        $request = $this->mockHandler->getLastRequest();
        static::assertNotNull($request);

        static::assertEquals('PURGE', $request->getMethod());
        static::assertEquals('http://localhost', $request->getUri()->__toString());
        static::assertEquals('tag-1 tag-2', $request->getHeader('xkey')[0]);
    }

    /** * @dataProvider providerExceptions */
    public function testInvalidateFails(\Throwable $e, string $message): void
    {

        $data = $this->prepareTransaction();

        $response = (new AsyncFinalizeResponse())->assign([
            'status' => StateMachineTransitionActions::ACTION_AUTHORIZE,
        ]);
        $this->appendNewResponse($this->signResponse($response->jsonSerialize()));

        $this->paymentService->finalizeTransaction($data['token']new \Symfony\Component\HttpFoundation\Request()$this->getSalesChannelContext($data['paymentMethodId']));

        /** @var Request $request */
        $request = $this->getLastRequest();
        $body = $request->getBody()->getContents();

        $appSecret = $this->app->getAppSecret();
        static::assertNotNull($appSecret);

        static::assertTrue($request->hasHeader('shopware-shop-signature'));
        static::assertSame(\hash_hmac('sha256', $body$appSecret)$request->getHeaderLine('shopware-shop-signature'));
        static::assertNotEmpty($request->getHeaderLine('sw-version'));
        static::assertNotEmpty($request->getHeaderLine(AuthMiddleware::SHOPWARE_CONTEXT_LANGUAGE));
        static::assertNotEmpty($request->getHeaderLine(AuthMiddleware::SHOPWARE_USER_LANGUAGE));
        static::assertSame('POST', $request->getMethod());
        
$client = $this->createClient(['test_case' => 'StandardFormLogin', 'root_config' => 'invalid_ip_access_control.yml']);
        $client->request('GET', '/unprotected_resource');
    }

    public function testPublicHomepage()
    {
        $client = $this->createClient(['test_case' => 'StandardFormLogin', 'root_config' => 'base_config.yml']);
        $client->request('GET', '/en/');

        $this->assertEquals(200, $client->getResponse()->getStatusCode()(string) $client->getResponse());
        $this->assertTrue($client->getResponse()->headers->getCacheControlDirective('public'));
        $this->assertSame(0, self::getContainer()->get('request_tracker_subscriber')->getLastRequest()->getSession()->getUsageIndex());
    }

    private function assertAllowed($client$path)
    {
        $client->request('GET', $path);
        $this->assertEquals(404, $client->getResponse()->getStatusCode());
    }

    private function assertRestricted($client$path)
    {
        $client->request('GET', $path);
        
$this->getContainer()->get('event_dispatcher'),
            FirstRunWizardStartedEvent::class,
            function DFirstRunWizardStartedEvent $event) use (&$dispatchedEvent): void {
                $dispatchedEvent = $event;
            }
        );

        $this->frwController->frwStart(Context::createDefaultContext());

        static::assertInstanceOf(FirstRunWizardStartedEvent::class$dispatchedEvent);

        $lastRequest = $this->getRequestHandler()->getLastRequest();
        static::assertInstanceOf(Request::class$lastRequest);
        static::assertEquals('POST', $lastRequest->getMethod());
        static::assertEquals('/swplatform/tracking/events', $lastRequest->getUri()->getPath());
    }

    public function testFrwLoginStoresFrwUserToken(): void
    {
        $frwUserToken = 'frw-us3r-t0k3n';
        $expirationDate = new \DateTimeImmutable('2022-12-15');
        $context = $this->createAdminStoreContext();

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

        $postData = \json_encode($postData);
        static::assertNotFalse($postData);
        static::assertJson($postData);

        $this->getBrowser()->request('POST', $url[][][]$postData);

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

        $request = $this->getLastRequest();
        static::assertNotNull($request);

        static::assertEquals('POST', $request->getMethod());
        $body = $request->getBody()->getContents();
        static::assertNotFalse($body);
        static::assertJson($body);
        $data = \json_decode($body, true, 512, \JSON_THROW_ON_ERROR);

        $shopIdProvider = $this->getContainer()->get(ShopIdProvider::class);

        $app = $action->getApp();
        
$response = RecurringPayResponse::create($transactionId[
            'status' => OrderTransactionStates::STATE_PAID,
        ]);

        $this->appendNewResponse($this->signResponse($response->jsonSerialize()));

        $paymentHandler = $this->getContainer()->get(AppPaymentHandler::class);
        $paymentHandler->captureRecurring($this->getRecurringStruct(), Context::createDefaultContext());

        /** @var Request $request */
        $request = $this->getLastRequest();
        $body = $request->getBody()->getContents();

        $appSecret = $this->app->getAppSecret();
        static::assertNotNull($appSecret);

        static::assertTrue($request->hasHeader('shopware-shop-signature'));
        static::assertSame(hash_hmac('sha256', $body$appSecret)$request->getHeaderLine('shopware-shop-signature'));
        static::assertNotEmpty($request->getHeaderLine('sw-version'));
        static::assertNotEmpty($request->getHeaderLine(AuthMiddleware::SHOPWARE_USER_LANGUAGE));
        static::assertNotEmpty($request->getHeaderLine(AuthMiddleware::SHOPWARE_CONTEXT_LANGUAGE));
        static::assertSame('POST', $request->getMethod());
        
Home | Imprint | This part of the site doesn't use cookies.