Merge pull request #236 from vimishor/issue-230
[Fix] Invalid JSON in response will trigger fatal erroroauth1test
commit
395b345e3d
|
@ -205,6 +205,11 @@ abstract class AbstractProvider implements ProviderInterface
|
|||
switch ($this->responseType) {
|
||||
case 'json':
|
||||
$result = json_decode($response, true);
|
||||
|
||||
if (JSON_ERROR_NONE !== json_last_error()) {
|
||||
$result = [];
|
||||
}
|
||||
|
||||
break;
|
||||
case 'string':
|
||||
parse_str($response, $result);
|
||||
|
|
|
@ -65,6 +65,25 @@ class GithubTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals('1', $token->uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 230
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Required option not passed: access_token
|
||||
*/
|
||||
public function testGetAccessTokenWithInvalidJson()
|
||||
{
|
||||
$response = m::mock('Guzzle\Http\Message\Response');
|
||||
$response->shouldReceive('getBody')->times(1)->andReturn('invalid');
|
||||
|
||||
$client = m::mock('Guzzle\Service\Client');
|
||||
$client->shouldReceive('setBaseUrl')->times(1);
|
||||
$client->shouldReceive('post->send')->times(1)->andReturn($response);
|
||||
$this->provider->setHttpClient($client);
|
||||
$this->provider->responseType = 'json';
|
||||
|
||||
$this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
||||
}
|
||||
|
||||
public function testGetAccessTokenSetResultUid()
|
||||
{
|
||||
$this->provider->uidKey = 'otherKey';
|
||||
|
|
Loading…
Reference in New Issue