Skip to content
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
13 changes: 7 additions & 6 deletions lib/Github/HttpClient/Message/ResponseMediator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ class ResponseMediator
{
public static function getContent(Response $response)
{
$body = $response->getBody(true);
$content = json_decode($body, true);

if (JSON_ERROR_NONE !== json_last_error()) {
return $body;
$body = $response->getBody(true);
if (strpos($response->getContentType(), 'application/json') === 0) {
$content = json_decode($body, true);
if (JSON_ERROR_NONE === json_last_error()) {
return $content;
}
}

return $content;
return $body;
}

public static function getPagination(Response $response)
Expand Down
18 changes: 18 additions & 0 deletions test/Github/Tests/Functional/RepoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ public function shouldRetrieveRawBlob()
$this->assertStringStartsWith('<?php', $contents);
}

/**
* @test
*/
public function shouldNotDecodeRawBlob()
{
$api = $this->client->api('git_data')->blobs();
$api->configure('raw');

$contents = $api->show(
'KnpLabs',
'php-github-api',
'dc16d3e77fd4e40638cb722927ffe15fa85b1434'
);

$this->assertInternalType('string', $contents);
$this->assertStringStartsWith('{', $contents);
}

/**
* @test
*/
Expand Down
6 changes: 6 additions & 0 deletions test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ public function shouldNotPassWhen400IsSent()
$response->expects($this->once())
->method('getBody')
->will($this->returnValue(json_encode(array('message' => 'test'))));
$response->expects($this->once())
->method('getContentType')
->will($this->returnValue('application/json'));
$response->expects($this->any())
->method('getStatusCode')
->will($this->returnValue(400));
Expand Down Expand Up @@ -159,6 +162,9 @@ public function shouldNotPassWhen422IsSentWithErrorCode($errorCode)
->method('getHeader')
->with('X-RateLimit-Limit')
->will($this->returnValue(5000));
$response->expects($this->once())
->method('getContentType')
->will($this->returnValue('application/json'));
$response->expects($this->once())
->method('getBody')
->will($this->returnValue($content));
Expand Down
5 changes: 5 additions & 0 deletions test/Github/Tests/Mock/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ public function getHeader($header = null)

return $header;
}

public function getContentType()
{
return 'application/json';
}
}