Skip to content

Commit 8b6d3d1

Browse files
committed
Don't send an emtpy ref to the client
The api will return Not Found when sending an empty ref.
1 parent 2ff0101 commit 8b6d3d1

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

lib/Github/Api/AbstractApi.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ protected function get($path, array $parameters = array(), $requestHeaders = arr
6969
if (null !== $this->perPage && !isset($parameters['per_page'])) {
7070
$parameters['per_page'] = $this->perPage;
7171
}
72+
if (array_key_exists('ref', $parameters) && is_null($parameters['ref'])) {
73+
unset($parameters['ref']);
74+
}
7275
$response = $this->client->getHttpClient()->get($path, $parameters, $requestHeaders);
7376

7477
return ResponseMediator::getContent($response);

test/Github/Tests/Api/AbstractApiTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Github\Tests\Api;
44

55
use Github\Api\AbstractApi;
6+
use Guzzle\Http\Message\Response;
67

78
class AbstractApiTest extends \PHPUnit_Framework_TestCase
89
{
@@ -111,6 +112,26 @@ public function shouldPassDELETERequestToClient()
111112
$this->assertEquals($expectedArray, $api->delete('/path', array('param1' => 'param1value'), array('option1' => 'option1value')));
112113
}
113114

115+
/**
116+
* @test
117+
*/
118+
public function shouldNotPassEmptyRefToClient()
119+
{
120+
$expectedResponse = new Response('value');
121+
122+
$httpClient = $this->getHttpMock();
123+
$httpClient
124+
->expects($this->any())
125+
->method('get')
126+
->with('/path', array())
127+
->will($this->returnValue($expectedResponse));
128+
$client = $this->getClientMock();
129+
$client->setHttpClient($httpClient);
130+
131+
$api = new ExposedAbstractApiTestInstance($client);
132+
$api->get('/path', array('ref' => null));
133+
}
134+
114135
protected function getAbstractApiObject($client)
115136
{
116137
return new AbstractApiTestInstance($client);
@@ -193,3 +214,14 @@ public function delete($path, array $parameters = array(), $requestHeaders = arr
193214
return $this->client->getHttpClient()->delete($path, $parameters, $requestHeaders);
194215
}
195216
}
217+
218+
class ExposedAbstractApiTestInstance extends AbstractApi
219+
{
220+
/**
221+
* {@inheritDoc}
222+
*/
223+
public function get($path, array $parameters = array(), $requestHeaders = array())
224+
{
225+
return parent::get($path, $parameters, $requestHeaders);
226+
}
227+
}

0 commit comments

Comments
 (0)