-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Transform both switchToXHR() and removeXhr() to xmlHttpRequest() #26381
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
Transform both switchToXHR() and removeXhr() to xmlHttpRequest() #26381
Conversation
e9c4e08 to
cbdfa5d
Compare
|
i think it should be either |
|
@javiereguiluz WDYT of @ro0NL's advice ? |
|
On Symfony Slack |
|
👍 for |
cbdfa5d to
a9c363c
Compare
|
PR updated. |
| $client->request('GET', 'http://example.com/', array(), array(), array(), null, true, true); | ||
| $this->assertEquals($client->getRequest()->getServer()['HTTP_X_REQUESTED_WITH'], 'XMLHttpRequest'); | ||
| $client->removeXHR(); | ||
| $client->xmlHttpRequest('GET', 'http://example.com/', array(), array(), array(), null, true); |
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.
in the end this test does not really test much. You can replace this with $client->request(...) and the test still passes.
Imho we should test that the client really receives a request with the correct header/server param?
You could modify the TestClient so you have access to the internal request maybe?
diff --git a/src/Symfony/Component/BrowserKit/Tests/ClientTest.php b/src/Symfony/Component/BrowserKit/Tests/ClientTest.php
index e715bb9a4c..cd7989c6a2 100644
--- a/src/Symfony/Component/BrowserKit/Tests/ClientTest.php
+++ b/src/Symfony/Component/BrowserKit/Tests/ClientTest.php
@@ -25,6 +25,7 @@ class TestClient extends Client
{
protected $nextResponse = null;
protected $nextScript = null;
+ protected $request = null;
public function setNextResponse(Response $response)
{
@@ -38,6 +39,8 @@ class TestClient extends Client
protected function doRequest($request)
{
+ $this->request = $request;
+
if (null === $this->nextResponse) {
return new Response();
}
@@ -70,6 +73,11 @@ require_once('$path');
echo serialize($this->nextScript);
EOF;
}
+
+ public function getRequest()
+ {
+ return $this->request;
+ }
}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 agree, the test does not really test anything here.
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.
Doing it, I agree too.
| /** | ||
| * Calls a URI with XMLHttpRequest. | ||
| * | ||
| * @return Crawler |
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.
This could be removed in favor of using : Crawler in the method signature instead.
| $client->request('GET', 'http://example.com/', array(), array(), array(), null, true, true); | ||
| $this->assertEquals($client->getRequest()->getServer()['HTTP_X_REQUESTED_WITH'], 'XMLHttpRequest'); | ||
| $client->removeXHR(); | ||
| $client->xmlHttpRequest('GET', 'http://example.com/', array(), array(), array(), null, true); |
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 agree, the test does not really test anything here.
af2da23 to
debcc85
Compare
|
Test modified, review taken in account. Status: Needs Review |
| return $response; | ||
| } | ||
|
|
||
| public function getRequest() |
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.
where is this method (and corresponding property) used?
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.
It’s used in the tests to check that the header has been added
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.
$this->assertEquals($client->getRequest()->getServer()['HTTP_X_REQUESTED_WITH'], 'XMLHttpRequest');
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'm sorry I don't understand. I tested locally after removing all the changes done here to the TestClient class and tests still do pass.
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.
Ahh @nicolas-grekas is right. The Client already keeps the request internally 😊
So the changes to TestClient are indeed not needed and should be reverted.
debcc85 to
00f26e2
Compare
|
Tests are apparently broken because of the changes done in this PR. |
00f26e2 to
fd25010
Compare
|
@Simperfit Can you rebase on current master? |
fd25010 to
4ed0889
Compare
|
@fabpot PR Rebased |
|
Thank you @Simperfit. |
…pRequest() (Simperfit) This PR was merged into the 4.1-dev branch. Discussion ---------- Transform both switchToXHR() and removeXhr() to xmlHttpRequest() | Q | A | ------------- | --- | Branch? | 4.1 | Bug fix? | no | New feature? | yes <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- don't forget to update UPGRADE-*.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | none <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | Will do. See #24778 (comment) for more information about this. We are switching from a possible global estate change to just only one request affected. Commits ------- 4ed0889 feature: transform both switchToXHR and removeXhr to a xhrRequest
See #24778 (comment) for more information about this.
We are switching from a possible global estate change to just only one request affected.