Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[HttpClient] Get request body when using MockResponse together with Psr18Client in symfony 7.2 #59141

Open
@W0rma

Description

@W0rma

Symfony version(s) affected

7.2.0

Description

I have an api client implementation relying on PSR interfaces and use thePsr18Client of symfony.

In my tests I use theMockHttpClient together with thePsr18Client.
After the upgrade to symfony 7.2 my approach to fetch the request body from theMockResponse does not work anymore (see reproducer code).

As far as I understand this is because of#58856.

Is it still possible to get the request body as described inhttps://symfony.com/doc/current/http_client.html#full-example ifMockHttpClient is used together withPsr18Client?

How to reproduce

usePsr\Http\Client\ClientInterface;usePsr\Http\Message\RequestFactoryInterface;usePsr\Http\Message\StreamFactoryInterface;useSymfony\Component\HttpClient\MockHttpClient;useSymfony\Component\HttpClient\Response\MockResponse;useSymfony\Component\HttpClient\Psr18Client;class MyApiClient{publicfunction__construct(privateClientInterface$client,privateRequestFactoryInterface$requestFactory,privateStreamFactoryInterface$streamFactory,    ) {}publicfunctionsomeApiAction():void    {$request =$this->requestFactory->createRequest('GET','some-uri');$stream =$this->streamFactory->createStream($jsonEncodedBody);$request =$request->withBody($stream);$this->client->sendRequest($request);    }}$mockResponse =newMockResponse();$httpClient =newPsr18Client(newMockHttpClient($mockResponse),);$myApiClient =newMyApiClient($httpClient,$httpClient,$httpClient,);$myApiClient->someApiAction();$requestBody =$mockResponse->getRequestOptions()['body'];

With symfony 7.1,$mockResponse->getRequestOptions()['body']; returned astring.

With symfony 7.2,$mockResponse->getRequestOptions()['body']; returns aClosure.

Possible Solution

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp