Skip to content

Commit 6838d82

Browse files
authored
Merge pull request #513 from Nyholm/issue-511
Removed extra slash after enterprise URL
2 parents 4a06d34 + 32eadaa commit 6838d82

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
44

5+
## 2.0.2
6+
7+
### Fixed
8+
9+
- Bug with double slashes when using enterprise URL.
510

611
## 2.0.0
712

lib/Github/Client.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ private function setEnterpriseUrl($enterpriseUrl)
315315
$builder->removePlugin(PathPrepend::class);
316316

317317
$builder->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri($enterpriseUrl)));
318-
$builder->addPlugin(new PathPrepend(sprintf('/api/%s/', $this->getApiVersion())));
318+
$builder->addPlugin(new PathPrepend(sprintf('/api/%s', $this->getApiVersion())));
319319
}
320320

321321
/**

test/Github/Tests/ClientTest.php

+24
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
use Github\Exception\BadMethodCallException;
88
use Github\HttpClient\Builder;
99
use Github\HttpClient\Plugin\Authentication;
10+
use GuzzleHttp\Psr7\Response;
1011
use Http\Client\Common\Plugin;
12+
use Http\Client\HttpClient;
13+
use Psr\Http\Message\RequestInterface;
1114

1215
class ClientTest extends \PHPUnit_Framework_TestCase
1316
{
@@ -205,4 +208,25 @@ public function getApiClassesProvider()
205208
array('meta', Api\Meta::class)
206209
);
207210
}
211+
212+
/**
213+
* Make sure that the URL is correct when using enterprise.
214+
*/
215+
public function testEnterpriseUrl()
216+
{
217+
$httpClientMock = $this->getMockBuilder(HttpClient::class)
218+
->setMethods(['sendRequest'])
219+
->getMock();
220+
221+
$httpClientMock->expects($this->once())
222+
->method('sendRequest')
223+
->with($this->callback(function (RequestInterface $request) {
224+
return (string) $request->getUri() === 'https://foobar.com/api/v3/enterprise/stats/all';
225+
}))
226+
->willReturn(new Response(200, [], '[]'));
227+
228+
$httpClientBuilder = new Builder($httpClientMock);
229+
$client = new Client($httpClientBuilder, null, 'https://foobar.com');
230+
$client->enterprise()->stats()->show('all');
231+
}
208232
}

0 commit comments

Comments
 (0)