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

Commit 553c454

Browse files
committed
Merge branch 'hotfix/165'
Close #165
2 parents b98e979 + b1d14aa commit 553c454

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ All notable changes to this project will be documented in this file, in reverse
2222

2323
### Fixed
2424

25+
- [#165](https://github.com/zendframework/zend-http/pull/165) fixes detection of the base URL when operating under a CLI environment.
26+
2527
- [#149](https://github.com/zendframework/zend-http/pull/149) provides fixes to `Client::setUri()` to ensure its status as a relative
2628
or absolute URI is correctly memoized.
2729

Diff for: src/PhpEnvironment/Request.php

+5
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,11 @@ protected function detectBaseUrl()
489489
// Backtrack up the SCRIPT_FILENAME to find the portion
490490
// matching PHP_SELF.
491491

492+
$argv = $this->getServer()->get('argv', []);
493+
if (isset($argv[0]) && strpos($filename, $argv[0]) === 0) {
494+
$filename = substr($filename, strlen($argv[0]));
495+
}
496+
492497
$baseUrl = '/';
493498
$basename = basename($filename);
494499
if ($basename) {

Diff for: test/PhpEnvironment/RequestTest.php

+14
Original file line numberDiff line numberDiff line change
@@ -791,4 +791,18 @@ public function testDetectBaseUrlDoesNotRaiseErrorOnEmptyBaseUrl()
791791
// If no baseUrl is detected at all, an empty string is returned.
792792
$this->assertEquals('', $url);
793793
}
794+
795+
public function testDetectCorrectBaseUrlForConsoleRequests()
796+
{
797+
$_SERVER['argv'] = ['/home/user/package/vendor/bin/phpunit'];
798+
$_SERVER['argc'] = 1;
799+
$_SERVER['SCRIPT_FILENAME'] = '/home/user/package/vendor/bin/phpunit';
800+
$_SERVER['SCRIPT_NAME'] = '/home/user/package/vendor/bin/phpunit';
801+
$_SERVER['PHP_SELF'] = '/home/user/package/vendor/bin/phpunit';
802+
803+
$request = new Request();
804+
$request->setRequestUri('/path/query/phpunit');
805+
806+
$this->assertSame('', $request->getBaseUrl());
807+
}
794808
}

0 commit comments

Comments
 (0)