From 4ed08896fa35adb05379eebfb51b334a40bebc2e Mon Sep 17 00:00:00 2001 From: Amrouche Hamza Date: Fri, 2 Mar 2018 18:44:26 +0100 Subject: [PATCH] feature: transform both switchToXHR and removeXhr to a xhrRequest --- src/Symfony/Component/BrowserKit/Client.php | 11 ++++++----- src/Symfony/Component/BrowserKit/Tests/ClientTest.php | 6 ++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Component/BrowserKit/Client.php b/src/Symfony/Component/BrowserKit/Client.php index 0beea40c4d..f185d43fee 100644 --- a/src/Symfony/Component/BrowserKit/Client.php +++ b/src/Symfony/Component/BrowserKit/Client.php @@ -151,14 +151,15 @@ abstract class Client return isset($this->server[$key]) ? $this->server[$key] : $default; } - public function switchToXHR() + public function xmlHttpRequest(string $method, string $uri, array $parameters = array(), array $files = array(), array $server = array(), string $content = null, bool $changeHistory = true): Crawler { $this->setServerParameter('HTTP_X_REQUESTED_WITH', 'XMLHttpRequest'); - } - public function removeXHR() - { - unset($this->server['HTTP_X_REQUESTED_WITH']); + try { + return $this->request($method, $uri, $parameters, $files, $server, $content, $changeHistory); + } finally { + unset($this->server['HTTP_X_REQUESTED_WITH']); + } } /** diff --git a/src/Symfony/Component/BrowserKit/Tests/ClientTest.php b/src/Symfony/Component/BrowserKit/Tests/ClientTest.php index e441432989..741b29b9c7 100644 --- a/src/Symfony/Component/BrowserKit/Tests/ClientTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/ClientTest.php @@ -104,13 +104,11 @@ class ClientTest extends TestCase $this->assertNull($client->getRequest()); } - public function testGetRequestWithXHR() + public function testXmlHttpRequest() { $client = new TestClient(); - $client->switchToXHR(); - $client->request('GET', 'http://example.com/', array(), array(), array(), null, true, true); + $client->xmlHttpRequest('GET', 'http://example.com/', array(), array(), array(), null, true); $this->assertEquals($client->getRequest()->getServer()['HTTP_X_REQUESTED_WITH'], 'XMLHttpRequest'); - $client->removeXHR(); $this->assertFalse($client->getServerParameter('HTTP_X_REQUESTED_WITH', false)); }