Skip to content

Commit 4ed0889

Browse files
author
Amrouche Hamza
committed
feature: transform both switchToXHR and removeXhr to a xhrRequest
1 parent 6059bdc commit 4ed0889

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/Symfony/Component/BrowserKit/Client.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,15 @@ public function getServerParameter($key, $default = '')
151151
return isset($this->server[$key]) ? $this->server[$key] : $default;
152152
}
153153

154-
public function switchToXHR()
154+
public function xmlHttpRequest(string $method, string $uri, array $parameters = array(), array $files = array(), array $server = array(), string $content = null, bool $changeHistory = true): Crawler
155155
{
156156
$this->setServerParameter('HTTP_X_REQUESTED_WITH', 'XMLHttpRequest');
157-
}
158157

159-
public function removeXHR()
160-
{
161-
unset($this->server['HTTP_X_REQUESTED_WITH']);
158+
try {
159+
return $this->request($method, $uri, $parameters, $files, $server, $content, $changeHistory);
160+
} finally {
161+
unset($this->server['HTTP_X_REQUESTED_WITH']);
162+
}
162163
}
163164

164165
/**

src/Symfony/Component/BrowserKit/Tests/ClientTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,11 @@ public function testGetRequestNull()
104104
$this->assertNull($client->getRequest());
105105
}
106106

107-
public function testGetRequestWithXHR()
107+
public function testXmlHttpRequest()
108108
{
109109
$client = new TestClient();
110-
$client->switchToXHR();
111-
$client->request('GET', 'http://example.com/', array(), array(), array(), null, true, true);
110+
$client->xmlHttpRequest('GET', 'http://example.com/', array(), array(), array(), null, true);
112111
$this->assertEquals($client->getRequest()->getServer()['HTTP_X_REQUESTED_WITH'], 'XMLHttpRequest');
113-
$client->removeXHR();
114112
$this->assertFalse($client->getServerParameter('HTTP_X_REQUESTED_WITH', false));
115113
}
116114

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy