Merge remote-tracking branch 'origin/master' into teardown

Conflicts:
	test/src/Provider/MicrosoftTest.php
1.0
Jildert Miedema 2014-11-30 22:50:12 +01:00
commit 3384cb56c8
38 changed files with 521 additions and 182 deletions

View File

@ -13,7 +13,7 @@ before_script:
script:
- mkdir -p build/logs
- phpunit --coverage-text
- ./vendor/bin/phpunit --coverage-text
- ./vendor/bin/phpcs src --standard=psr2
after_script:

View File

@ -21,12 +21,22 @@ We accept contributions via Pull Requests on [Github](https://github.com/thephpl
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting.
- **Ensure tests pass!** - Please run the tests (see below) before submitting your pull request, and make sure they pass. We won't accept a patch until all tests pass.
- **Ensure no coding standards violations** - Please run PHP Code Sniffer using the PSR-2 standard (see below) before submitting your pull request. A violation will cause the build to fail, so please make sure there are no violations. We can't accept a patch if the build fails.
## Running Tests
``` bash
$ phpunit
$ ./vendor/bin/phpunit
```
## Running PHP Code Sniffer
``` bash
$ ./vendor/bin/phpcs src --standard=psr2 -sp
```
**Happy coding**!

View File

@ -124,8 +124,39 @@ below.
These providers allow integration with other providers not supported by `oauth2-client`. They may require an older version
so please help them out with a pull request if you notice this.
- [Battle.net](https://packagist.org/packages/depotwarehouse/oauth2-bnet)
- [QQ](https://github.com/tlikai/oauth2-client)
- [Weibo](https://github.com/tlikai/oauth2-client)
- [Meetup](https://github.com/howlowck/meetup-oauth2-provider)
### Implementing your own provider
If you are working with an oauth2 service not supported out-of-the-box or by an existing package, it is quite simple to
implement your own. Simply extend `League\OAuth2\Client\Provider\AbstractProvider` and implement the required abstract
methods:
```php
abstract public function urlAuthorize();
abstract public function urlAccessToken();
abstract public function urlUserDetails(\League\OAuth2\Client\Token\AccessToken $token);
abstract public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $token);
```
Each of these abstract methods contain a docblock defining their expectations and typical behaviour. Once you have
extended this class, you can simply follow the example above using your new `Provider`.
#### Custom account identifiers in access token responses
Some OAuth2 Server implementations include a field in their access token response defining some identifier
for the user account that just requested the access token. In many cases this field, if present, is called "uid", but
some providers define custom identifiers in their response. If your provider uses a nonstandard name for the "uid" field,
when extending the AbstractProvider, in your new class, define a property `public $uidKey` and set it equal to whatever
your provider uses as its key. For example, Battle.net uses `accountId` as the key for the identifier field, so in that
provider you would add a property:
```php
public $uidKey = 'accountId';
```
### Client Packages
@ -137,18 +168,14 @@ Some developers use this library as a base for their own PHP API wrappers, and t
Via Composer
``` json
{
"require": {
"league/oauth2-client": "~0.3"
}
}
``` bash
$ composer require league/oauth2-client
```
## Testing
``` bash
$ phpunit
$ ./vendor/bin/phpunit
```
## Contributing

View File

@ -41,7 +41,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "0.4-dev"
"dev-master": "0.5.x-dev"
}
}
}

View File

@ -52,7 +52,7 @@ class User
public function getArrayCopy()
{
return array(
return [
'uid' => $this->uid,
'nickname' => $this->nickname,
'name' => $this->name,
@ -65,7 +65,7 @@ class User
'urls' => $this->urls,
'gender' => $this->gender,
'locale' => $this->locale,
);
];
}
public function exchangeArray(array $data)

View File

@ -13,19 +13,13 @@ class IDPException extends \Exception
$code = isset($result['code']) ? $result['code'] : 0;
if (isset($result['error'])) {
// OAuth 2.0 Draft 10 style
$message = $result['error'];
} elseif (isset($result['message'])) {
// cURL style
$message = $result['message'];
} else {
$message = 'Unknown Error.';
}
parent::__construct($message, $code);
@ -34,7 +28,6 @@ class IDPException extends \Exception
public function getType()
{
if (isset($this->result['error'])) {
$message = $this->result['error'];
if (is_string($message)) {
@ -53,12 +46,12 @@ class IDPException extends \Exception
*/
public function __toString()
{
$str = $this->getType() . ': ';
$str = $this->getType().': ';
if ($this->code != 0) {
$str .= $this->code . ': ';
$str .= $this->code.': ';
}
return $str . $this->message;
return $str.$this->message;
}
}

View File

@ -20,7 +20,7 @@ class AuthorizationCode implements GrantInterface
return array_merge($defaultParams, $params);
}
public function handleResponse($response = array())
public function handleResponse($response = [])
{
return new AccessToken($response);
}

View File

@ -0,0 +1,25 @@
<?php
namespace League\OAuth2\Client\Grant;
use League\OAuth2\Client\Token\AccessToken;
class ClientCredentials implements GrantInterface
{
public function __toString()
{
return 'client_credentials';
}
public function prepRequestParams($defaultParams, $params)
{
$params['grant_type'] = 'client_credentials';
return array_merge($defaultParams, $params);
}
public function handleResponse($response = array())
{
return new AccessToken($response);
}
}

View File

@ -6,7 +6,7 @@ interface GrantInterface
{
public function __toString();
public function handleResponse($response = array());
public function handleResponse($response = []);
public function prepRequestParams($defaultParams, $params);
}

33
src/Grant/Password.php Normal file
View File

@ -0,0 +1,33 @@
<?php
namespace League\OAuth2\Client\Grant;
use League\OAuth2\Client\Token\AccessToken;
class Password implements GrantInterface
{
public function __toString()
{
return 'password';
}
public function prepRequestParams($defaultParams, $params)
{
if (! isset($params['username']) || empty($params['username'])) {
throw new \BadMethodCallException('Missing username');
}
if (! isset($params['password']) || empty($params['password'])) {
throw new \BadMethodCallException('Missing password');
}
$params['grant_type'] = 'password';
return array_merge($defaultParams, $params);
}
public function handleResponse($response = array())
{
return new AccessToken($response);
}
}

View File

@ -22,7 +22,7 @@ class RefreshToken implements GrantInterface
return array_merge($defaultParams, $params);
}
public function handleResponse($response = array())
public function handleResponse($response = [])
{
return new AccessToken($response);
}

View File

@ -2,11 +2,11 @@
namespace League\OAuth2\Client\Provider;
use Guzzle\Service\Client as GuzzleClient;
use Guzzle\Http\Exception\BadResponseException;
use League\OAuth2\Client\Token\AccessToken as AccessToken;
use Guzzle\Service\Client as GuzzleClient;
use League\OAuth2\Client\Exception\IDPException as IDPException;
use League\OAuth2\Client\Grant\GrantInterface;
use League\OAuth2\Client\Token\AccessToken as AccessToken;
abstract class AbstractProvider implements ProviderInterface
{
@ -22,7 +22,7 @@ abstract class AbstractProvider implements ProviderInterface
public $uidKey = 'uid';
public $scopes = array();
public $scopes = [];
public $method = 'post';
@ -40,15 +40,15 @@ abstract class AbstractProvider implements ProviderInterface
*/
protected $httpBuildEncType = 1;
public function __construct($options = array())
public function __construct($options = [])
{
foreach ($options as $option => $value) {
if (isset($this->{$option})) {
if (property_exists($this, $option)) {
$this->{$option} = $value;
}
}
$this->setHttpClient(new GuzzleClient);
$this->setHttpClient(new GuzzleClient());
}
public function setHttpClient(GuzzleClient $client)
@ -65,12 +65,41 @@ abstract class AbstractProvider implements ProviderInterface
return $client;
}
/**
* Get the URL that this provider uses to begin authorization.
*
* @return string
*/
abstract public function urlAuthorize();
/**
* Get the URL that this provider users to request an access token.
*
* @return string
*/
abstract public function urlAccessToken();
/**
* Get the URL that this provider uses to request user details.
*
* Since this URL is typically an authorized route, most providers will require you to pass the access_token as
* a parameter to the request. For example, the google url is:
*
* 'https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token='.$token
*
* @param AccessToken $token
* @return string
*/
abstract public function urlUserDetails(\League\OAuth2\Client\Token\AccessToken $token);
/**
* Given an object response from the server, process the user details into a format expected by the user
* of the client.
*
* @param object $response
* @param AccessToken $token
* @return mixed
*/
abstract public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $token);
public function getScopes()
@ -83,51 +112,51 @@ abstract class AbstractProvider implements ProviderInterface
$this->scopes = $scopes;
}
public function getAuthorizationUrl($options = array())
public function getAuthorizationUrl($options = [])
{
$this->state = md5(uniqid(rand(), true));
$this->state = isset($options['state']) ? $options['state'] : md5(uniqid(rand(), true));
$params = array(
$params = [
'client_id' => $this->clientId,
'redirect_uri' => $this->redirectUri,
'state' => $this->state,
'scope' => is_array($this->scopes) ? implode($this->scopeSeparator, $this->scopes) : $this->scopes,
'response_type' => isset($options['response_type']) ? $options['response_type'] : 'code',
'approval_prompt' => 'auto'
);
'approval_prompt' => 'auto',
];
return $this->urlAuthorize() . '?' . $this->httpBuildQuery($params, '', '&');
return $this->urlAuthorize().'?'.$this->httpBuildQuery($params, '', '&');
}
// @codeCoverageIgnoreStart
public function authorize($options = array())
public function authorize($options = [])
{
header('Location: ' . $this->getAuthorizationUrl($options));
header('Location: '.$this->getAuthorizationUrl($options));
exit;
}
// @codeCoverageIgnoreEnd
public function getAccessToken($grant = 'authorization_code', $params = array())
public function getAccessToken($grant = 'authorization_code', $params = [])
{
if (is_string($grant)) {
// PascalCase the grant. E.g: 'authorization_code' becomes 'AuthorizationCode'
$className = str_replace(' ', '', ucwords(str_replace(array('-', '_'), ' ', $grant)));
$className = str_replace(' ', '', ucwords(str_replace(['-', '_'], ' ', $grant)));
$grant = 'League\\OAuth2\\Client\\Grant\\'.$className;
if (! class_exists($grant)) {
throw new \InvalidArgumentException('Unknown grant "'.$grant.'"');
}
$grant = new $grant;
$grant = new $grant();
} elseif (! $grant instanceof GrantInterface) {
$message = get_class($grant).' is not an instance of League\OAuth2\Client\Grant\GrantInterface';
throw new \InvalidArgumentException($message);
}
$defaultParams = array(
$defaultParams = [
'client_id' => $this->clientId,
'client_secret' => $this->clientSecret,
'redirect_uri' => $this->redirectUri,
'grant_type' => $grant,
);
];
$requestParams = $grant->prepRequestParams($defaultParams, $params);
@ -137,7 +166,7 @@ abstract class AbstractProvider implements ProviderInterface
// @codeCoverageIgnoreStart
// No providers included with this library use get but 3rd parties may
$client = $this->getHttpClient();
$client->setBaseUrl($this->urlAccessToken() . '?' . $this->httpBuildQuery($requestParams, '', '&'));
$client->setBaseUrl($this->urlAccessToken().'?'.$this->httpBuildQuery($requestParams, '', '&'));
$request = $client->send();
$response = $request->getBody();
break;
@ -175,9 +204,29 @@ abstract class AbstractProvider implements ProviderInterface
// @codeCoverageIgnoreEnd
}
$this->setResultUid($result);
return $grant->handleResponse($result);
}
/**
* Sets any result keys we've received matching our provider-defined uidKey to the key "uid".
*
* @param array $result
*/
protected function setResultUid(array &$result)
{
// If we're operating with the default uidKey there's nothing to do.
if ($this->uidKey === "uid") {
return;
}
if (isset($result[$this->uidKey])) {
// The AccessToken expects a "uid" to have the key "uid".
$result['uid'] = $result[$this->uidKey];
}
}
public function getUserDetails(AccessToken $token)
{
$response = $this->fetchUserDetails($token);
@ -235,7 +284,6 @@ abstract class AbstractProvider implements ProviderInterface
$url = $this->urlUserDetails($token);
try {
$client = $this->getHttpClient();
$client->setBaseUrl($url);
@ -245,7 +293,6 @@ abstract class AbstractProvider implements ProviderInterface
$request = $client->get()->send();
$response = $request->getBody();
} catch (BadResponseException $e) {
// @codeCoverageIgnoreStart
$raw_response = explode("\n", $e->getResponse());

View File

@ -6,13 +6,12 @@ use League\OAuth2\Client\Entity\User;
class Eventbrite extends AbstractProvider
{
public function __construct($options)
{
parent::__construct($options);
$this->headers = array(
'Authorization' => 'Bearer'
);
$this->headers = [
'Authorization' => 'Bearer',
];
}
public function urlAuthorize()
@ -32,11 +31,11 @@ class Eventbrite extends AbstractProvider
public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $token)
{
$user = new User;
$user->exchangeArray(array(
$user = new User();
$user->exchangeArray([
'uid' => $response->user->user_id,
'email' => $response->user->email,
));
]);
return $user;
}

View File

@ -6,7 +6,7 @@ use League\OAuth2\Client\Entity\User;
class Facebook extends AbstractProvider
{
public $scopes = array('offline_access', 'email', 'read_stream');
public $scopes = ['offline_access', 'email', 'read_stream'];
public $responseType = 'string';
public function urlAuthorize()
@ -27,12 +27,12 @@ class Facebook extends AbstractProvider
public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $token)
{
$client = $this->getHttpClient();
$client->setBaseUrl('https://graph.facebook.com/me/picture?type=normal&access_token=' . $token->accessToken);
$client->setBaseUrl('https://graph.facebook.com/me/picture?type=normal&access_token='.$token->accessToken);
$request = $client->get()->send();
$info = $request->getInfo();
$imageUrl = $info['url'];
$user = new User;
$user = new User();
$username = (isset($response->username)) ? $response->username : null;
$email = (isset($response->email)) ? $response->email : null;
@ -40,7 +40,7 @@ class Facebook extends AbstractProvider
$description = (isset($response->bio)) ? $response->bio : null;
$imageUrl = ($imageUrl) ?: null;
$user->exchangeArray(array(
$user->exchangeArray([
'uid' => $response->id,
'nickname' => $username,
'name' => $response->name,
@ -50,8 +50,8 @@ class Facebook extends AbstractProvider
'location' => $location,
'description' => $description,
'imageurl' => $imageUrl,
'urls' => array( 'Facebook' => $response->link ),
));
'urls' => [ 'Facebook' => $response->link ],
]);
return $user;
}
@ -68,6 +68,6 @@ class Facebook extends AbstractProvider
public function userScreenName($response, \League\OAuth2\Client\Token\AccessToken $token)
{
return array($response->first_name, $response->last_name);
return [$response->first_name, $response->last_name];
}
}

View File

@ -25,20 +25,20 @@ class Github extends AbstractProvider
public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $token)
{
$user = new User;
$user = new User();
$name = (isset($response->name)) ? $response->name : null;
$email = (isset($response->email)) ? $response->email : null;
$user->exchangeArray(array(
$user->exchangeArray([
'uid' => $response->id,
'nickname' => $response->login,
'name' => $name,
'email' => $email,
'urls' =>array(
'GitHub' => 'http://github.com/' . $response->login,
),
));
'urls' => [
'GitHub' => 'http://github.com/'.$response->login,
],
]);
return $user;
}

View File

@ -8,10 +8,26 @@ class Google extends AbstractProvider
{
public $scopeSeparator = ' ';
public $scopes = array(
public $scopes = [
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email'
);
'https://www.googleapis.com/auth/userinfo.email',
];
/**
* @var string If set, this will be sent to google as the "hd" parameter.
* @link https://developers.google.com/accounts/docs/OAuth2Login#hd-param
*/
public $hostedDomain = '';
public function setHostedDomain($hd)
{
$this->hostedDomain = $hd;
}
public function getHostedDomain()
{
return $this->hostedDomain;
}
public function urlAuthorize()
{
@ -32,18 +48,18 @@ class Google extends AbstractProvider
{
$response = (array) $response;
$user = new User;
$user = new User();
$imageUrl = (isset($response['picture'])) ? $response['picture'] : null;
$user->exchangeArray(array(
$user->exchangeArray([
'uid' => $response['id'],
'name' => $response['name'],
'firstname' => $response['given_name'],
'lastName' => $response['family_name'],
'email' => $response['email'],
'imageUrl' => $imageUrl,
));
]);
return $user;
}
@ -60,6 +76,17 @@ class Google extends AbstractProvider
public function userScreenName($response, \League\OAuth2\Client\Token\AccessToken $token)
{
return array($response->given_name, $response->family_name);
return [$response->given_name, $response->family_name];
}
public function getAuthorizationUrl($options = array())
{
$url = parent::getAuthorizationUrl($options);
if (!empty($this->hostedDomain)) {
$url .= '&' . $this->httpBuildQuery(['hd' => $this->hostedDomain]);
}
return $url;
}
}

View File

@ -6,7 +6,7 @@ use League\OAuth2\Client\Entity\User;
class Instagram extends AbstractProvider
{
public $scopes = array('basic');
public $scopes = ['basic'];
public $responseType = 'json';
public function urlAuthorize()
@ -26,18 +26,17 @@ class Instagram extends AbstractProvider
public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $token)
{
$user = new User;
$user = new User();
$description = (isset($response->data->bio)) ? $response->data->bio : null;
$user->exchangeArray(array(
$user->exchangeArray([
'uid' => $response->data->id,
'nickname' => $response->data->username,
'name' => $response->data->full_name,
'description' => $description,
'imageUrl' => $response->data->profile_picture,
));
]);
return $user;
}

View File

@ -7,12 +7,12 @@ use League\OAuth2\Client\Token\AccessToken;
class LinkedIn extends AbstractProvider
{
public $scopes = array('r_basicprofile r_emailaddress r_contactinfo');
public $scopes = ['r_basicprofile r_emailaddress r_contactinfo'];
public $responseType = 'json';
public $fields = array(
public $fields = [
'id', 'email-address', 'first-name', 'last-name', 'headline',
'location', 'industry', 'picture-url', 'public-profile-url'
);
'location', 'industry', 'picture-url', 'public-profile-url',
];
public function urlAuthorize()
{
@ -26,29 +26,30 @@ class LinkedIn extends AbstractProvider
public function urlUserDetails(AccessToken $token)
{
return 'https://api.linkedin.com/v1/people/~:(' . implode(",", $this->fields)
. ')?format=json&oauth2_access_token=' . $token;
return 'https://api.linkedin.com/v1/people/~:('.implode(",", $this->fields)
.')?format=json&oauth2_access_token='.$token;
}
public function userDetails($response, AccessToken $token)
{
$user = new User;
$user = new User();
$email = (isset($response->emailAddress)) ? $response->emailAddress : null;
$location = (isset($response->location->name)) ? $response->location->name : null;
$description = (isset($response->headline)) ? $response->headline : null;
$pictureUrl = (isset($response->pictureUrl)) ? $response->pictureUrl : null;
$user->exchangeArray(array(
$user->exchangeArray([
'uid' => $response->id,
'name' => $response->firstName . ' ' . $response->lastName,
'name' => $response->firstName.' '.$response->lastName,
'firstname' => $response->firstName,
'lastname' => $response->lastName,
'email' => $email,
'location' => $location,
'description' => $description,
'imageurl' => $response->pictureUrl,
'imageurl' => $pictureUrl,
'urls' => $response->publicProfileUrl,
));
]);
return $user;
}
@ -67,6 +68,6 @@ class LinkedIn extends AbstractProvider
public function userScreenName($response, AccessToken $token)
{
return array($response->firstName, $response->lastName);
return [$response->firstName, $response->lastName];
}
}

View File

@ -7,7 +7,7 @@ use League\OAuth2\Client\Token\AccessToken;
class Microsoft extends AbstractProvider
{
public $scopes = array('wl.basic', 'wl.emails');
public $scopes = ['wl.basic', 'wl.emails'];
public $responseType = 'json';
public function urlAuthorize()
@ -28,24 +28,24 @@ class Microsoft extends AbstractProvider
public function userDetails($response, AccessToken $token)
{
$client = $this->getHttpClient();
$client->setBaseUrl('https://apis.live.net/v5.0/' . $response->id . '/picture');
$client->setBaseUrl('https://apis.live.net/v5.0/'.$response->id.'/picture');
$request = $client->get()->send();
$info = $request->getInfo();
$imageUrl = $info['url'];
$user = new User;
$user = new User();
$email = (isset($response->emails->preferred)) ? $response->emails->preferred : null;
$user->exchangeArray(array(
$user->exchangeArray([
'uid' => $response->id,
'name' => $response->name,
'firstname' => $response->first_name,
'lastname' => $response->last_name,
'email' => $email,
'imageurl' => $imageUrl,
'urls' => $response->link . '/cid-' . $response->id,
));
'urls' => $response->link.'/cid-'.$response->id,
]);
return $user;
}
@ -64,6 +64,6 @@ class Microsoft extends AbstractProvider
public function userScreenName($response, AccessToken $token)
{
return array($response->first_name, $response->last_name);
return [$response->first_name, $response->last_name];
}
}

View File

@ -18,11 +18,11 @@ interface ProviderInterface
public function setScopes(array $scopes);
public function getAuthorizationUrl($options = array());
public function getAuthorizationUrl($options = []);
public function authorize($options = array());
public function authorize($options = []);
public function getAccessToken($grant = 'authorization_code', $params = array());
public function getAccessToken($grant = 'authorization_code', $params = []);
public function getUserDetails(AccessToken $token);

View File

@ -7,7 +7,7 @@ use League\OAuth2\Client\Token\AccessToken;
class Vkontakte extends AbstractProvider
{
public $scopes = array();
public $scopes = [];
public $responseType = 'json';
public function urlAuthorize()
@ -22,7 +22,7 @@ class Vkontakte extends AbstractProvider
public function urlUserDetails(AccessToken $token)
{
$fields = array('nickname',
$fields = ['nickname',
'screen_name',
'sex',
'bdate',
@ -46,23 +46,23 @@ class Vkontakte extends AbstractProvider
'can_post',
'universities',
'schools',
'verified');
'verified', ];
return "https://api.vk.com/method/users.get?user_id={$token->uid}&fields="
. implode(",", $fields)."&access_token={$token}";
.implode(",", $fields)."&access_token={$token}";
}
public function userDetails($response, AccessToken $token)
{
$response = $response->response[0];
$user = new User;
$user = new User();
$email = (isset($response->email)) ? $response->email : null;
$location = (isset($response->country)) ? $response->country : null;
$description = (isset($response->status)) ? $response->status : null;
$user->exchangeArray(array(
$user->exchangeArray([
'uid' => $response->uid,
'nickname' => $response->nickname,
'name' => $response->screen_name,
@ -72,7 +72,7 @@ class Vkontakte extends AbstractProvider
'location' => $location,
'description' => $description,
'imageUrl' => $response->photo_200_orig,
));
]);
return $user;
}
@ -95,6 +95,6 @@ class Vkontakte extends AbstractProvider
{
$response = $response->response[0];
return array($response->first_name, $response->last_name);
return [$response->first_name, $response->last_name];
}
}

View File

@ -36,8 +36,8 @@ class AccessToken
{
if (! isset($options['access_token'])) {
throw new \InvalidArgumentException(
'Required option not passed: access_token'. PHP_EOL
. print_r($options, true)
'Required option not passed: access_token'.PHP_EOL
.print_r($options, true)
);
}
@ -52,6 +52,9 @@ class AccessToken
// Mailru uses x_mailru_vid instead of uid
isset($options['x_mailru_vid']) and $this->uid = $options['x_mailru_vid'];
//Battle.net uses accountId instead of uid
isset($options['accountId']) and $this->uid = $options['accountId'];
// We need to know when the token expires. Show preference to
// 'expires_in' since it is defined in RFC6749 Section 5.1.
// Defer to 'expires' if it is provided instead.

View File

@ -23,20 +23,22 @@ class Bootstrap
{
$vendorPath = static::findParentPath('vendor');
$loader = include $vendorPath . '/autoload.php';
$loader = include $vendorPath.'/autoload.php';
}
protected static function findParentPath($path)
{
$dir = __DIR__;
$previousDir = '.';
while (!is_dir($dir . '/' . $path)) {
while (!is_dir($dir.'/'.$path)) {
$dir = dirname($dir);
if ($previousDir === $dir) return false;
if ($previousDir === $dir) {
return false;
}
$previousDir = $dir;
}
return $dir . '/' . $path;
return $dir.'/'.$path;
}
}

View File

@ -12,9 +12,9 @@ class UserTest extends \PHPUnit_Framework_TestCase
public function setUp()
{
$this->user = new User;
$this->user = new User();
$this->userArray = array(
$this->userArray = [
'uid' => 'mock_uid',
'nickname' => 'mock_nickname',
'name' => 'mock_name',
@ -26,8 +26,8 @@ class UserTest extends \PHPUnit_Framework_TestCase
'imageUrl' => 'mock_imageUrl',
'urls' => 'mock_urls',
'gender' => 'mock_gender',
'locale' => 'mock_locale'
);
'locale' => 'mock_locale',
];
}
public function testExchangeArrayGetArrayCopy()

View File

@ -10,11 +10,11 @@ class AuthorizationCodeTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->provider = new \League\OAuth2\Client\Provider\Google(array(
$this->provider = new \League\OAuth2\Client\Provider\Google([
'clientId' => 'mock_client_id',
'clientSecret' => 'mock_secret',
'redirectUri' => 'none',
));
]);
}
public function tearDown()
@ -42,6 +42,6 @@ class AuthorizationCodeTest extends \PHPUnit_Framework_TestCase
$client->shouldReceive('post->send')->times(0)->andReturn($response);
$this->provider->setHttpClient($client);
$this->provider->getAccessToken('authorization_code', array('invalid_code' => 'mock_authorization_code'));
$this->provider->getAccessToken('authorization_code', ['invalid_code' => 'mock_authorization_code']);
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace League\OAuth2\Client\Test\Grant;
use \Mockery as m;
class ClientCredentialsTest extends \PHPUnit_Framework_TestCase
{
protected $provider;
protected function setUp()
{
$this->provider = new \League\OAuth2\Client\Provider\Google(array(
'clientId' => 'mock_client_id',
'clientSecret' => 'mock_secret',
'redirectUri' => 'none',
));
}
public function testGetAccessToken()
{
$response = m::mock('Guzzle\Http\Message\Response');
$response->shouldReceive('getBody')->times(2)->andReturn('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
$client = m::mock('Guzzle\Service\Client');
$client->shouldReceive('setBaseUrl')->times(1);
$client->shouldReceive('post->send')->times(1)->andReturn($response);
$this->provider->setHttpClient($client);
$token = $this->provider->getAccessToken('client_credentials');
$this->assertInstanceOf('League\OAuth2\Client\Token\AccessToken', $token);
$grant = new \League\OAuth2\Client\Grant\ClientCredentials();
$this->assertEquals('client_credentials', (string) $grant);
}
}

View File

@ -0,0 +1,68 @@
<?php
namespace League\OAuth2\Client\Test\Grant;
use \Mockery as m;
class PasswordTest extends \PHPUnit_Framework_TestCase
{
protected $provider;
protected function setUp()
{
$this->provider = new \League\OAuth2\Client\Provider\Google(array(
'clientId' => 'mock_client_id',
'clientSecret' => 'mock_secret',
'redirectUri' => 'none',
));
}
public function testGetAccessToken()
{
$response = m::mock('Guzzle\Http\Message\Response');
$response->shouldReceive('getBody')->times(2)->andReturn('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
$client = m::mock('Guzzle\Service\Client');
$client->shouldReceive('setBaseUrl')->times(1);
$client->shouldReceive('post->send')->times(1)->andReturn($response);
$this->provider->setHttpClient($client);
$token = $this->provider->getAccessToken('password', array('username' => 'mock_username', 'password' => 'mock_password'));
$this->assertInstanceOf('League\OAuth2\Client\Token\AccessToken', $token);
$grant = new \League\OAuth2\Client\Grant\Password();
$this->assertEquals('password', (string) $grant);
}
/**
* @expectedException BadMethodCallException
*/
public function testInvalidUsername()
{
$response = m::mock('Guzzle\Http\Message\Response');
$response->shouldReceive('getBody')->times(2)->andReturn('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
$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->getAccessToken('password', array('invalid_username' => 'mock_username', 'password' => 'mock_password'));
}
/**
* @expectedException BadMethodCallException
*/
public function testInvalidPassword()
{
$response = m::mock('Guzzle\Http\Message\Response');
$response->shouldReceive('getBody')->times(2)->andReturn('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
$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->getAccessToken('password', array('username' => 'mock_username', 'invalid_password' => 'mock_password'));
}
}

View File

@ -10,11 +10,11 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->provider = new \League\OAuth2\Client\Provider\Google(array(
$this->provider = new \League\OAuth2\Client\Provider\Google([
'clientId' => 'mock_client_id',
'clientSecret' => 'mock_secret',
'redirectUri' => 'none',
));
]);
}
public function tearDown()
@ -33,13 +33,13 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
$client->shouldReceive('post->send')->times(2)->andReturn($response);
$this->provider->setHttpClient($client);
$token = $this->provider->getAccessToken('authorization_code', array('code' => 'mock_authorization_code'));
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
$this->assertInstanceOf('League\OAuth2\Client\Token\AccessToken', $token);
$grant = new \League\OAuth2\Client\Grant\RefreshToken();
$this->assertEquals('refresh_token', (string) $grant);
$newToken = $this->provider->getAccessToken($grant, array('refresh_token' => $token->refreshToken));
$newToken = $this->provider->getAccessToken($grant, ['refresh_token' => $token->refreshToken]);
$this->assertInstanceOf('League\OAuth2\Client\Token\AccessToken', $newToken);
}
@ -56,9 +56,9 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
$client->shouldReceive('post->send')->times(1)->andReturn($response);
$this->provider->setHttpClient($client);
$token = $this->provider->getAccessToken('authorization_code', array('code' => 'mock_authorization_code'));
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
$grant = new \League\OAuth2\Client\Grant\RefreshToken();
$refreshToken = $this->provider->getAccessToken($grant, array('invalid_refresh_token' => $token->refreshToken));
$refreshToken = $this->provider->getAccessToken($grant, ['invalid_refresh_token' => $token->refreshToken]);
}
}

View File

@ -2,7 +2,6 @@
namespace League\OAuth2\Client\Test\Provider;
use \Mockery as m;
class AbstractProviderTest extends \PHPUnit_Framework_TestCase
{
@ -10,11 +9,11 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->provider = new \League\OAuth2\Client\Provider\Google(array(
$this->provider = new \League\OAuth2\Client\Provider\Google([
'clientId' => 'mock_client_id',
'clientSecret' => 'mock_secret',
'redirectUri' => 'none',
));
]);
}
public function tearDown()
@ -28,7 +27,7 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase
*/
public function testInvalidGrantString()
{
$this->provider->getAccessToken('invalid_grant', array('invalid_parameter' => 'none'));
$this->provider->getAccessToken('invalid_grant', ['invalid_parameter' => 'none']);
}
/**
@ -36,7 +35,63 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase
*/
public function testInvalidGrantObject()
{
$grant = new \StdClass;
$this->provider->getAccessToken($grant, array('invalid_parameter' => 'none'));
$grant = new \StdClass();
$this->provider->getAccessToken($grant, ['invalid_parameter' => 'none']);
}
public function testAuthorizationUrlStateParam()
{
$this->assertContains('state=XXX', $this->provider->getAuthorizationUrl([
'state' => 'XXX'
]));
}
/**
* Tests https://github.com/thephpleague/oauth2-client/issues/134
*/
public function testConstructorSetsProperties()
{
$options = [
'clientId' => '1234',
'clientSecret' => '4567',
'redirectUri' => 'http://example.org/redirect',
'state' => 'foo',
'name' => 'bar',
'uidKey' => 'mynewuid',
'scopes' => ['a', 'b', 'c'],
'method' => 'get',
'scopeSeparator' => ';',
'responseType' => 'csv',
'headers' => ['Foo' => 'Bar'],
];
$mockProvider = new MockProvider($options);
foreach ($options as $key => $value) {
$this->assertEquals($value, $mockProvider->{$key});
}
}
}
class MockProvider extends \League\OAuth2\Client\Provider\AbstractProvider
{
public function urlAuthorize()
{
return '';
}
public function urlAccessToken()
{
return '';
}
public function urlUserDetails(\League\OAuth2\Client\Token\AccessToken $token)
{
return '';
}
public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $token)
{
return '';
}
}

View File

@ -10,11 +10,11 @@ class EventbriteTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->provider = new \League\OAuth2\Client\Provider\Eventbrite(array(
$this->provider = new \League\OAuth2\Client\Provider\Eventbrite([
'clientId' => 'mock_client_id',
'clientSecret' => 'mock_secret',
'redirectUri' => 'none',
));
]);
}
public function tearDown()
@ -56,7 +56,7 @@ class EventbriteTest extends \PHPUnit_Framework_TestCase
$client->shouldReceive('post->send')->times(1)->andReturn($response);
$this->provider->setHttpClient($client);
$token = $this->provider->getAccessToken('authorization_code', array('code' => 'mock_authorization_code'));
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
$this->assertEquals('mock_access_token', $token->accessToken);
$this->assertLessThanOrEqual(time() + 3600, $token->expires);
@ -67,7 +67,7 @@ class EventbriteTest extends \PHPUnit_Framework_TestCase
public function testScopes()
{
$this->assertEquals(array(), $this->provider->getScopes());
$this->assertEquals([], $this->provider->getScopes());
}
public function testUserData()
@ -85,7 +85,7 @@ class EventbriteTest extends \PHPUnit_Framework_TestCase
$client->shouldReceive('setDefaultOption')->times(4);
$this->provider->setHttpClient($client);
$token = $this->provider->getAccessToken('authorization_code', array('code' => 'mock_authorization_code'));
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
$user = $this->provider->getUserDetails($token);
$this->assertEquals(12345, $this->provider->getUserUid($token));

View File

@ -10,11 +10,11 @@ class FacebookTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->provider = new \League\OAuth2\Client\Provider\Facebook(array(
$this->provider = new \League\OAuth2\Client\Provider\Facebook([
'clientId' => 'mock_client_id',
'clientSecret' => 'mock_secret',
'redirectUri' => 'none',
));
]);
}
public function tearDown()
@ -56,7 +56,7 @@ class FacebookTest extends \PHPUnit_Framework_TestCase
$client->shouldReceive('post->send')->times(1)->andReturn($response);
$this->provider->setHttpClient($client);
$token = $this->provider->getAccessToken('authorization_code', array('code' => 'mock_authorization_code'));
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
# print_r($token);die();
@ -69,7 +69,7 @@ class FacebookTest extends \PHPUnit_Framework_TestCase
public function testScopes()
{
$this->assertEquals(array('offline_access', 'email', 'read_stream'), $this->provider->getScopes());
$this->assertEquals(['offline_access', 'email', 'read_stream'], $this->provider->getScopes());
}
public function testUserData()
@ -79,7 +79,7 @@ class FacebookTest extends \PHPUnit_Framework_TestCase
$getResponse = m::mock('Guzzle\Http\Message\Response');
$getResponse->shouldReceive('getBody')->andReturn('{"id": 12345, "name": "mock_name", "username": "mock_username", "first_name": "mock_first_name", "last_name": "mock_last_name", "email": "mock_email", "Location": "mock_home", "bio": "mock_description", "link": "mock_facebook_url"}');
$getResponse->shouldReceive('getInfo')->andReturn(array('url' => 'mock_image_url'));
$getResponse->shouldReceive('getInfo')->andReturn(['url' => 'mock_image_url']);
$client = m::mock('Guzzle\Service\Client');
$client->shouldReceive('setBaseUrl')->times(6);
@ -87,11 +87,11 @@ class FacebookTest extends \PHPUnit_Framework_TestCase
$client->shouldReceive('get->send')->andReturn($getResponse);
$this->provider->setHttpClient($client);
$token = $this->provider->getAccessToken('authorization_code', array('code' => 'mock_authorization_code'));
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
$user = $this->provider->getUserDetails($token);
$this->assertEquals(12345, $this->provider->getUserUid($token));
$this->assertEquals(array('mock_first_name', 'mock_last_name'), $this->provider->getUserScreenName($token));
$this->assertEquals(['mock_first_name', 'mock_last_name'], $this->provider->getUserScreenName($token));
$this->assertEquals('mock_email', $this->provider->getUserEmail($token));
$this->assertEquals('mock_email', $user->email);
}

View File

@ -10,11 +10,11 @@ class GithubTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->provider = new \League\OAuth2\Client\Provider\Github(array(
$this->provider = new \League\OAuth2\Client\Provider\Github([
'clientId' => 'mock',
'clientSecret' => 'mock_secret',
'redirectUri' => 'none',
));
]);
}
public function tearDown()
@ -56,7 +56,7 @@ class GithubTest extends \PHPUnit_Framework_TestCase
$client->shouldReceive('post->send')->times(1)->andReturn($response);
$this->provider->setHttpClient($client);
$token = $this->provider->getAccessToken('authorization_code', array('code' => 'mock_authorization_code'));
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
$this->assertEquals('mock_access_token', $token->accessToken);
$this->assertLessThanOrEqual(time() + 3600, $token->expires);
@ -67,8 +67,8 @@ class GithubTest extends \PHPUnit_Framework_TestCase
public function testScopes()
{
$this->provider->setScopes(array('user', 'repo'));
$this->assertEquals(array('user', 'repo'), $this->provider->getScopes());
$this->provider->setScopes(['user', 'repo']);
$this->assertEquals(['user', 'repo'], $this->provider->getScopes());
}
public function testUserData()
@ -85,7 +85,7 @@ class GithubTest extends \PHPUnit_Framework_TestCase
$client->shouldReceive('get->send')->times(4)->andReturn($getResponse);
$this->provider->setHttpClient($client);
$token = $this->provider->getAccessToken('authorization_code', array('code' => 'mock_authorization_code'));
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
$user = $this->provider->getUserDetails($token);
$this->assertEquals(12345, $this->provider->getUserUid($token));

View File

@ -10,11 +10,12 @@ class GoogleTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->provider = new \League\OAuth2\Client\Provider\Google(array(
$this->provider = new \League\OAuth2\Client\Provider\Google([
'clientId' => 'mock_client_id',
'clientSecret' => 'mock_secret',
'redirectUri' => 'none',
));
'hostedDomain' => 'mock_domain',
]);
}
public function tearDown()
@ -35,6 +36,7 @@ class GoogleTest extends \PHPUnit_Framework_TestCase
$this->assertArrayHasKey('scope', $query);
$this->assertArrayHasKey('response_type', $query);
$this->assertArrayHasKey('approval_prompt', $query);
$this->assertArrayHasKey('hd', $query);
$this->assertNotNull($this->provider->state);
}
@ -56,7 +58,7 @@ class GoogleTest extends \PHPUnit_Framework_TestCase
$client->shouldReceive('post->send')->times(1)->andReturn($response);
$this->provider->setHttpClient($client);
$token = $this->provider->getAccessToken('authorization_code', array('code' => 'mock_authorization_code'));
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
# print_r($token);die();
@ -69,7 +71,7 @@ class GoogleTest extends \PHPUnit_Framework_TestCase
public function testScopes()
{
$this->assertEquals(array('https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/userinfo.email'), $this->provider->getScopes());
$this->assertEquals(['https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/userinfo.email'], $this->provider->getScopes());
}
public function testUserData()
@ -86,12 +88,23 @@ class GoogleTest extends \PHPUnit_Framework_TestCase
$client->shouldReceive('get->send')->times(4)->andReturn($getResponse);
$this->provider->setHttpClient($client);
$token = $this->provider->getAccessToken('authorization_code', array('code' => 'mock_authorization_code'));
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
$user = $this->provider->getUserDetails($token);
$this->assertEquals(12345, $this->provider->getUserUid($token));
$this->assertEquals(array('mock_first_name', 'mock_last_name'), $this->provider->getUserScreenName($token));
$this->assertEquals(['mock_first_name', 'mock_last_name'], $this->provider->getUserScreenName($token));
$this->assertEquals('mock_email', $this->provider->getUserEmail($token));
$this->assertEquals('mock_email', $user->email);
}
public function testGetHostedDomain()
{
$this->assertEquals('mock_domain', $this->provider->getHostedDomain());
}
public function testSetHostedDomain()
{
$this->provider->setHostedDomain('changed_domain');
$this->assertEquals('changed_domain', $this->provider->hostedDomain);
}
}

View File

@ -10,11 +10,11 @@ class InstagramTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->provider = new \League\OAuth2\Client\Provider\Instagram(array(
$this->provider = new \League\OAuth2\Client\Provider\Instagram([
'clientId' => 'mock_client_id',
'clientSecret' => 'mock_secret',
'redirectUri' => 'none',
));
]);
}
public function tearDown()
@ -56,7 +56,7 @@ class InstagramTest extends \PHPUnit_Framework_TestCase
$client->shouldReceive('post->send')->times(1)->andReturn($response);
$this->provider->setHttpClient($client);
$token = $this->provider->getAccessToken('authorization_code', array('code' => 'mock_authorization_code'));
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
# print_r($token);die();
@ -69,7 +69,7 @@ class InstagramTest extends \PHPUnit_Framework_TestCase
public function testScopes()
{
$this->assertEquals(array('basic'), $this->provider->getScopes());
$this->assertEquals(['basic'], $this->provider->getScopes());
}
public function testUserData()
@ -86,7 +86,7 @@ class InstagramTest extends \PHPUnit_Framework_TestCase
$client->shouldReceive('get->send')->times(4)->andReturn($getResponse);
$this->provider->setHttpClient($client);
$token = $this->provider->getAccessToken('authorization_code', array('code' => 'mock_authorization_code'));
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
$user = $this->provider->getUserDetails($token);
$this->assertEquals(12345, $this->provider->getUserUid($token));

View File

@ -10,11 +10,11 @@ class LinkedInTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->provider = new \League\OAuth2\Client\Provider\LinkedIn(array(
$this->provider = new \League\OAuth2\Client\Provider\LinkedIn([
'clientId' => 'mock_client_id',
'clientSecret' => 'mock_secret',
'redirectUri' => 'none',
));
]);
}
public function tearDown()
@ -56,7 +56,7 @@ class LinkedInTest extends \PHPUnit_Framework_TestCase
$client->shouldReceive('post->send')->times(1)->andReturn($response);
$this->provider->setHttpClient($client);
$token = $this->provider->getAccessToken('authorization_code', array('code' => 'mock_authorization_code'));
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
# print_r($token);die();
@ -69,7 +69,7 @@ class LinkedInTest extends \PHPUnit_Framework_TestCase
public function testScopes()
{
$this->assertEquals(array('r_basicprofile r_emailaddress r_contactinfo'), $this->provider->getScopes());
$this->assertEquals(['r_basicprofile r_emailaddress r_contactinfo'], $this->provider->getScopes());
}
public function testUserData()
@ -86,11 +86,11 @@ class LinkedInTest extends \PHPUnit_Framework_TestCase
$client->shouldReceive('get->send')->times(4)->andReturn($getResponse);
$this->provider->setHttpClient($client);
$token = $this->provider->getAccessToken('authorization_code', array('code' => 'mock_authorization_code'));
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
$user = $this->provider->getUserDetails($token);
$this->assertEquals(12345, $this->provider->getUserUid($token));
$this->assertEquals(array('mock_first_name', 'mock_last_name'), $this->provider->getUserScreenName($token));
$this->assertEquals(['mock_first_name', 'mock_last_name'], $this->provider->getUserScreenName($token));
$this->assertEquals('mock_email', $this->provider->getUserEmail($token));
$this->assertEquals('mock_email', $user->email);
}

View File

@ -10,11 +10,11 @@ class MicrosoftTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->provider = new \League\OAuth2\Client\Provider\Microsoft(array(
$this->provider = new \League\OAuth2\Client\Provider\Microsoft([
'clientId' => 'mock_client_id',
'clientSecret' => 'mock_secret',
'redirectUri' => 'none',
));
]);
}
public function tearDown()
@ -56,7 +56,7 @@ class MicrosoftTest extends \PHPUnit_Framework_TestCase
$client->shouldReceive('post->send')->times(1)->andReturn($response);
$this->provider->setHttpClient($client);
$token = $this->provider->getAccessToken('authorization_code', array('code' => 'mock_authorization_code'));
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
# print_r($token);die();
@ -69,7 +69,7 @@ class MicrosoftTest extends \PHPUnit_Framework_TestCase
public function testScopes()
{
$this->assertEquals(array('wl.basic', 'wl.emails'), $this->provider->getScopes());
$this->assertEquals(['wl.basic', 'wl.emails'], $this->provider->getScopes());
}
public function testUserData()
@ -78,6 +78,7 @@ class MicrosoftTest extends \PHPUnit_Framework_TestCase
$postResponse->shouldReceive('getBody')->times(1)->andReturn('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}');
$getResponse = m::mock('Guzzle\Http\Message\Response');
$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(array('url' => 'mock_image_url'));
@ -87,11 +88,11 @@ class MicrosoftTest extends \PHPUnit_Framework_TestCase
$client->shouldReceive('get->send')->times(5)->andReturn($getResponse);
$this->provider->setHttpClient($client);
$token = $this->provider->getAccessToken('authorization_code', array('code' => 'mock_authorization_code'));
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
$user = $this->provider->getUserDetails($token);
$this->assertEquals(12345, $this->provider->getUserUid($token));
$this->assertEquals(array('mock_first_name', 'mock_last_name'), $this->provider->getUserScreenName($token));
$this->assertEquals(['mock_first_name', 'mock_last_name'], $this->provider->getUserScreenName($token));
$this->assertEquals('mock_email', $this->provider->getUserEmail($token));
$this->assertEquals('mock_email', $user->email);
$this->assertEquals('mock_image_url', $user->imageUrl);

View File

@ -10,11 +10,11 @@ class VkontakteTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->provider = new \League\OAuth2\Client\Provider\Vkontakte(array(
$this->provider = new \League\OAuth2\Client\Provider\Vkontakte([
'clientId' => 'mock_client_id',
'clientSecret' => 'mock_secret',
'redirectUri' => 'none',
));
]);
}
public function tearDown()
@ -56,7 +56,7 @@ class VkontakteTest extends \PHPUnit_Framework_TestCase
$client->shouldReceive('post->send')->times(1)->andReturn($response);
$this->provider->setHttpClient($client);
$token = $this->provider->getAccessToken('authorization_code', array('code' => 'mock_authorization_code'));
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
$this->assertEquals('mock_access_token', $token->accessToken);
$this->assertLessThanOrEqual(time() + 3600, $token->expires);
@ -67,7 +67,7 @@ class VkontakteTest extends \PHPUnit_Framework_TestCase
public function testScopes()
{
$this->assertEquals(array(), $this->provider->getScopes());
$this->assertEquals([], $this->provider->getScopes());
}
public function testUserData()
@ -84,11 +84,11 @@ class VkontakteTest extends \PHPUnit_Framework_TestCase
$client->shouldReceive('get->send')->times(4)->andReturn($getResponse);
$this->provider->setHttpClient($client);
$token = $this->provider->getAccessToken('authorization_code', array('code' => 'mock_authorization_code'));
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
$user = $this->provider->getUserDetails($token);
$this->assertEquals(12345, $this->provider->getUserUid($token));
$this->assertEquals(array('mock_first_name', 'mock_last_name'), $this->provider->getUserScreenName($token));
$this->assertEquals(['mock_first_name', 'mock_last_name'], $this->provider->getUserScreenName($token));
$this->assertEquals('mock_email', $this->provider->getUserEmail($token));
$this->assertEquals('mock_email', $user->email);
}

View File

@ -9,7 +9,7 @@ class AccessTokenTest extends \PHPUnit_Framework_TestCase
*/
public function testInvalidRefreshToken()
{
new \League\OAuth2\Client\Token\AccessToken(array('invalid_access_token' => 'none'));
new \League\OAuth2\Client\Token\AccessToken(['invalid_access_token' => 'none']);
}
public function testExpiresInCorrection()