mirror of
https://github.com/elyby/league-oauth2-ely.git
synced 2024-12-22 13:29:45 +05:30
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:
commit
e9efb3aa61
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user