[HttpClient] Add MockResponse::getRequestMethod() and getRequestUrl() to allow inspecting which request has been sent #36487
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As same as the
MockResponse
class hasgetRequestOptions()
when doing a request; I've added:getRequestUrl()
- returns the URL used when doing the requestgetRequestMethod()
- returns the HTTP method used when doing the requestWith these two getters, we would be able to assert that the method and URL passed to the
HttpClient
were well generated. I've tried to assert the URL generated in a unit test of a class with aSymfonyHttpClient
injected and it wasn't possible. Calling$mock->getInfo('url')
returnsnull
.Example, if we have a class with
HttpClientInterface
injected like this:And if we want to do a unit test of
SymfonyHttpUserClient
right now we are not able to check if the URL of the request was well-formed passing aMockResponse
. Also, we weren't able to assert the HTTP method (maybe this piece is not so critical to assert in the unit test).This only happens if the class has injected the HttpClient and if it is used inside void methods with no being able to return the response. If the class returns the response,
url
andhttp_method
are available with$response->getInfo()
call. But this response object is a new one, is not the mock passed by argument when you instance the MockHttpClient.Var dumps of
getInfo
array:This is a minor change, I opened the PR with
4.4
as base branch; but not sure if it should be opened with5.0
as base branch or evenmaster
taking account is a feature (add two new getters in MockResponse class). Let me know if I didn't follow right the instructions (first PR on Symfony project 😃)Thanks!