mirror of
https://github.com/elyby/oauth2-server.git
synced 2025-05-31 14:12:07 +05:30
Updated tests
This commit is contained in:
@@ -16,12 +16,12 @@ class AbstractTokenTest extends \PHPUnit_Framework_TestCase
|
||||
$time = time();
|
||||
|
||||
$entity = new StubAbstractTokenEntity($server);
|
||||
$entity->setToken('foobar');
|
||||
$entity->setId('foobar');
|
||||
$entity->setExpireTime($time);
|
||||
$entity->setSession((new SessionEntity($server)));
|
||||
$entity->associateScope((new ScopeEntity($server))->setId('foo'));
|
||||
$entity->associateScope((new ScopeEntity($server))->hydrate(['id' => 'foo']));
|
||||
|
||||
$this->assertEquals('foobar', $entity->getToken());
|
||||
$this->assertEquals('foobar', $entity->getId());
|
||||
$this->assertEquals($time, $entity->getExpireTime());
|
||||
// $this->assertTrue($entity->getSession() instanceof SessionEntity);
|
||||
// $this->assertTrue($entity->hasScope('foo'));
|
||||
@@ -92,8 +92,8 @@ class AbstractTokenTest extends \PHPUnit_Framework_TestCase
|
||||
$method->setAccessible(true);
|
||||
|
||||
$scopes = [
|
||||
(new ScopeEntity($server))->setId('scope1')->setDescription('foo'),
|
||||
(new ScopeEntity($server))->setId('scope2')->setDescription('bar')
|
||||
(new ScopeEntity($server))->hydrate(['id' => 'scope1', 'description' => 'foo']),
|
||||
(new ScopeEntity($server))->hydrate(['id' => 'scope2', 'description' => 'bar'])
|
||||
];
|
||||
|
||||
$result = $method->invokeArgs($entity, [$scopes]);
|
||||
@@ -110,7 +110,7 @@ class AbstractTokenTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$entity = new StubAbstractTokenEntity($server);
|
||||
$this->assertEquals('', (string) $entity);
|
||||
$entity->setToken('foobar');
|
||||
$entity->setId('foobar');
|
||||
$this->assertEquals('foobar', (string) $entity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class AccessTokenTest extends \PHPUnit_Framework_TestCase
|
||||
$accessTokenStorage->shouldReceive('associateScope');
|
||||
$accessTokenStorage->shouldReceive('setServer');
|
||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
||||
]);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
|
||||
@@ -18,7 +18,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$code = new AuthCodeEntity($server);
|
||||
$code->setRedirectUri('http://foo/bar');
|
||||
$code->setToken('foobar');
|
||||
$code->setId('foobar');
|
||||
$code->setSession($session);
|
||||
|
||||
$this->assertEquals('http://foo/bar', $code->getRedirectUri());
|
||||
@@ -37,7 +37,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||
$authCodeStorage->shouldReceive('associateScope');
|
||||
$authCodeStorage->shouldReceive('setServer');
|
||||
$authCodeStorage->shouldReceive('getScopes')->andReturn([
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
||||
]);
|
||||
|
||||
$server->shouldReceive('getStorage')->with('auth_code')->andReturn($authCodeStorage);
|
||||
|
||||
@@ -10,11 +10,12 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
||||
public function testSetGet()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
$client = new ClientEntity($server);
|
||||
$client->setId('foobar');
|
||||
$client->setSecret('barfoo');
|
||||
$client->setName('Test Client');
|
||||
$client->setRedirectUri('http://foo/bar');
|
||||
$client = (new ClientEntity($server))->hydrate([
|
||||
'id' => 'foobar',
|
||||
'secret' => 'barfoo',
|
||||
'name' => 'Test Client',
|
||||
'redirectUri' => 'http://foo/bar'
|
||||
]);
|
||||
|
||||
$this->assertEquals('foobar', $client->getId());
|
||||
$this->assertEquals('barfoo', $client->getSecret());
|
||||
|
||||
@@ -39,10 +39,10 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||
$accessTokenStorage->shouldReceive('setServer');
|
||||
$accessTokenStorage->shouldReceive('getByRefreshToken')->andReturn(
|
||||
(new AccessTokenEntity($server))->setToken('foobar')
|
||||
(new AccessTokenEntity($server))->setId('foobar')
|
||||
);
|
||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
||||
]);
|
||||
|
||||
$server->shouldReceive('getStorage')->with('access_token')->andReturn($accessTokenStorage);
|
||||
|
||||
@@ -10,9 +10,10 @@ class ScopeTest extends \PHPUnit_Framework_TestCase
|
||||
public function testSetGet()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
$scope = new ScopeEntity($server);
|
||||
$scope->setId('foobar');
|
||||
$scope->setDescription('barfoo');
|
||||
$scope = (new ScopeEntity($server))->hydrate([
|
||||
'id' => 'foobar',
|
||||
'description' => 'barfoo'
|
||||
]);
|
||||
|
||||
$this->assertEquals('foobar', $scope->getId());
|
||||
$this->assertEquals('barfoo', $scope->getDescription());
|
||||
|
||||
@@ -14,14 +14,22 @@ class SessionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSetGet()
|
||||
{
|
||||
$emitter = M::mock('League\Event\Emitter');
|
||||
$emitter->shouldReceive('emit');
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
$server->shouldReceive('setEventEmitter');
|
||||
$server->shouldReceive('getEventEmitter')->andReturn($emitter);
|
||||
$server->setEventEmitter($emitter);
|
||||
|
||||
$entity = new SessionEntity($server);
|
||||
$entity->setId('foobar');
|
||||
$entity->setOwner('user', 123);
|
||||
$entity->associateAccessToken((new AccessTokenEntity($server)));
|
||||
$entity->associateRefreshToken((new RefreshTokenEntity($server)));
|
||||
$entity->associateClient((new ClientEntity($server)));
|
||||
$entity->associateScope((new ScopeEntity($server))->setId('foo'));
|
||||
$entity->associateScope(
|
||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
||||
);
|
||||
// $entity->associateAuthCode((new AuthCode($server)));
|
||||
|
||||
$this->assertEquals('foobar', $entity->getId());
|
||||
@@ -51,8 +59,8 @@ class SessionTest extends \PHPUnit_Framework_TestCase
|
||||
$method->setAccessible(true);
|
||||
|
||||
$scopes = [
|
||||
(new ScopeEntity($server))->setId('scope1')->setDescription('foo'),
|
||||
(new ScopeEntity($server))->setId('scope2')->setDescription('bar')
|
||||
(new ScopeEntity($server))->hydrate(['id' => 'scope1']),
|
||||
(new ScopeEntity($server))->hydrate(['id' => 'scope2'])
|
||||
];
|
||||
|
||||
$result = $method->invokeArgs($entity, [$scopes]);
|
||||
@@ -124,14 +132,14 @@ class SessionTest extends \PHPUnit_Framework_TestCase
|
||||
$sessionStorage->shouldReceive('associateScope');
|
||||
$sessionStorage->shouldReceive('setServer');
|
||||
$sessionStorage->shouldReceive('getScopes')->andReturn([
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
||||
]);
|
||||
|
||||
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage);
|
||||
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('getBySession')->andReturn(
|
||||
(new ClientEntity($server))->setId('foo')
|
||||
(new ClientEntity($server))->hydrate(['id' => 'foo'])
|
||||
);
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user