8000 feature: transform both switchToXHR and removeXhr to a xhrRequest · symfony/symfony@fd25010 · GitHub
[go: up one dir, main page]

Skip to content

Commit fd25010

Browse files
author
Amrouche Hamza
committed
feature: transform both switchToXHR and removeXhr to a xhrRequest
1 parent cab05ab commit fd25010

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)
0