Remove Guzzle dependency
parent
7a0741c7df
commit
fb880c1d27
|
@ -4,7 +4,8 @@
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.4.0",
|
"php": ">=5.4.0",
|
||||||
"guzzlehttp/guzzle": "~5.0"
|
"ext-curl": "*",
|
||||||
|
"egeloen/http-adapter": "0.6.*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "~4.0",
|
"phpunit/phpunit": "~4.0",
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
namespace League\OAuth2\Client\Provider;
|
namespace League\OAuth2\Client\Provider;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use GuzzleHttp\Client as GuzzleClient;
|
use Ivory\HttpAdapter\CurlHttpAdapter;
|
||||||
use GuzzleHttp\Exception\BadResponseException;
|
use Ivory\HttpAdapter\HttpAdapterException;
|
||||||
|
use Ivory\HttpAdapter\HttpAdapterInterface;
|
||||||
use League\OAuth2\Client\Exception\IDPException as IDPException;
|
use League\OAuth2\Client\Exception\IDPException as IDPException;
|
||||||
use League\OAuth2\Client\Grant\GrantInterface;
|
use League\OAuth2\Client\Grant\GrantInterface;
|
||||||
use League\OAuth2\Client\Token\AccessToken as AccessToken;
|
use League\OAuth2\Client\Token\AccessToken as AccessToken;
|
||||||
|
@ -34,7 +35,7 @@ abstract class AbstractProvider implements ProviderInterface
|
||||||
public $headers = null;
|
public $headers = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var GuzzleClient
|
* @var HttpAdapterInterface
|
||||||
*/
|
*/
|
||||||
protected $httpClient;
|
protected $httpClient;
|
||||||
|
|
||||||
|
@ -46,7 +47,7 @@ abstract class AbstractProvider implements ProviderInterface
|
||||||
*/
|
*/
|
||||||
protected $httpBuildEncType = 1;
|
protected $httpBuildEncType = 1;
|
||||||
|
|
||||||
public function __construct($options = [])
|
public function __construct($options = [], HttpAdapterInterface $httpClient = null)
|
||||||
{
|
{
|
||||||
foreach ($options as $option => $value) {
|
foreach ($options as $option => $value) {
|
||||||
if (property_exists($this, $option)) {
|
if (property_exists($this, $option)) {
|
||||||
|
@ -54,10 +55,10 @@ abstract class AbstractProvider implements ProviderInterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setHttpClient(new GuzzleClient());
|
$this->setHttpClient($httpClient ?: new CurlHttpAdapter());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setHttpClient(GuzzleClient $client)
|
public function setHttpClient(HttpAdapterInterface $client)
|
||||||
{
|
{
|
||||||
$this->httpClient = $client;
|
$this->httpClient = $client;
|
||||||
|
|
||||||
|
@ -66,7 +67,7 @@ abstract class AbstractProvider implements ProviderInterface
|
||||||
|
|
||||||
public function getHttpClient()
|
public function getHttpClient()
|
||||||
{
|
{
|
||||||
$client = clone $this->httpClient;
|
$client = $this->httpClient;
|
||||||
|
|
||||||
return $client;
|
return $client;
|
||||||
}
|
}
|
||||||
|
@ -178,28 +179,25 @@ abstract class AbstractProvider implements ProviderInterface
|
||||||
// @codeCoverageIgnoreStart
|
// @codeCoverageIgnoreStart
|
||||||
// No providers included with this library use get but 3rd parties may
|
// No providers included with this library use get but 3rd parties may
|
||||||
$client = $this->getHttpClient();
|
$client = $this->getHttpClient();
|
||||||
$client->setBaseUrl($this->urlAccessToken() . '?' . $this->httpBuildQuery($requestParams, '', '&'));
|
$httpResponse = $client->get(
|
||||||
$request = $client->get(null, null, $requestParams)->send();
|
$this->urlAccessToken() . '?' . $this->httpBuildQuery($requestParams, '', '&')
|
||||||
$response = $request->getBody();
|
);
|
||||||
|
$response = (string) $httpResponse->getBody();
|
||||||
break;
|
break;
|
||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
case 'POST':
|
case 'POST':
|
||||||
$client = $this->getHttpClient();
|
$client = $this->getHttpClient();
|
||||||
$url = $this->urlAccessToken();
|
$httpResponse = $client->post($this->urlAccessToken(), [], $requestParams);
|
||||||
$options = [
|
$response = (string) $httpResponse->getBody();
|
||||||
'body' => $requestParams
|
|
||||||
];
|
|
||||||
$request = $client->post($url, $options);
|
|
||||||
$response = $request->getBody();
|
|
||||||
break;
|
break;
|
||||||
// @codeCoverageIgnoreStart
|
// @codeCoverageIgnoreStart
|
||||||
default:
|
default:
|
||||||
throw new \InvalidArgumentException('Neither GET nor POST is specified for request');
|
throw new \InvalidArgumentException('Neither GET nor POST is specified for request');
|
||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
}
|
}
|
||||||
} catch (BadResponseException $e) {
|
} catch (HttpAdapterException $e) {
|
||||||
// @codeCoverageIgnoreStart
|
// @codeCoverageIgnoreStart
|
||||||
$response = $e->getResponse()->getBody();
|
$response = (string) $e->getResponse()->getBody();
|
||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,17 +333,12 @@ abstract class AbstractProvider implements ProviderInterface
|
||||||
try {
|
try {
|
||||||
$client = $this->getHttpClient();
|
$client = $this->getHttpClient();
|
||||||
|
|
||||||
$options = [];
|
$httpResponse = $client->get($url, $this->headers ?: []);
|
||||||
|
|
||||||
if ($this->headers) {
|
$response = (string) $httpResponse->getBody();
|
||||||
$options['headers'] = $this->headers;
|
} catch (HttpAdapterException $e) {
|
||||||
}
|
|
||||||
|
|
||||||
$request = $client->get($url, $options);
|
|
||||||
$response = $request->getBody();
|
|
||||||
} catch (BadResponseException $e) {
|
|
||||||
// @codeCoverageIgnoreStart
|
// @codeCoverageIgnoreStart
|
||||||
$raw_response = explode("\n", $e->getResponse());
|
$raw_response = explode("\n", (string) $e->getResponse()->getBody());
|
||||||
throw new IDPException(end($raw_response));
|
throw new IDPException(end($raw_response));
|
||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
}
|
}
|
||||||
|
@ -353,7 +346,6 @@ abstract class AbstractProvider implements ProviderInterface
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function setRedirectHandler(Closure $handler)
|
public function setRedirectHandler(Closure $handler)
|
||||||
{
|
{
|
||||||
$this->redirectHandler = $handler;
|
$this->redirectHandler = $handler;
|
||||||
|
|
|
@ -28,10 +28,8 @@ class Microsoft extends AbstractProvider
|
||||||
public function userDetails($response, AccessToken $token)
|
public function userDetails($response, AccessToken $token)
|
||||||
{
|
{
|
||||||
$client = $this->getHttpClient();
|
$client = $this->getHttpClient();
|
||||||
$url = 'https://apis.live.net/v5.0/' . $response->id . '/picture';
|
$httpResponse = $client->get('https://apis.live.net/v5.0/'.$response->id.'/picture');
|
||||||
$request = $client->get($url);
|
$imageUrl = $httpResponse->getHeader('location');
|
||||||
$info = $request->getInfo();
|
|
||||||
$imageUrl = $info['url'];
|
|
||||||
|
|
||||||
$user = new User();
|
$user = new User();
|
||||||
|
|
||||||
|
|
|
@ -41,4 +41,4 @@ class IDPExceptionTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$this->assertEquals('message: 404: message', (string)$exception);
|
$this->assertEquals('message: 404: message', (string)$exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ use Mockery as m;
|
||||||
|
|
||||||
class AuthorizationCodeTest extends \PHPUnit_Framework_TestCase
|
class AuthorizationCodeTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
/** @var \League\OAuth2\Client\Provider\AbstractProvider */
|
||||||
protected $provider;
|
protected $provider;
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
|
@ -30,7 +31,7 @@ class AuthorizationCodeTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException BadMethodCallException
|
* @expectedException \BadMethodCallException
|
||||||
*/
|
*/
|
||||||
public function testInvalidRefreshToken()
|
public function testInvalidRefreshToken()
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,10 +2,12 @@
|
||||||
|
|
||||||
namespace League\OAuth2\Client\Test\Grant;
|
namespace League\OAuth2\Client\Test\Grant;
|
||||||
|
|
||||||
|
use Ivory\HttpAdapter\Message\Stream\StringStream;
|
||||||
use Mockery as m;
|
use Mockery as m;
|
||||||
|
|
||||||
class ClientCredentialsTest extends \PHPUnit_Framework_TestCase
|
class ClientCredentialsTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
/** @var \League\OAuth2\Client\Provider\AbstractProvider */
|
||||||
protected $provider;
|
protected $provider;
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
|
@ -25,11 +27,12 @@ class ClientCredentialsTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testGetAccessToken()
|
public function testGetAccessToken()
|
||||||
{
|
{
|
||||||
$response = m::mock('GuzzleHttp\Message\Response');
|
$response = m::mock('Ivory\HttpAdapter\Message\ResponseInterface');
|
||||||
$response->shouldReceive('getBody')->times(1)->andReturn('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
|
$response->shouldReceive('getBody')->times(1)->andReturn(new StringStream('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}'));
|
||||||
|
|
||||||
$client = m::mock('GuzzleHttp\Client');
|
$client = m::mock('Ivory\HttpAdapter\HttpAdapterInterface');
|
||||||
$client->shouldReceive('post')->times(1)->andReturn($response);
|
$client->shouldReceive('post')->times(1)->andReturn($response);
|
||||||
|
|
||||||
$this->provider->setHttpClient($client);
|
$this->provider->setHttpClient($client);
|
||||||
|
|
||||||
$token = $this->provider->getAccessToken('client_credentials');
|
$token = $this->provider->getAccessToken('client_credentials');
|
||||||
|
|
|
@ -2,10 +2,12 @@
|
||||||
|
|
||||||
namespace League\OAuth2\Client\Test\Grant;
|
namespace League\OAuth2\Client\Test\Grant;
|
||||||
|
|
||||||
|
use Ivory\HttpAdapter\Message\Stream\StringStream;
|
||||||
use Mockery as m;
|
use Mockery as m;
|
||||||
|
|
||||||
class PasswordTest extends \PHPUnit_Framework_TestCase
|
class PasswordTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
/** @var \League\OAuth2\Client\Provider\AbstractProvider */
|
||||||
protected $provider;
|
protected $provider;
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
|
@ -25,11 +27,12 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testGetAccessToken()
|
public function testGetAccessToken()
|
||||||
{
|
{
|
||||||
$response = m::mock('GuzzleHttp\Message\Response');
|
$response = m::mock('Ivory\HttpAdapter\Message\ResponseInterface');
|
||||||
$response->shouldReceive('getBody')->times(1)->andReturn('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
|
$response->shouldReceive('getBody')->times(1)->andReturn(new StringStream('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}'));
|
||||||
|
|
||||||
$client = m::mock('GuzzleHttp\Client');
|
$client = m::mock('Ivory\HttpAdapter\HttpAdapterInterface');
|
||||||
$client->shouldReceive('post')->times(1)->andReturn($response);
|
$client->shouldReceive('post')->times(1)->andReturn($response);
|
||||||
|
|
||||||
$this->provider->setHttpClient($client);
|
$this->provider->setHttpClient($client);
|
||||||
|
|
||||||
$token = $this->provider->getAccessToken('password', array('username' => 'mock_username', 'password' => 'mock_password'));
|
$token = $this->provider->getAccessToken('password', array('username' => 'mock_username', 'password' => 'mock_password'));
|
||||||
|
@ -40,7 +43,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException BadMethodCallException
|
* @expectedException \BadMethodCallException
|
||||||
*/
|
*/
|
||||||
public function testInvalidUsername()
|
public function testInvalidUsername()
|
||||||
{
|
{
|
||||||
|
@ -48,7 +51,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException BadMethodCallException
|
* @expectedException \BadMethodCallException
|
||||||
*/
|
*/
|
||||||
public function testInvalidPassword()
|
public function testInvalidPassword()
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,6 +6,7 @@ use Mockery as m;
|
||||||
|
|
||||||
class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
/** @var \League\OAuth2\Client\Provider\AbstractProvider */
|
||||||
protected $provider;
|
protected $provider;
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
|
@ -25,11 +26,12 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testGetAccessToken()
|
public function testGetAccessToken()
|
||||||
{
|
{
|
||||||
$response = m::mock('GuzzleHttp\Message\Response');
|
$response = m::mock('Ivory\HttpAdapter\Message\ResponseInterface');
|
||||||
$response->shouldReceive('getBody')->times(2)->andReturn('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
|
$response->shouldReceive('getBody')->times(2)->andReturn(new \Ivory\HttpAdapter\Message\Stream\StringStream('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}'));
|
||||||
|
|
||||||
$client = m::mock('GuzzleHttp\Client');
|
$client = m::mock('Ivory\HttpAdapter\HttpAdapterInterface');
|
||||||
$client->shouldReceive('post')->times(2)->andReturn($response);
|
$client->shouldReceive('post')->times(2)->andReturn($response);
|
||||||
|
|
||||||
$this->provider->setHttpClient($client);
|
$this->provider->setHttpClient($client);
|
||||||
|
|
||||||
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
||||||
|
@ -43,15 +45,16 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException BadMethodCallException
|
* @expectedException \BadMethodCallException
|
||||||
*/
|
*/
|
||||||
public function testInvalidRefreshToken()
|
public function testInvalidRefreshToken()
|
||||||
{
|
{
|
||||||
$response = m::mock('GuzzleHttp\Message\Response');
|
$response = m::mock('Ivory\HttpAdapter\Message\ResponseInterface');
|
||||||
$response->shouldReceive('getBody')->times(1)->andReturn('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
|
$response->shouldReceive('getBody')->times(1)->andReturn(new \Ivory\HttpAdapter\Message\Stream\StringStream('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}'));
|
||||||
|
|
||||||
$client = m::mock('GuzzleHttp\Client');
|
$client = m::mock('Ivory\HttpAdapter\HttpAdapterInterface');
|
||||||
$client->shouldReceive('post')->times(1)->andReturn($response);
|
$client->shouldReceive('post')->times(1)->andReturn($response);
|
||||||
|
|
||||||
$this->provider->setHttpClient($client);
|
$this->provider->setHttpClient($client);
|
||||||
|
|
||||||
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
||||||
|
|
|
@ -29,7 +29,7 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException InvalidArgumentException
|
* @expectedException \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function testInvalidGrantString()
|
public function testInvalidGrantString()
|
||||||
{
|
{
|
||||||
|
@ -37,7 +37,7 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException InvalidArgumentException
|
* @expectedException \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function testInvalidGrantObject()
|
public function testInvalidGrantObject()
|
||||||
{
|
{
|
||||||
|
@ -78,6 +78,14 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testConstructorSetsHttpAdapter()
|
||||||
|
{
|
||||||
|
$mockAdapter = m::mock('Ivory\HttpAdapter\HttpAdapterInterface');
|
||||||
|
|
||||||
|
$mockProvider = new MockProvider([], $mockAdapter);
|
||||||
|
$this->assertSame($mockAdapter, $mockProvider->getHttpClient());
|
||||||
|
}
|
||||||
|
|
||||||
public function testSetRedirectHandler()
|
public function testSetRedirectHandler()
|
||||||
{
|
{
|
||||||
$this->testFunction = false;
|
$this->testFunction = false;
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace League\OAuth2\Client\Test\Provider;
|
||||||
|
|
||||||
|
use Ivory\HttpAdapter\Message\Stream\StringStream;
|
||||||
|
use Mockery as m;
|
||||||
|
|
||||||
|
abstract class ConcreteProviderTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var \League\OAuth2\Client\Provider\AbstractProvider
|
||||||
|
*/
|
||||||
|
protected $provider;
|
||||||
|
|
||||||
|
protected function tearDown()
|
||||||
|
{
|
||||||
|
m::close();
|
||||||
|
parent::tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createMockHttpClient()
|
||||||
|
{
|
||||||
|
$client = m::mock('Ivory\HttpAdapter\HttpAdapterInterface');
|
||||||
|
$client->shouldReceive('getConfiguration')->andReturn(new \Ivory\HttpAdapter\Configuration());
|
||||||
|
|
||||||
|
return $client;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createMockResponse($responseBody)
|
||||||
|
{
|
||||||
|
$response = m::mock('Ivory\HttpAdapter\Message\ResponseInterface');
|
||||||
|
$response->shouldReceive('getBody')->andReturn(new StringStream($responseBody));
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,10 +4,8 @@ namespace League\OAuth2\Client\Test\Provider;
|
||||||
|
|
||||||
use Mockery as m;
|
use Mockery as m;
|
||||||
|
|
||||||
class EventbriteTest extends \PHPUnit_Framework_TestCase
|
class EventbriteTest extends ConcreteProviderTest
|
||||||
{
|
{
|
||||||
protected $provider;
|
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
$this->provider = new \League\OAuth2\Client\Provider\Eventbrite([
|
$this->provider = new \League\OAuth2\Client\Provider\Eventbrite([
|
||||||
|
@ -17,12 +15,6 @@ class EventbriteTest extends \PHPUnit_Framework_TestCase
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
|
||||||
{
|
|
||||||
m::close();
|
|
||||||
parent::tearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testAuthorizationUrl()
|
public function testAuthorizationUrl()
|
||||||
{
|
{
|
||||||
$url = $this->provider->getAuthorizationUrl();
|
$url = $this->provider->getAuthorizationUrl();
|
||||||
|
@ -48,11 +40,9 @@ class EventbriteTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testGetAccessToken()
|
public function testGetAccessToken()
|
||||||
{
|
{
|
||||||
$response = m::mock('GuzzleHttp\Message\Response');
|
$client = $this->createMockHttpClient();
|
||||||
$response->shouldReceive('getBody')->times(1)->andReturn('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
|
$client->shouldReceive('post')->times(1)->andReturn($this->createMockResponse('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}'));
|
||||||
|
|
||||||
$client = m::mock('GuzzleHttp\Client');
|
|
||||||
$client->shouldReceive('post')->times(1)->andReturn($response);
|
|
||||||
$this->provider->setHttpClient($client);
|
$this->provider->setHttpClient($client);
|
||||||
|
|
||||||
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
||||||
|
@ -71,13 +61,11 @@ class EventbriteTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testUserData()
|
public function testUserData()
|
||||||
{
|
{
|
||||||
$postResponse = m::mock('GuzzleHttp\Message\Response');
|
$client = $this->createMockHttpClient();
|
||||||
$postResponse->shouldReceive('getBody')->times(1)->andReturn('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
|
|
||||||
|
|
||||||
$getResponse = m::mock('GuzzleHttp\Message\Response');
|
$postResponse = $this->createMockResponse('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
|
||||||
$getResponse->shouldReceive('getBody')->times(4)->andReturn('{"user": {"user_id": 12345, "email": "mock_email"}}');
|
$getResponse = $this->createMockResponse('{"user": {"user_id": 12345, "email": "mock_email"}}');
|
||||||
|
|
||||||
$client = m::mock('GuzzleHttp\Client');
|
|
||||||
$client->shouldReceive('post')->times(1)->andReturn($postResponse);
|
$client->shouldReceive('post')->times(1)->andReturn($postResponse);
|
||||||
$client->shouldReceive('get')->times(4)->andReturn($getResponse);
|
$client->shouldReceive('get')->times(4)->andReturn($getResponse);
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,11 @@ namespace League\OAuth2\Client\Test\Provider;
|
||||||
|
|
||||||
use Mockery as m;
|
use Mockery as m;
|
||||||
|
|
||||||
class GithubTest extends \PHPUnit_Framework_TestCase
|
class GithubTest extends ConcreteProviderTest
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var \League\OAuth2\Client\Provider\Github
|
||||||
|
*/
|
||||||
protected $provider;
|
protected $provider;
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
|
@ -17,12 +20,6 @@ class GithubTest extends \PHPUnit_Framework_TestCase
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
|
||||||
{
|
|
||||||
m::close();
|
|
||||||
parent::tearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testAuthorizationUrl()
|
public function testAuthorizationUrl()
|
||||||
{
|
{
|
||||||
$url = $this->provider->getAuthorizationUrl();
|
$url = $this->provider->getAuthorizationUrl();
|
||||||
|
@ -48,11 +45,9 @@ class GithubTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testGetAccessToken()
|
public function testGetAccessToken()
|
||||||
{
|
{
|
||||||
$response = m::mock('GuzzleHttp\Message\Response');
|
$client = $this->createMockHttpClient();
|
||||||
$response->shouldReceive('getBody')->times(1)->andReturn('access_token=mock_access_token&expires=3600&refresh_token=mock_refresh_token&uid=1');
|
$client->shouldReceive('post')->times(1)->andReturn($this->createMockResponse('access_token=mock_access_token&expires=3600&refresh_token=mock_refresh_token&uid=1'));
|
||||||
|
|
||||||
$client = m::mock('GuzzleHttp\Client');
|
|
||||||
$client->shouldReceive('post')->times(1)->andReturn($response);
|
|
||||||
$this->provider->setHttpClient($client);
|
$this->provider->setHttpClient($client);
|
||||||
|
|
||||||
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
||||||
|
@ -68,11 +63,9 @@ class GithubTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$this->provider->uidKey = 'otherKey';
|
$this->provider->uidKey = 'otherKey';
|
||||||
|
|
||||||
$response = m::mock('GuzzleHttp\Message\Response');
|
$client = $this->createMockHttpClient();
|
||||||
$response->shouldReceive('getBody')->times(1)->andReturn('access_token=mock_access_token&expires=3600&refresh_token=mock_refresh_token&otherKey={1234}');
|
$client->shouldReceive('post')->times(1)->andReturn($this->createMockResponse('access_token=mock_access_token&expires=3600&refresh_token=mock_refresh_token&otherKey={1234}'));
|
||||||
|
|
||||||
$client = m::mock('GuzzleHttp\Client');
|
|
||||||
$client->shouldReceive('post')->times(1)->andReturn($response);
|
|
||||||
$this->provider->setHttpClient($client);
|
$this->provider->setHttpClient($client);
|
||||||
|
|
||||||
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
||||||
|
@ -92,15 +85,14 @@ class GithubTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testUserData()
|
public function testUserData()
|
||||||
{
|
{
|
||||||
$postResponse = m::mock('GuzzleHttp\Message\Response');
|
$client = $this->createMockHttpClient();
|
||||||
$postResponse->shouldReceive('getBody')->times(1)->andReturn('access_token=mock_access_token&expires=3600&refresh_token=mock_refresh_token&uid=1');
|
|
||||||
|
|
||||||
$getResponse = m::mock('GuzzleHttp\Message\Response');
|
$postResponse = $this->createMockResponse('access_token=mock_access_token&expires=3600&refresh_token=mock_refresh_token&uid=1');
|
||||||
$getResponse->shouldReceive('getBody')->times(4)->andReturn('{"id": 12345, "login": "mock_login", "name": "mock_name", "email": "mock_email"}');
|
$getResponse = $this->createMockResponse('{"id": 12345, "login": "mock_login", "name": "mock_name", "email": "mock_email"}');
|
||||||
|
|
||||||
$client = m::mock('GuzzleHttp\Client');
|
|
||||||
$client->shouldReceive('post')->times(1)->andReturn($postResponse);
|
$client->shouldReceive('post')->times(1)->andReturn($postResponse);
|
||||||
$client->shouldReceive('get')->times(4)->andReturn($getResponse);
|
$client->shouldReceive('get')->times(4)->andReturn($getResponse);
|
||||||
|
|
||||||
$this->provider->setHttpClient($client);
|
$this->provider->setHttpClient($client);
|
||||||
|
|
||||||
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
||||||
|
@ -114,11 +106,9 @@ class GithubTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testGithubDomainUrls()
|
public function testGithubDomainUrls()
|
||||||
{
|
{
|
||||||
$client = m::mock('GuzzleHttp\Client');
|
$client = $this->createMockHttpClient();
|
||||||
$response = m::mock('GuzzleHttp\Message\Response');
|
$client->shouldReceive('post')->times(1)->andReturn($this->createMockResponse('access_token=mock_access_token&expires=3600&refresh_token=mock_refresh_token&otherKey={1234}'));
|
||||||
$response->shouldReceive('getBody')->times(1)->andReturn('access_token=mock_access_token&expires=3600&refresh_token=mock_refresh_token&otherKey={1234}');
|
|
||||||
|
|
||||||
$client->shouldReceive('post')->times(1)->andReturn($response);
|
|
||||||
$this->provider->setHttpClient($client);
|
$this->provider->setHttpClient($client);
|
||||||
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
||||||
|
|
||||||
|
@ -132,11 +122,9 @@ class GithubTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$this->provider->domain = 'https://github.company.com';
|
$this->provider->domain = 'https://github.company.com';
|
||||||
|
|
||||||
$client = m::mock('GuzzleHttp\Client');
|
$client = $this->createMockHttpClient();
|
||||||
$response = m::mock('GuzzleHttp\Message\Response');
|
$client->shouldReceive('post')->times(1)->andReturn($this->createMockResponse('access_token=mock_access_token&expires=3600&refresh_token=mock_refresh_token&otherKey={1234}'));
|
||||||
$response->shouldReceive('getBody')->times(1)->andReturn('access_token=mock_access_token&expires=3600&refresh_token=mock_refresh_token&otherKey={1234}');
|
|
||||||
|
|
||||||
$client->shouldReceive('post')->times(1)->andReturn($response);
|
|
||||||
$this->provider->setHttpClient($client);
|
$this->provider->setHttpClient($client);
|
||||||
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
||||||
|
|
||||||
|
@ -148,15 +136,14 @@ class GithubTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testUserEmails()
|
public function testUserEmails()
|
||||||
{
|
{
|
||||||
$postResponse = m::mock('GuzzleHttp\Message\Response');
|
$client = $this->createMockHttpClient();
|
||||||
$postResponse->shouldReceive('getBody')->times(1)->andReturn('access_token=mock_access_token&expires=3600&refresh_token=mock_refresh_token&uid=1');
|
|
||||||
|
|
||||||
$getResponse = m::mock('GuzzleHttp\Message\Response');
|
$postResponse = $this->createMockResponse('access_token=mock_access_token&expires=3600&refresh_token=mock_refresh_token&uid=1');
|
||||||
$getResponse->shouldReceive('getBody')->times(1)->andReturn('[{"email":"mock_email_1","primary":false,"verified":true},{"email":"mock_email_2","primary":false,"verified":true},{"email":"mock_email_3","primary":true,"verified":true}]');
|
$getResponse = $this->createMockResponse('[{"email":"mock_email_1","primary":false,"verified":true},{"email":"mock_email_2","primary":false,"verified":true},{"email":"mock_email_3","primary":true,"verified":true}]');
|
||||||
|
|
||||||
$client = m::mock('GuzzleHttp\Client');
|
|
||||||
$client->shouldReceive('post')->times(1)->andReturn($postResponse);
|
$client->shouldReceive('post')->times(1)->andReturn($postResponse);
|
||||||
$client->shouldReceive('get')->times(1)->andReturn($getResponse);
|
$client->shouldReceive('get')->times(1)->andReturn($getResponse);
|
||||||
|
|
||||||
$this->provider->setHttpClient($client);
|
$this->provider->setHttpClient($client);
|
||||||
|
|
||||||
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
||||||
|
|
|
@ -4,8 +4,11 @@ namespace League\OAuth2\Client\Test\Provider;
|
||||||
|
|
||||||
use Mockery as m;
|
use Mockery as m;
|
||||||
|
|
||||||
class GoogleTest extends \PHPUnit_Framework_TestCase
|
class GoogleTest extends ConcreteProviderTest
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var \League\OAuth2\Client\Provider\Google
|
||||||
|
*/
|
||||||
protected $provider;
|
protected $provider;
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
|
@ -19,12 +22,6 @@ class GoogleTest extends \PHPUnit_Framework_TestCase
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
|
||||||
{
|
|
||||||
m::close();
|
|
||||||
parent::tearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testAuthorizationUrl()
|
public function testAuthorizationUrl()
|
||||||
{
|
{
|
||||||
$url = $this->provider->getAuthorizationUrl();
|
$url = $this->provider->getAuthorizationUrl();
|
||||||
|
@ -52,11 +49,9 @@ class GoogleTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testGetAccessToken()
|
public function testGetAccessToken()
|
||||||
{
|
{
|
||||||
$response = m::mock('GuzzleHttp\Message\Response');
|
$client = $this->createMockHttpClient();
|
||||||
$response->shouldReceive('getBody')->times(1)->andReturn('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
|
$client->shouldReceive('post')->times(1)->andReturn($this->createMockResponse('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}'));
|
||||||
|
|
||||||
$client = m::mock('GuzzleHttp\Client');
|
|
||||||
$client->shouldReceive('post')->times(1)->andReturn($response);
|
|
||||||
$this->provider->setHttpClient($client);
|
$this->provider->setHttpClient($client);
|
||||||
|
|
||||||
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
||||||
|
@ -77,15 +72,14 @@ class GoogleTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testUserData()
|
public function testUserData()
|
||||||
{
|
{
|
||||||
$postResponse = m::mock('GuzzleHttp\Message\Response');
|
$client = $this->createMockHttpClient();
|
||||||
$postResponse->shouldReceive('getBody')->times(1)->andReturn('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
|
|
||||||
|
|
||||||
$getResponse = m::mock('GuzzleHttp\Message\Response');
|
$postResponse = $this->createMockResponse('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
|
||||||
$getResponse->shouldReceive('getBody')->times(4)->andReturn('{"emails": [{"value": "mock_email"}],"id": "12345","displayName": "mock_name","name": {"familyName": "mock_last_name","givenName": "mock_first_name"},"image": {"url": "mock_image_url"}}');
|
$getResponse = $this->createMockResponse('{"emails": [{"value": "mock_email"}],"id": "12345","displayName": "mock_name","name": {"familyName": "mock_last_name","givenName": "mock_first_name"},"image": {"url": "mock_image_url"}}');
|
||||||
|
|
||||||
$client = m::mock('GuzzleHttp\Client');
|
|
||||||
$client->shouldReceive('post')->times(1)->andReturn($postResponse);
|
$client->shouldReceive('post')->times(1)->andReturn($postResponse);
|
||||||
$client->shouldReceive('get')->times(4)->andReturn($getResponse);
|
$client->shouldReceive('get')->times(4)->andReturn($getResponse);
|
||||||
|
|
||||||
$this->provider->setHttpClient($client);
|
$this->provider->setHttpClient($client);
|
||||||
|
|
||||||
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
||||||
|
|
|
@ -4,10 +4,8 @@ namespace League\OAuth2\Client\Test\Provider;
|
||||||
|
|
||||||
use Mockery as m;
|
use Mockery as m;
|
||||||
|
|
||||||
class InstagramTest extends \PHPUnit_Framework_TestCase
|
class InstagramTest extends ConcreteProviderTest
|
||||||
{
|
{
|
||||||
protected $provider;
|
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
$this->provider = new \League\OAuth2\Client\Provider\Instagram([
|
$this->provider = new \League\OAuth2\Client\Provider\Instagram([
|
||||||
|
@ -17,12 +15,6 @@ class InstagramTest extends \PHPUnit_Framework_TestCase
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
|
||||||
{
|
|
||||||
m::close();
|
|
||||||
parent::tearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testAuthorizationUrl()
|
public function testAuthorizationUrl()
|
||||||
{
|
{
|
||||||
$url = $this->provider->getAuthorizationUrl();
|
$url = $this->provider->getAuthorizationUrl();
|
||||||
|
@ -48,11 +40,9 @@ class InstagramTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testGetAccessToken()
|
public function testGetAccessToken()
|
||||||
{
|
{
|
||||||
$response = m::mock('GuzzleHttp\Message\Response');
|
$client = $this->createMockHttpClient();
|
||||||
$response->shouldReceive('getBody')->times(1)->andReturn('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
|
$client->shouldReceive('post')->times(1)->andReturn($this->createMockResponse('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}'));
|
||||||
|
|
||||||
$client = m::mock('GuzzleHttp\Client');
|
|
||||||
$client->shouldReceive('post')->times(1)->andReturn($response);
|
|
||||||
$this->provider->setHttpClient($client);
|
$this->provider->setHttpClient($client);
|
||||||
|
|
||||||
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
||||||
|
@ -73,15 +63,14 @@ class InstagramTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testUserData()
|
public function testUserData()
|
||||||
{
|
{
|
||||||
$postResponse = m::mock('GuzzleHttp\Message\Response');
|
$client = $this->createMockHttpClient();
|
||||||
$postResponse->shouldReceive('getBody')->times(1)->andReturn('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
|
|
||||||
|
|
||||||
$getResponse = m::mock('GuzzleHttp\Message\Response');
|
$postResponse = $this->createMockResponse('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
|
||||||
$getResponse->shouldReceive('getBody')->times(4)->andReturn('{"data": {"id": "12345", "username": "mock_username", "full_name": "mock_full_name", "bio": "mock_bio", "profile_picture": "mock_profile_picture"}}');
|
$getResponse = $this->createMockResponse('{"data": {"id": "12345", "username": "mock_username", "full_name": "mock_full_name", "bio": "mock_bio", "profile_picture": "mock_profile_picture"}}');
|
||||||
|
|
||||||
$client = m::mock('GuzzleHttp\Client');
|
|
||||||
$client->shouldReceive('post')->times(1)->andReturn($postResponse);
|
$client->shouldReceive('post')->times(1)->andReturn($postResponse);
|
||||||
$client->shouldReceive('get')->times(4)->andReturn($getResponse);
|
$client->shouldReceive('get')->times(4)->andReturn($getResponse);
|
||||||
|
|
||||||
$this->provider->setHttpClient($client);
|
$this->provider->setHttpClient($client);
|
||||||
|
|
||||||
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
||||||
|
|
|
@ -4,10 +4,8 @@ namespace League\OAuth2\Client\Test\Provider;
|
||||||
|
|
||||||
use Mockery as m;
|
use Mockery as m;
|
||||||
|
|
||||||
class LinkedInTest extends \PHPUnit_Framework_TestCase
|
class LinkedInTest extends ConcreteProviderTest
|
||||||
{
|
{
|
||||||
protected $provider;
|
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
$this->provider = new \League\OAuth2\Client\Provider\LinkedIn([
|
$this->provider = new \League\OAuth2\Client\Provider\LinkedIn([
|
||||||
|
@ -17,12 +15,6 @@ class LinkedInTest extends \PHPUnit_Framework_TestCase
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
|
||||||
{
|
|
||||||
m::close();
|
|
||||||
parent::tearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testAuthorizationUrl()
|
public function testAuthorizationUrl()
|
||||||
{
|
{
|
||||||
$url = $this->provider->getAuthorizationUrl();
|
$url = $this->provider->getAuthorizationUrl();
|
||||||
|
@ -48,11 +40,11 @@ class LinkedInTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testGetAccessToken()
|
public function testGetAccessToken()
|
||||||
{
|
{
|
||||||
$response = m::mock('GuzzleHttp\Message\Response');
|
$client = $this->createMockHttpClient();
|
||||||
$response->shouldReceive('getBody')->times(1)->andReturn('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
|
$response = $this->createMockResponse('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
|
||||||
|
|
||||||
$client = m::mock('GuzzleHttp\Client');
|
|
||||||
$client->shouldReceive('post')->times(1)->andReturn($response);
|
$client->shouldReceive('post')->times(1)->andReturn($response);
|
||||||
|
|
||||||
$this->provider->setHttpClient($client);
|
$this->provider->setHttpClient($client);
|
||||||
|
|
||||||
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
||||||
|
@ -73,15 +65,14 @@ class LinkedInTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testUserData()
|
public function testUserData()
|
||||||
{
|
{
|
||||||
$postResponse = m::mock('GuzzleHttp\Message\Response');
|
$client = $this->createMockHttpClient();
|
||||||
$postResponse->shouldReceive('getBody')->times(1)->andReturn('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
|
|
||||||
|
|
||||||
$getResponse = m::mock('GuzzleHttp\Message\Response');
|
$postResponse = $this->createMockResponse('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
|
||||||
$getResponse->shouldReceive('getBody')->times(4)->andReturn('{"id": 12345, "firstName": "mock_first_name", "lastName": "mock_last_name", "emailAddress": "mock_email", "location": { "name": "mock_location" }, "headline": "mock_headline", "pictureUrl": "mock_picture_url", "publicProfileUrl": "mock_profile_url"}');
|
$getResponse = $this->createMockResponse('{"id": 12345, "firstName": "mock_first_name", "lastName": "mock_last_name", "emailAddress": "mock_email", "location": { "name": "mock_location" }, "headline": "mock_headline", "pictureUrl": "mock_picture_url", "publicProfileUrl": "mock_profile_url"}');
|
||||||
|
|
||||||
$client = m::mock('GuzzleHttp\Client');
|
|
||||||
$client->shouldReceive('post')->times(1)->andReturn($postResponse);
|
$client->shouldReceive('post')->times(1)->andReturn($postResponse);
|
||||||
$client->shouldReceive('get')->times(4)->andReturn($getResponse);
|
$client->shouldReceive('get')->times(4)->andReturn($getResponse);
|
||||||
|
|
||||||
$this->provider->setHttpClient($client);
|
$this->provider->setHttpClient($client);
|
||||||
|
|
||||||
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
||||||
|
|
|
@ -4,10 +4,8 @@ namespace League\OAuth2\Client\Test\Provider;
|
||||||
|
|
||||||
use Mockery as m;
|
use Mockery as m;
|
||||||
|
|
||||||
class MicrosoftTest extends \PHPUnit_Framework_TestCase
|
class MicrosoftTest extends ConcreteProviderTest
|
||||||
{
|
{
|
||||||
protected $provider;
|
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
$this->provider = new \League\OAuth2\Client\Provider\Microsoft([
|
$this->provider = new \League\OAuth2\Client\Provider\Microsoft([
|
||||||
|
@ -17,12 +15,6 @@ class MicrosoftTest extends \PHPUnit_Framework_TestCase
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
|
||||||
{
|
|
||||||
m::close();
|
|
||||||
parent::tearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testAuthorizationUrl()
|
public function testAuthorizationUrl()
|
||||||
{
|
{
|
||||||
$url = $this->provider->getAuthorizationUrl();
|
$url = $this->provider->getAuthorizationUrl();
|
||||||
|
@ -56,11 +48,11 @@ class MicrosoftTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testGetAccessToken()
|
public function testGetAccessToken()
|
||||||
{
|
{
|
||||||
$response = m::mock('GuzzleHttp\Message\Response');
|
$client = $this->createMockHttpClient();
|
||||||
$response->shouldReceive('getBody')->times(1)->andReturn('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
|
$response = $this->createMockResponse('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
|
||||||
|
|
||||||
$client = m::mock('GuzzleHttp\Client');
|
|
||||||
$client->shouldReceive('post')->times(1)->andReturn($response);
|
$client->shouldReceive('post')->times(1)->andReturn($response);
|
||||||
|
|
||||||
$this->provider->setHttpClient($client);
|
$this->provider->setHttpClient($client);
|
||||||
|
|
||||||
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
||||||
|
@ -81,18 +73,12 @@ class MicrosoftTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testUserData()
|
public function testUserData()
|
||||||
{
|
{
|
||||||
$postResponse = m::mock('GuzzleHttp\Message\Response');
|
$client = $this->createMockHttpClient();
|
||||||
$postResponse->shouldReceive('getBody')->times(1)->andReturn('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
|
$postResponse = $this->createMockResponse('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
|
||||||
|
$getResponse = $this->createMockResponse('{"id": 12345, "name": "mock_name", "first_name": "mock_first_name", "last_name": "mock_last_name", "emails": {"preferred": "mock_email"}, "link": "mock_link"}');
|
||||||
$getResponse = m::mock('GuzzleHttp\Message\Response');
|
$getResponse->shouldReceive('getHeader')->with('location')->andReturn('mock_image_url');
|
||||||
|
|
||||||
$getResponse->shouldReceive('getBody')->times(4)->andReturn('{"id": 12345, "name": "mock_name", "first_name": "mock_first_name", "last_name": "mock_last_name", "emails": {"preferred": "mock_email"}, "link": "mock_link"}');
|
|
||||||
$getResponse->shouldReceive('getInfo')->andReturn(['url' => 'mock_image_url']);
|
|
||||||
|
|
||||||
$client = m::mock('GuzzleHttp\Client');
|
|
||||||
$client->shouldReceive('post')->times(1)->andReturn($postResponse);
|
$client->shouldReceive('post')->times(1)->andReturn($postResponse);
|
||||||
$client->shouldReceive('get')->times(5)->andReturn($getResponse);
|
$client->shouldReceive('get')->times(5)->andReturn($getResponse);
|
||||||
|
|
||||||
$this->provider->setHttpClient($client);
|
$this->provider->setHttpClient($client);
|
||||||
|
|
||||||
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
||||||
|
|
|
@ -5,7 +5,7 @@ namespace League\OAuth2\Client\Test\Token;
|
||||||
class AccessTokenTest extends \PHPUnit_Framework_TestCase
|
class AccessTokenTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @expectedException InvalidArgumentException
|
* @expectedException \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function testInvalidRefreshToken()
|
public function testInvalidRefreshToken()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue