Skip to content

Commit

Permalink
Merge branch '5.0'
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
nicolas-grekas committed May 16, 2020
2 parents 108757a + d2e69cc commit cbb4567
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
19 changes: 5 additions & 14 deletions AbstractBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
*
* To make the actual request, you need to implement the doRequest() method.
*
* HttpBrowser is an implementation that uses the HttpClient component
* to make real HTTP requests.
*
* If you want to be able to run requests in their own process (insulated flag),
* you need to also implement the getScript() method.
*
Expand All @@ -51,9 +48,7 @@ abstract class AbstractBrowser
private $isMainRequest = true;

/**
* @param array $server The server parameters (equivalent of $_SERVER)
* @param History $history A History instance to store the browser history
* @param CookieJar $cookieJar A CookieJar instance to store the cookies
* @param array $server The server parameters (equivalent of $_SERVER)
*/
public function __construct(array $server = [], History $history = null, CookieJar $cookieJar = null)
{
Expand Down Expand Up @@ -297,7 +292,6 @@ public function clickLink(string $linkText): Crawler
/**
* Submits a form.
*
* @param Form $form A Form instance
* @param array $values An array of form field values
* @param array $serverParameters An array of server parameters
*
Expand Down Expand Up @@ -366,7 +360,7 @@ public function request(string $method, string $uri, array $parameters = [], arr
$uri = preg_replace('{^'.parse_url($uri, PHP_URL_SCHEME).'}', $server['HTTPS'] ? 'https' : 'http', $uri);
}

if (!$this->history->isEmpty()) {
if (!isset($server['HTTP_REFERER']) && !$this->history->isEmpty()) {
$server['HTTP_REFERER'] = $this->history->current()->getUri();
}

Expand Down Expand Up @@ -481,8 +475,6 @@ protected function getScript($request)
/**
* Filters the BrowserKit request to the origin one.
*
* @param Request $request The BrowserKit Request to filter
*
* @return object An origin request instance
*/
protected function filterRequest(Request $request)
Expand Down Expand Up @@ -685,8 +677,7 @@ protected function getAbsoluteUri(string $uri)
/**
* Makes a request from a Request object directly.
*
* @param Request $request A Request instance
* @param bool $changeHistory Whether to update the history or not (only used internally for back(), forward(), and reload())
* @param bool $changeHistory Whether to update the history or not (only used internally for back(), forward(), and reload())
*
* @return Crawler
*/
Expand All @@ -695,7 +686,7 @@ protected function requestFromRequest(Request $request, $changeHistory = true)
return $this->request($request->getMethod(), $request->getUri(), $request->getParameters(), $request->getFiles(), $request->getServer(), $request->getContent(), $changeHistory);
}

private function updateServerFromUri($server, $uri)
private function updateServerFromUri(array $server, string $uri): array
{
$server['HTTP_HOST'] = $this->extractHost($uri);
$scheme = parse_url($uri, PHP_URL_SCHEME);
Expand All @@ -705,7 +696,7 @@ private function updateServerFromUri($server, $uri)
return $server;
}

private function extractHost($uri)
private function extractHost(string $uri): ?string
{
$host = parse_url($uri, PHP_URL_HOST);

Expand Down
9 changes: 9 additions & 0 deletions Tests/AbstractBrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,15 @@ public function testRequestReferer()
$this->assertEquals('http://www.example.com/foo/foobar', $server['HTTP_REFERER'], '->request() sets the referer');
}

public function testRequestRefererCanBeOverridden()
{
$client = new TestClient();
$client->request('GET', 'http://www.example.com/foo/foobar');
$client->request('GET', 'bar', [], [], ['HTTP_REFERER' => 'xyz']);
$server = $client->getRequest()->getServer();
$this->assertEquals('xyz', $server['HTTP_REFERER'], '->request() allows referer to be overridden');
}

public function testRequestHistory()
{
$client = $this->getBrowser();
Expand Down

0 comments on commit cbb4567

Please sign in to comment.