Skip to content

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

Merged

Conversation

Simperfit
Copy link
Contributor

@Simperfit Simperfit commented Mar 2, 2018

Q A
Branch? 4.1
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets none
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.

@nicolas-grekas nicolas-grekas added this to the 4.1 milestone Mar 2, 2018
@Simperfit Simperfit force-pushed the feature/change-xhr-method-to-xhr-request branch 2 times, most recently from e9c4e08 to cbdfa5d Compare March 2, 2018 17:53
@ro0NL
Copy link
Contributor

ro0NL commented Mar 3, 2018

i think it should be either xhr() or xmlHttpRequest() :) preferring the first i guess.

@Simperfit
Copy link
Contributor Author

@javiereguiluz WDYT of @ro0NL's advice ?

@javiereguiluz
Copy link
Member

On Symfony Slack xmlHttpRequest() won 2 to 1 to xhrRequest() Other proposals were ajaxRequest() and asyncRequest()

@ro0NL
Copy link
Contributor

ro0NL commented Mar 4, 2018

👍 for xmlHttpRequest

@Simperfit Simperfit force-pushed the feature/change-xhr-method-to-xhr-request branch from cbdfa5d to a9c363c Compare March 5, 2018 16:55
@Simperfit
Copy link
Contributor Author

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);
Copy link
Contributor

@dmaicher dmaicher Mar 7, 2018

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;
+    }
 }

Copy link
Member

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.

Copy link
Contributor Author

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.

@javiereguiluz javiereguiluz added the ❄️ Feature Freeze Important Pull Requests to finish before the next Symfony "feature freeze" label Mar 12, 2018
@javiereguiluz javiereguiluz changed the title feature: transform both switchToXHR and removeXhr to a xhrRequest Transform both switchToXHR() and removeXhr() to xmlHttpRequest() Mar 12, 2018
/**
* Calls a URI with XMLHttpRequest.
*
* @return Crawler
Copy link
Member

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);
Copy link
Member

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.

@Simperfit Simperfit force-pushed the feature/change-xhr-method-to-xhr-request branch 2 times, most recently from af2da23 to debcc85 Compare March 14, 2018 09:00
@Simperfit
Copy link
Contributor Author

Test modified, review taken in account.

Status: Needs Review

@@ -48,6 +51,11 @@ protected function doRequest($request)
return $response;
}

public function getRequest()
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

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');

Copy link
Member

@nicolas-grekas nicolas-grekas Mar 19, 2018

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.

Copy link
Contributor

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 😊

https://github.com/Simperfit/symfony/blob/00f26e280c5aec7c27fd25c825285546887a1771/src/Symfony/Component/BrowserKit/Client.php#L36

So the changes to TestClient are indeed not needed and should be reverted.

@Simperfit Simperfit force-pushed the feature/change-xhr-method-to-xhr-request branch from debcc85 to 00f26e2 Compare March 16, 2018 09:04
@fabpot
Copy link
Member

fabpot commented Mar 18, 2018

Tests are apparently broken because of the changes done in this PR.

@Simperfit Simperfit force-pushed the feature/change-xhr-method-to-xhr-request branch from 00f26e2 to fd25010 Compare March 19, 2018 17:26
@fabpot
Copy link
Member

fabpot commented Mar 19, 2018

@Simperfit Can you rebase on current master?

@Simperfit Simperfit force-pushed the feature/change-xhr-method-to-xhr-request branch from fd25010 to 4ed0889 Compare March 20, 2018 07:55
@Simperfit
Copy link
Contributor Author

@fabpot PR Rebased

@fabpot
Copy link
Member

fabpot commented Mar 20, 2018

Thank you @Simperfit.

@fabpot fabpot merged commit 4ed0889 into symfony:master Mar 20, 2018
fabpot added a commit that referenced this pull request Mar 20, 2018
…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
@fabpot fabpot mentioned this pull request May 7, 2018
@Simperfit Simperfit deleted the feature/change-xhr-method-to-xhr-request branch May 16, 2018 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecation Feature ❄️ Feature Freeze Important Pull Requests to finish before the next Symfony "feature freeze" Status: Reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants