-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[BrowserKit] Add jsonRequest function to the browser-kit client #38596
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BrowserKit] Add jsonRequest function to the browser-kit client #38596
Conversation
e57df9b
to
4fdf2fa
Compare
4fdf2fa
to
e2edfc1
Compare
cc1415f
to
696a3f8
Compare
Thank you I like the idea of this because I know there are a lot of parameters to set when you want to test some custom requests. I am not sure it is a good idea to hard code the content type to Just FYI. There is a small package from @nebkam that I like. It has a |
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.
LGTM.
@Nyholm about to hard code the content type to application/json
I think it's fine as default value. Anyway, you'll can change these server parameters through the $server
argument if you want.
$server = array_merge($this->server, $server); |
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.
Thanks. Don't miss adding a changelog entry in the component.
@nicolas-grekas changelog is updated. fabbot is failing because of #38596 (comment) and #38596 (comment). Let me now if I need to change something. |
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.
What about @Nyholm's comment?
(yes you can ignore fabbot here, the report is a false-positive)
@Nyholm I think we should go here with |
4948af9
to
b1123d2
Compare
b1123d2
to
596b2c0
Compare
…chranz) This PR was merged into the 4.4 branch. Discussion ---------- Refractor AbstractBrowserTest to assertSame | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | Fix #...instead --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> As mentioned by @nicolas-grekas at #38596 (comment) the AbstractBrowserTest should be refractored to use `assertSame` instead of `assertEquals` to compare string. Commits ------- 3f320c8 Refractor AbstractBrowserTest to assertSame
@@ -161,6 +161,24 @@ public function xmlHttpRequest(string $method, string $uri, array $parameters = | |||
} | |||
} | |||
|
|||
/** | |||
* Converts the request parameters into a json string and used it as request content. |
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.
json string
-> JSON string
and used it
-> and uses it
52efab2
to
c2fa2cb
Compare
Thank you @alexander-schranz. |
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.
A
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.
src/Symfony/Component/BrowserKit/AbstractBrowser.php
If you use the FOSRestBundle for your Api's you have maybe many tests using just:
To test your JSON api as in the real browser request FOSRestBundle converts the json body into the
$request->request
object. I think something similar is done by ApiPlatform. If you have tests like above they will now fail as the integer is converted to string see also #38591.This PR add a new
jsonRequest
which will look like the following and will so fix the above problem: