Skip to content

Commit cbb4567

Browse files
Merge branch '5.0'
* 5.0: [VarDumper] fix for change in PHP 7.4.6 (bis) [VarExporter] fix for change in PHP 7.4.6 [BrowserKit] Allow Referer set by history to be overridden (3.4)
2 parents 108757a + d2e69cc commit cbb4567

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

AbstractBrowser.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
*
2323
* To make the actual request, you need to implement the doRequest() method.
2424
*
25-
* HttpBrowser is an implementation that uses the HttpClient component
26-
* to make real HTTP requests.
27-
*
2825
* If you want to be able to run requests in their own process (insulated flag),
2926
* you need to also implement the getScript() method.
3027
*
@@ -51,9 +48,7 @@ abstract class AbstractBrowser
5148
private $isMainRequest = true;
5249

5350
/**
54-
* @param array $server The server parameters (equivalent of $_SERVER)
55-
* @param History $history A History instance to store the browser history
56-
* @param CookieJar $cookieJar A CookieJar instance to store the cookies
51+
* @param array $server The server parameters (equivalent of $_SERVER)
5752
*/
5853
public function __construct(array $server = [], History $history = null, CookieJar $cookieJar = null)
5954
{
@@ -297,7 +292,6 @@ public function clickLink(string $linkText): Crawler
297292
/**
298293
* Submits a form.
299294
*
300-
* @param Form $form A Form instance
301295
* @param array $values An array of form field values
302296
* @param array $serverParameters An array of server parameters
303297
*
@@ -366,7 +360,7 @@ public function request(string $method, string $uri, array $parameters = [], arr
366360
$uri = preg_replace('{^'.parse_url($uri, PHP_URL_SCHEME).'}', $server['HTTPS'] ? 'https' : 'http', $uri);
367361
}
368362

369-
if (!$this->history->isEmpty()) {
363+
if (!isset($server['HTTP_REFERER']) && !$this->history->isEmpty()) {
370364
$server['HTTP_REFERER'] = $this->history->current()->getUri();
371365
}
372366

@@ -481,8 +475,6 @@ protected function getScript($request)
481475
/**
482476
* Filters the BrowserKit request to the origin one.
483477
*
484-
* @param Request $request The BrowserKit Request to filter
485-
*
486478
* @return object An origin request instance
487479
*/
488480
protected function filterRequest(Request $request)
@@ -685,8 +677,7 @@ protected function getAbsoluteUri(string $uri)
685677
/**
686678
* Makes a request from a Request object directly.
687679
*
688-
* @param Request $request A Request instance
689-
* @param bool $changeHistory Whether to update the history or not (only used internally for back(), forward(), and reload())
680+
* @param bool $changeHistory Whether to update the history or not (only used internally for back(), forward(), and reload())
690681
*
691682
* @return Crawler
692683
*/
@@ -695,7 +686,7 @@ protected function requestFromRequest(Request $request, $changeHistory = true)
695686
return $this->request($request->getMethod(), $request->getUri(), $request->getParameters(), $request->getFiles(), $request->getServer(), $request->getContent(), $changeHistory);
696687
}
697688

698-
private function updateServerFromUri($server, $uri)
689+
private function updateServerFromUri(array $server, string $uri): array
699690
{
700691
$server['HTTP_HOST'] = $this->extractHost($uri);
701692
$scheme = parse_url($uri, PHP_URL_SCHEME);
@@ -705,7 +696,7 @@ private function updateServerFromUri($server, $uri)
705696
return $server;
706697
}
707698

708-
private function extractHost($uri)
699+
private function extractHost(string $uri): ?string
709700
{
710701
$host = parse_url($uri, PHP_URL_HOST);
711702

Tests/AbstractBrowserTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,15 @@ public function testRequestReferer()
215215
$this->assertEquals('http://www.example.com/foo/foobar', $server['HTTP_REFERER'], '->request() sets the referer');
216216
}
217217

218+
public function testRequestRefererCanBeOverridden()
219+
{
220+
$client = new TestClient();
221+
$client->request('GET', 'http://www.example.com/foo/foobar');
222+
$client->request('GET', 'bar', [], [], ['HTTP_REFERER' => 'xyz']);
223+
$server = $client->getRequest()->getServer();
224+
$this->assertEquals('xyz', $server['HTTP_REFERER'], '->request() allows referer to be overridden');
225+
}
226+
218227
public function testRequestHistory()
219228
{
220229
$client = $this->getBrowser();

0 commit comments

Comments
 (0)