mirror of
https://github.com/elyby/league-oauth2-ely.git
synced 2024-11-26 16:52:03 +05:30
Cleanup tests. Try to fix builds. Include composer.lock.
This commit is contained in:
parent
9b14a1d427
commit
1b4de783ff
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,7 +2,6 @@
|
|||||||
/build
|
/build
|
||||||
/vendor
|
/vendor
|
||||||
composer.phar
|
composer.phar
|
||||||
composer.lock
|
|
||||||
.php_cs.cache
|
.php_cs.cache
|
||||||
.php_cs
|
.php_cs
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
@ -5,6 +5,7 @@ php:
|
|||||||
- 7.0
|
- 7.0
|
||||||
- 7.1
|
- 7.1
|
||||||
- 7.2
|
- 7.2
|
||||||
|
- 7.3
|
||||||
- nightly
|
- nightly
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
@ -21,6 +22,7 @@ env:
|
|||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- composer global show hirak/prestissimo -q || travis_retry composer global require $DEFAULT_COMPOSER_FLAGS hirak/prestissimo
|
- composer global show hirak/prestissimo -q || travis_retry composer global require $DEFAULT_COMPOSER_FLAGS hirak/prestissimo
|
||||||
|
- '[ "${TRAVIS_PHP_VERSION:0:1}" == "5" ] && composer remove ely/php-code-style'
|
||||||
- travis_retry composer update --no-interaction --prefer-source $PREFER_LOWEST
|
- travis_retry composer update --no-interaction --prefer-source $PREFER_LOWEST
|
||||||
- travis_retry phpenv rehash
|
- travis_retry phpenv rehash
|
||||||
|
|
||||||
|
@ -19,9 +19,9 @@
|
|||||||
"league/oauth2-client": "^1.0 | ^2.0"
|
"league/oauth2-client": "^1.0 | ^2.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^4.8 || ^5.0",
|
"ext-json": "*",
|
||||||
"mockery/mockery": "~0.9",
|
"phpunit/phpunit": "^4.8",
|
||||||
"ely/php-code-style": "^0.2.0"
|
"ely/php-code-style": "^0.3.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
2684
composer.lock
generated
Normal file
2684
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,19 +1,28 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/** @noinspection PhpUnhandledExceptionInspection */
|
||||||
namespace Ely\OAuth2\Client\Test;
|
namespace Ely\OAuth2\Client\Test;
|
||||||
|
|
||||||
|
use Ely\OAuth2\Client\Exception\IdentityProviderException;
|
||||||
use Ely\OAuth2\Client\Provider;
|
use Ely\OAuth2\Client\Provider;
|
||||||
use Ely\OAuth2\Client\ResourceOwner;
|
use Ely\OAuth2\Client\ResourceOwner;
|
||||||
use GuzzleHttp\ClientInterface;
|
use GuzzleHttp\Client;
|
||||||
|
use GuzzleHttp\Handler\MockHandler;
|
||||||
|
use GuzzleHttp\HandlerStack;
|
||||||
|
use GuzzleHttp\Psr7\Response;
|
||||||
use League\OAuth2\Client\Token\AccessToken;
|
use League\OAuth2\Client\Token\AccessToken;
|
||||||
use Mockery as m;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
|
||||||
|
|
||||||
class ProviderTest extends \PHPUnit_Framework_TestCase {
|
class ProviderTest extends TestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Provider
|
* @var Provider
|
||||||
*/
|
*/
|
||||||
protected $provider;
|
private $provider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var MockHandler
|
||||||
|
*/
|
||||||
|
private $mockHandler;
|
||||||
|
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
$this->provider = new Provider([
|
$this->provider = new Provider([
|
||||||
@ -21,17 +30,14 @@ class ProviderTest extends \PHPUnit_Framework_TestCase {
|
|||||||
'clientSecret' => 'mock_secret',
|
'clientSecret' => 'mock_secret',
|
||||||
'redirectUri' => 'none',
|
'redirectUri' => 'none',
|
||||||
]);
|
]);
|
||||||
}
|
$this->mockHandler = new MockHandler();
|
||||||
|
$client = new Client(['handler' => HandlerStack::create($this->mockHandler)]);
|
||||||
public function tearDown() {
|
$this->provider->setHttpClient($client);
|
||||||
m::close();
|
|
||||||
parent::tearDown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetResourceOwnerDetailsUrl() {
|
public function testGetResourceOwnerDetailsUrl() {
|
||||||
$url = $this->provider->getResourceOwnerDetailsUrl(new AccessToken(['access_token' => 'mock_token']));
|
$url = $this->provider->getResourceOwnerDetailsUrl(new AccessToken(['access_token' => 'mock_token']));
|
||||||
$uri = parse_url($url);
|
$this->assertSame('/api/account/v1/info', parse_url($url, PHP_URL_PATH));
|
||||||
$this->assertEquals('/api/account/v1/info', $uri['path']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetAuthorizationUrl() {
|
public function testGetAuthorizationUrl() {
|
||||||
@ -39,7 +45,7 @@ class ProviderTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$uri = parse_url($url);
|
$uri = parse_url($url);
|
||||||
parse_str($uri['query'], $query);
|
parse_str($uri['query'], $query);
|
||||||
|
|
||||||
$this->assertEquals('/oauth2/v1/mock_client_id', $uri['path']);
|
$this->assertSame('/oauth2/v1/mock_client_id', $uri['path']);
|
||||||
$this->assertArrayNotHasKey('client_id', $query);
|
$this->assertArrayNotHasKey('client_id', $query);
|
||||||
$this->assertArrayHasKey('redirect_uri', $query);
|
$this->assertArrayHasKey('redirect_uri', $query);
|
||||||
$this->assertArrayHasKey('state', $query);
|
$this->assertArrayHasKey('state', $query);
|
||||||
@ -51,115 +57,64 @@ class ProviderTest extends \PHPUnit_Framework_TestCase {
|
|||||||
|
|
||||||
public function testScopes() {
|
public function testScopes() {
|
||||||
$options = ['scope' => ['minecraft_server_session', 'account_info']];
|
$options = ['scope' => ['minecraft_server_session', 'account_info']];
|
||||||
|
|
||||||
$url = $this->provider->getAuthorizationUrl($options);
|
$url = $this->provider->getAuthorizationUrl($options);
|
||||||
|
$this->assertContains('scope=minecraft_server_session%2Caccount_info', $url);
|
||||||
$this->assertContains(urlencode(implode(',', $options['scope'])), $url);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetBaseAccessTokenUrl() {
|
public function testGetBaseAccessTokenUrl() {
|
||||||
$params = [];
|
$url = $this->provider->getBaseAccessTokenUrl([]);
|
||||||
|
$this->assertSame('/api/oauth2/v1/token', parse_url($url, PHP_URL_PATH));
|
||||||
$url = $this->provider->getBaseAccessTokenUrl($params);
|
|
||||||
$uri = parse_url($url);
|
|
||||||
|
|
||||||
$this->assertEquals('/api/oauth2/v1/token', $uri['path']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetAccessToken() {
|
public function testGetAccessToken() {
|
||||||
/** @var m\Mock|ResponseInterface $response */
|
$this->mockHandler->append(new Response(200, ['content-type' => 'json'], $this->getAccessTokenResponse()));
|
||||||
$response = m::mock(ResponseInterface::class);
|
|
||||||
$response->shouldReceive('getBody')->andReturn($this->getAccessTokenResponse());
|
|
||||||
$response->shouldReceive('getHeader')->andReturn(['content-type' => 'json']);
|
|
||||||
$response->shouldReceive('getStatusCode')->andReturn(200);
|
|
||||||
|
|
||||||
/** @var m\Mock|ClientInterface $client */
|
|
||||||
$client = m::mock(ClientInterface::class);
|
|
||||||
$client->shouldReceive('send')->times(1)->andReturn($response);
|
|
||||||
$this->provider->setHttpClient($client);
|
|
||||||
|
|
||||||
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
||||||
|
|
||||||
$this->assertEquals('mock_access_token', $token->getToken());
|
$this->assertSame('mock_access_token', $token->getToken());
|
||||||
$this->assertNotNull($token->getExpires());
|
$this->assertNotNull($token->getExpires());
|
||||||
$this->assertNull($token->getRefreshToken());
|
$this->assertNull($token->getRefreshToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \Ely\OAuth2\Client\Exception\IdentityProviderException
|
|
||||||
* @expectedExceptionMessageRegExp /Exception message .+/
|
|
||||||
*/
|
|
||||||
public function testExceptionThrownWhenErrorObjectReceived() {
|
public function testExceptionThrownWhenErrorObjectReceived() {
|
||||||
$name = 'Error ' . uniqid();
|
$this->mockHandler->append(new Response(418, ['content-type' => 'json'], json_encode([
|
||||||
$message = 'Exception message ' . uniqid();
|
'name' => 'Some error happened',
|
||||||
$status = mt_rand(400, 600);
|
'message' => 'Some exception message',
|
||||||
/** @var m\Mock|ResponseInterface $postResponse */
|
'status' => 418,
|
||||||
$postResponse = m::mock(ResponseInterface::class);
|
|
||||||
$postResponse->shouldReceive('getBody')->andReturn(json_encode([
|
|
||||||
'name' => $name,
|
|
||||||
'message' => $message,
|
|
||||||
'status' => $status,
|
|
||||||
'code' => 0,
|
'code' => 0,
|
||||||
]));
|
])));
|
||||||
$postResponse->shouldReceive('getHeader')->andReturn(['content-type' => 'json']);
|
|
||||||
$postResponse->shouldReceive('getStatusCode')->andReturn($status);
|
$this->setExpectedException(IdentityProviderException::class, 'Some exception message');
|
||||||
|
|
||||||
/** @var m\Mock|ClientInterface $client */
|
|
||||||
$client = m::mock(ClientInterface::class);
|
|
||||||
$client->shouldReceive('send')
|
|
||||||
->times(1)
|
|
||||||
->andReturn($postResponse);
|
|
||||||
$this->provider->setHttpClient($client);
|
|
||||||
$this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
$this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \Ely\OAuth2\Client\Exception\IdentityProviderException
|
|
||||||
* @expectedExceptionMessage Bad Gateway
|
|
||||||
*/
|
|
||||||
public function testExceptionThrownOnIncorrectContentType() {
|
public function testExceptionThrownOnIncorrectContentType() {
|
||||||
/** @var m\Mock|ResponseInterface $postResponse */
|
$this->mockHandler->append(new Response(502, ['content-type' => 'text/html; charset=UTF-8'], 'html content'));
|
||||||
$postResponse = m::mock(ResponseInterface::class);
|
|
||||||
$postResponse->shouldReceive('getHeader')->andReturn(['content-type' => 'text/html; charset=UTF-8']);
|
$this->setExpectedException(IdentityProviderException::class, 'Bad Gateway');
|
||||||
$postResponse->shouldReceive('getBody')->andReturn('html content');
|
|
||||||
$postResponse->shouldReceive('getStatusCode')->andReturn(502);
|
|
||||||
$postResponse->shouldReceive('getReasonPhrase')->andReturn('Bad Gateway');
|
|
||||||
|
|
||||||
/** @var m\Mock|ClientInterface $client */
|
|
||||||
$client = m::mock(ClientInterface::class);
|
|
||||||
$client->shouldReceive('send')
|
|
||||||
->times(1)
|
|
||||||
->andReturn($postResponse);
|
|
||||||
$this->provider->setHttpClient($client);
|
|
||||||
$this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
$this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetResourceOwner() {
|
public function testGetResourceOwner() {
|
||||||
/** @var m\Mock|ResponseInterface $postResponse */
|
$this->mockHandler->append(new Response(200, ['content-type' => 'json'], $this->getAccessTokenResponse()));
|
||||||
$postResponse = m::mock(ResponseInterface::class);
|
$this->mockHandler->append(new Response(200, ['content-type' => 'json'], json_encode([
|
||||||
$postResponse->shouldReceive('getBody')->andReturn($this->getAccessTokenResponse());
|
'id' => 1,
|
||||||
$postResponse->shouldReceive('getHeader')->andReturn(['content-type' => 'json']);
|
'uuid' => 'ffc8fdc9-5824-509e-8a57-c99b940fb996',
|
||||||
$postResponse->shouldReceive('getStatusCode')->andReturn(200);
|
'username' => 'ErickSkrauch',
|
||||||
|
'registeredAt' => 1470566470,
|
||||||
/** @var m\Mock|ResponseInterface $userResponse */
|
'profileLink' => 'http://ely.by/u1',
|
||||||
$userResponse = m::mock(ResponseInterface::class);
|
'preferredLanguage' => 'be',
|
||||||
$userResponse->shouldReceive('getBody')->andReturn(
|
'email' => 'erickskrauch@ely.by',
|
||||||
file_get_contents(__DIR__ . '/data/identity-info-response.json')
|
])));
|
||||||
);
|
|
||||||
$userResponse->shouldReceive('getHeader')->andReturn(['content-type' => 'json']);
|
|
||||||
$userResponse->shouldReceive('getStatusCode')->andReturn(200);
|
|
||||||
|
|
||||||
/** @var m\Mock|ClientInterface $client */
|
|
||||||
$client = m::mock(ClientInterface::class);
|
|
||||||
$client->shouldReceive('send')
|
|
||||||
->times(2)
|
|
||||||
->andReturn($postResponse, $userResponse);
|
|
||||||
$this->provider->setHttpClient($client);
|
|
||||||
|
|
||||||
|
/** @var AccessToken $token */
|
||||||
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
|
||||||
$user = $this->provider->getResourceOwner($token);
|
$user = $this->provider->getResourceOwner($token);
|
||||||
|
|
||||||
$this->assertInstanceOf(ResourceOwner::class, $user);
|
$this->assertInstanceOf(ResourceOwner::class, $user);
|
||||||
|
$this->assertSame(0, $this->mockHandler->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getAccessTokenResponse() {
|
private function getAccessTokenResponse() {
|
||||||
|
@ -1,55 +1,57 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Ely\OAuth2\Client\Test;
|
namespace Ely\OAuth2\Client\Test;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
use Ely\OAuth2\Client\ResourceOwner;
|
use Ely\OAuth2\Client\ResourceOwner;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class ResourceOwnerTest extends \PHPUnit_Framework_TestCase {
|
class ResourceOwnerTest extends TestCase {
|
||||||
|
|
||||||
public function testGetId() {
|
public function testGetId() {
|
||||||
$this->assertEquals(1, $this->createModel()->getId());
|
$this->assertSame(1, $this->createModel()->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetUuid() {
|
public function testGetUuid() {
|
||||||
$this->assertEquals('ffc8fdc9-5824-509e-8a57-c99b940fb996', $this->createModel()->getUuid());
|
$this->assertSame('ffc8fdc9-5824-509e-8a57-c99b940fb996', $this->createModel()->getUuid());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetUsername() {
|
public function testGetUsername() {
|
||||||
$this->assertEquals('ErickSkrauch', $this->createModel()->getUsername());
|
$this->assertSame('ErickSkrauch', $this->createModel()->getUsername());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetEmail() {
|
public function testGetEmail() {
|
||||||
$this->assertEquals('erickskrauch@ely.by', $this->createModel()->getEmail());
|
$this->assertSame('erickskrauch@ely.by', $this->createModel()->getEmail());
|
||||||
$this->assertNull($this->createModelWithoutEmail()->getEmail());
|
$this->assertNull($this->createModelWithoutEmail()->getEmail());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetRegisteredAt() {
|
public function testGetRegisteredAt() {
|
||||||
$registeredAt = $this->createModel()->getRegisteredAt();
|
$registeredAt = $this->createModel()->getRegisteredAt();
|
||||||
$this->assertInstanceOf(\DateTime::class, $registeredAt);
|
$this->assertInstanceOf(DateTime::class, $registeredAt);
|
||||||
$this->assertEquals(1470566470, $registeredAt->getTimestamp());
|
$this->assertSame(1470566470, $registeredAt->getTimestamp());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetProfileLink() {
|
public function testGetProfileLink() {
|
||||||
$this->assertEquals('http://ely.by/u1', $this->createModel()->getProfileLink());
|
$this->assertSame('http://ely.by/u1', $this->createModel()->getProfileLink());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetPreferredLanguage() {
|
public function testGetPreferredLanguage() {
|
||||||
$this->assertEquals('be', $this->createModel()->getPreferredLanguage());
|
$this->assertSame('be', $this->createModel()->getPreferredLanguage());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetSkinUrl() {
|
public function testGetSkinUrl() {
|
||||||
$this->assertEquals('http://skinsystem.ely.by/skins/ErickSkrauch.png', $this->createModel()->getSkinUrl());
|
$this->assertSame('http://skinsystem.ely.by/skins/ErickSkrauch.png', $this->createModel()->getSkinUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testToArray() {
|
public function testToArray() {
|
||||||
$array = $this->createModel()->toArray();
|
$array = $this->createModel()->toArray();
|
||||||
$this->assertTrue(is_array($array));
|
$this->assertInternalType('array', $array);
|
||||||
$this->assertEquals(1, $array['id']);
|
$this->assertSame(1, $array['id']);
|
||||||
$this->assertEquals('ffc8fdc9-5824-509e-8a57-c99b940fb996', $array['uuid']);
|
$this->assertSame('ffc8fdc9-5824-509e-8a57-c99b940fb996', $array['uuid']);
|
||||||
$this->assertEquals('ErickSkrauch', $array['username']);
|
$this->assertSame('ErickSkrauch', $array['username']);
|
||||||
$this->assertEquals('erickskrauch@ely.by', $array['email']);
|
$this->assertSame('erickskrauch@ely.by', $array['email']);
|
||||||
$this->assertEquals(1470566470, $array['registeredAt']);
|
$this->assertSame(1470566470, $array['registeredAt']);
|
||||||
$this->assertEquals('http://ely.by/u1', $array['profileLink']);
|
$this->assertSame('http://ely.by/u1', $array['profileLink']);
|
||||||
$this->assertEquals('http://skinsystem.ely.by/skins/ErickSkrauch.png', $array['skinUrl']);
|
$this->assertSame('http://skinsystem.ely.by/skins/ErickSkrauch.png', $array['skinUrl']);
|
||||||
|
|
||||||
$array = $this->createModelWithoutEmail()->toArray();
|
$array = $this->createModelWithoutEmail()->toArray();
|
||||||
$this->assertArrayNotHasKey('email', $array);
|
$this->assertArrayNotHasKey('email', $array);
|
||||||
@ -67,7 +69,15 @@ class ResourceOwnerTest extends \PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function getAllResponseParams() {
|
private function getAllResponseParams() {
|
||||||
return json_decode(file_get_contents(__DIR__ . '/data/identity-info-response.json'), true);
|
return [
|
||||||
|
'id' => 1,
|
||||||
|
'uuid' => 'ffc8fdc9-5824-509e-8a57-c99b940fb996',
|
||||||
|
'username' => 'ErickSkrauch',
|
||||||
|
'registeredAt' => 1470566470,
|
||||||
|
'profileLink' => 'http://ely.by/u1',
|
||||||
|
'preferredLanguage' => 'be',
|
||||||
|
'email' => 'erickskrauch@ely.by',
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"id": 1,
|
|
||||||
"uuid": "ffc8fdc9-5824-509e-8a57-c99b940fb996",
|
|
||||||
"username": "ErickSkrauch",
|
|
||||||
"registeredAt": 1470566470,
|
|
||||||
"profileLink": "http:\/\/ely.by\/u1",
|
|
||||||
"preferredLanguage": "be",
|
|
||||||
"email": "erickskrauch@ely.by"
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user