Skip to content

Commit

Permalink
fixed Connection::getBaseUri
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Feb 7, 2017
1 parent 0113459 commit c3bf1d9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/AbstractConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,19 +249,20 @@ public function checkResponse(ResponseInterface $response)
*/
abstract public function getResponseError(ResponseInterface $response);

protected $baseUriChecked;

/**
* Return API base uri.
* Adds trailing slash if uri is domain only.
* @return string
*/
public function getBaseUri()
{
static $checked;
if (empty($checked)) {
if (count(explode('/', $this->baseUri, 4)) === 3) {
if (empty($this->baseUriChecked)) {
if (preg_match('#^https?://[^/]+$#', $this->baseUri)) {
$this->baseUri .= '/';
}
$checked = true;
$this->baseUriChecked = true;
}

return $this->baseUri;
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ protected function tearDown()
{
}

public function testGetBaseUri()
public function testShortBaseUri()
{
$this->db->baseUri = $this->shortUri;
$this->assertSame($this->fixedUri, $this->db->getBaseUri());
}

public function testFixedBaseUri()
{
$this->db->baseUri = $this->fixedUri;
$this->assertSame($this->fixedUri, $this->db->getBaseUri());
}
Expand Down

0 comments on commit c3bf1d9

Please sign in to comment.