Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
Description
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