Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/165'
Browse files Browse the repository at this point in the history
Close #165
  • Loading branch information
weierophinney committed Jan 8, 2019
2 parents b98e979 + b1d14aa commit 553c454
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -22,6 +22,8 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- [#165](https://github.com/zendframework/zend-http/pull/165) fixes detection of the base URL when operating under a CLI environment.

- [#149](https://github.com/zendframework/zend-http/pull/149) provides fixes to `Client::setUri()` to ensure its status as a relative
or absolute URI is correctly memoized.

Expand Down
5 changes: 5 additions & 0 deletions src/PhpEnvironment/Request.php
Expand Up @@ -489,6 +489,11 @@ protected function detectBaseUrl()
// Backtrack up the SCRIPT_FILENAME to find the portion
// matching PHP_SELF.

$argv = $this->getServer()->get('argv', []);
if (isset($argv[0]) && strpos($filename, $argv[0]) === 0) {
$filename = substr($filename, strlen($argv[0]));
}

$baseUrl = '/';
$basename = basename($filename);
if ($basename) {
Expand Down
14 changes: 14 additions & 0 deletions test/PhpEnvironment/RequestTest.php
Expand Up @@ -791,4 +791,18 @@ public function testDetectBaseUrlDoesNotRaiseErrorOnEmptyBaseUrl()
// If no baseUrl is detected at all, an empty string is returned.
$this->assertEquals('', $url);
}

public function testDetectCorrectBaseUrlForConsoleRequests()
{
$_SERVER['argv'] = ['/home/user/package/vendor/bin/phpunit'];
$_SERVER['argc'] = 1;
$_SERVER['SCRIPT_FILENAME'] = '/home/user/package/vendor/bin/phpunit';
$_SERVER['SCRIPT_NAME'] = '/home/user/package/vendor/bin/phpunit';
$_SERVER['PHP_SELF'] = '/home/user/package/vendor/bin/phpunit';

$request = new Request();
$request->setRequestUri('/path/query/phpunit');

$this->assertSame('', $request->getBaseUrl());
}
}

0 comments on commit 553c454

Please sign in to comment.