Merge pull request #4 from Obsidian-MC/fix-llegal-string-offset-warning

Sometimes the $data argument of the checkResponse() method has a string type
This commit is contained in:
ErickSkrauch 2018-08-20 15:23:43 +03:00 committed by GitHub
commit e9efb3aa61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 2 deletions

View File

@ -70,8 +70,9 @@ class Provider extends AbstractProvider
protected function checkResponse(ResponseInterface $response, $data)
{
$statusCode = $response->getStatusCode();
if ($statusCode !== 200 || isset($data['message'])) {
throw new IdentityProviderException($data['message'] ?: $response->getReasonPhrase(), $statusCode, $response);
if ($statusCode !== 200) {
$message = isset($data['message']) ? $data['message'] : $response->getReasonPhrase();
throw new IdentityProviderException($message, $statusCode, $response);
}
}

View File

@ -121,6 +121,28 @@ class ProviderTest extends \PHPUnit_Framework_TestCase
$this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
}
/**
* @expectedException \Ely\OAuth2\Client\Exception\IdentityProviderException
* @expectedExceptionMessage Bad Gateway
*/
public function testExceptionThrownOnIncorrectContentType()
{
/** @var m\Mock|ResponseInterface $postResponse */
$postResponse = m::mock(ResponseInterface::class);
$postResponse->shouldReceive('getHeader')->andReturn(['content-type' => 'text/html; charset=UTF-8']);
$postResponse->shouldReceive('getBody')->andReturn('html content');
$postResponse->shouldReceive('getStatusCode')->andReturn(502);
$postResponse->shouldReceive('getReasonPhrase')->andReturn('Bad Gateway');
/** @var m\Mock|ClientInterface $client */
$client = m::mock(ClientInterface::class);
$client->shouldReceive('send')
->times(1)
->andReturn($postResponse);
$this->provider->setHttpClient($client);
$this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
}
public function testGetResourceOwner()
{
/** @var m\Mock|ResponseInterface $postResponse */