Skip to content

Don't send an emtpy ref to the client #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 21, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/Github/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ protected function get($path, array $parameters = array(), $requestHeaders = arr
if (null !== $this->perPage && !isset($parameters['per_page'])) {
$parameters['per_page'] = $this->perPage;
}
if (array_key_exists('ref', $parameters) && is_null($parameters['ref'])) {
unset($parameters['ref']);
}
$response = $this->client->getHttpClient()->get($path, $parameters, $requestHeaders);

return ResponseMediator::getContent($response);
Expand Down
32 changes: 32 additions & 0 deletions test/Github/Tests/Api/AbstractApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Github\Tests\Api;

use Github\Api\AbstractApi;
use Guzzle\Http\Message\Response;

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

/**
* @test
*/
public function shouldNotPassEmptyRefToClient()
{
$expectedResponse = new Response('value');

$httpClient = $this->getHttpMock();
$httpClient
->expects($this->any())
->method('get')
->with('/path', array())
->will($this->returnValue($expectedResponse));
$client = $this->getClientMock();
$client->setHttpClient($httpClient);

$api = new ExposedAbstractApiTestInstance($client);
$api->get('/path', array('ref' => null));
}

protected function getAbstractApiObject($client)
{
return new AbstractApiTestInstance($client);
Expand Down Expand Up @@ -193,3 +214,14 @@ public function delete($path, array $parameters = array(), $requestHeaders = arr
return $this->client->getHttpClient()->delete($path, $parameters, $requestHeaders);
}
}

class ExposedAbstractApiTestInstance extends AbstractApi
{
/**
* {@inheritDoc}
*/
public function get($path, array $parameters = array(), $requestHeaders = array())
{
return parent::get($path, $parameters, $requestHeaders);
}
}