Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[HttpClient] Add MockResponse::getRequestMethod() and getRequestUrl() to allow inspecting which request has been sent#36487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
nicolas-grekas commentedApr 18, 2020
Would it make sense to do |
Uh oh!
There was an error while loading.Please reload this page.
javespi commentedJun 8, 2020
Hi@nicolas-grekas, is there anything I can do to move forward this PR? Thanks! 😃 |
… to allow inspecting which request has been sent
nicolas-grekas left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
(I just rebased the PR to target master)
fabpot commentedJul 1, 2020
Thank you@javespi. |
javespi commentedJul 1, 2020
Thanks@fabpot@nicolas-grekas for all the effort and support!! |
Uh oh!
There was an error while loading.Please reload this page.
As same as the
MockResponseclass 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
HttpClientwere well generated. I've tried to assert the URL generated in a unit test of a class with aSymfonyHttpClientinjected and it wasn't possible. Calling$mock->getInfo('url')returnsnull.Example, if we have a class with
HttpClientInterfaceinjected like this:And if we want to do a unit test of
SymfonyHttpUserClientright 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,
urlandhttp_methodare 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
getInfoarray:This is a minor change, I opened the PR with
4.4as base branch; but not sure if it should be opened with5.0as base branch or evenmastertaking 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!