diff --git a/src/Provider/AbstractProvider.php b/src/Provider/AbstractProvider.php index c43a0fd..ccbb249 100644 --- a/src/Provider/AbstractProvider.php +++ b/src/Provider/AbstractProvider.php @@ -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); diff --git a/test/src/Provider/GithubTest.php b/test/src/Provider/GithubTest.php index b0e14db..dd66f50 100644 --- a/test/src/Provider/GithubTest.php +++ b/test/src/Provider/GithubTest.php @@ -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';