mirror of
https://github.com/elyby/oauth2-server.git
synced 2026-04-27 17:52:30 +05:30
Moved unit tests
This commit is contained in:
116
tests/unit/Entity/AbstractTokenEntityTest.php
Normal file
116
tests/unit/Entity/AbstractTokenEntityTest.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace LeagueTests\Entity;
|
||||
|
||||
use LeagueTests\Stubs\StubAbstractTokenEntity;
|
||||
use League\OAuth2\Server\Entity\SessionEntity;
|
||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||
use League\OAuth2\Server\AuthorizationServer;
|
||||
use \Mockery as M;
|
||||
|
||||
class AbstractTokenTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSetGet()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
$time = time();
|
||||
|
||||
$entity = new StubAbstractTokenEntity($server);
|
||||
$entity->setId('foobar');
|
||||
$entity->setExpireTime($time);
|
||||
$entity->setSession((new SessionEntity($server)));
|
||||
$entity->associateScope((new ScopeEntity($server))->hydrate(['id' => 'foo']));
|
||||
|
||||
$this->assertEquals('foobar', $entity->getId());
|
||||
$this->assertEquals($time, $entity->getExpireTime());
|
||||
// $this->assertTrue($entity->getSession() instanceof SessionEntity);
|
||||
// $this->assertTrue($entity->hasScope('foo'));
|
||||
|
||||
// $result = $entity->getScopes();
|
||||
// $this->assertTrue(isset($result['foo']));
|
||||
}
|
||||
|
||||
/*public function testGetSession()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AuthorizationServer');
|
||||
$server->shouldReceive('setSessionStorage');
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
|
||||
(new SessionEntity($server))
|
||||
);
|
||||
$sessionStorage->shouldReceive('setServer');
|
||||
|
||||
$server->shouldReceive('getStorage')->andReturn($sessionStorage);
|
||||
|
||||
$server->setSessionStorage($sessionStorage);
|
||||
|
||||
$entity = new StubAbstractTokenEntity($server);
|
||||
$this->assertTrue($entity->getSession() instanceof SessionEntity);
|
||||
}*/
|
||||
|
||||
/*public function testGetScopes()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AuthorizationServer');
|
||||
$server->shouldReceive('setAccessTokenStorage');
|
||||
|
||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn(
|
||||
[]
|
||||
);
|
||||
$accessTokenStorage->shouldReceive('setServer');
|
||||
|
||||
$server->setAccessTokenStorage($accessTokenStorage);
|
||||
|
||||
$entity = new StubAbstractTokenEntity($server);
|
||||
$this->assertEquals($entity->getScopes(), []);
|
||||
}*/
|
||||
|
||||
/*public function testHasScopes()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AuthorizationServer');
|
||||
|
||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn(
|
||||
[]
|
||||
);
|
||||
$accessTokenStorage''>shouldReceive('setServer');
|
||||
|
||||
$server->setAccessTokenStorage($accessTokenStorage);
|
||||
|
||||
$entity = new StubAbstractTokenEntity($server);
|
||||
$this->assertFalse($entity->hasScope('foo'));
|
||||
}*/
|
||||
|
||||
public function testFormatScopes()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
|
||||
$entity = new StubAbstractTokenEntity($server);
|
||||
$reflectedEntity = new \ReflectionClass('LeagueTests\Stubs\StubAbstractTokenEntity');
|
||||
$method = $reflectedEntity->getMethod('formatScopes');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$scopes = [
|
||||
(new ScopeEntity($server))->hydrate(['id' => 'scope1', 'description' => 'foo']),
|
||||
(new ScopeEntity($server))->hydrate(['id' => 'scope2', 'description' => 'bar'])
|
||||
];
|
||||
|
||||
$result = $method->invokeArgs($entity, [$scopes]);
|
||||
|
||||
$this->assertTrue(isset($result['scope1']));
|
||||
$this->assertTrue(isset($result['scope2']));
|
||||
$this->assertTrue($result['scope1'] instanceof ScopeEntity);
|
||||
$this->assertTrue($result['scope2'] instanceof ScopeEntity);
|
||||
}
|
||||
|
||||
public function test__toString()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
|
||||
$entity = new StubAbstractTokenEntity($server);
|
||||
$this->assertEquals('', (string) $entity);
|
||||
$entity->setId('foobar');
|
||||
$this->assertEquals('foobar', (string) $entity);
|
||||
}
|
||||
}
|
||||
59
tests/unit/Entity/AccessTokenEntityTest.php
Normal file
59
tests/unit/Entity/AccessTokenEntityTest.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace LeagueTests\Entity;
|
||||
|
||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||
use League\OAuth2\Server\Entity\SessionEntity;
|
||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||
use \Mockery as M;
|
||||
|
||||
class AccessTokenTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSave()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
$server->shouldReceive('setAccessTokenStorage');
|
||||
$server->shouldReceive('setSessionStorage');
|
||||
|
||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||
$accessTokenStorage->shouldReceive('create');
|
||||
$accessTokenStorage->shouldReceive('associateScope');
|
||||
$accessTokenStorage->shouldReceive('setServer');
|
||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
||||
]);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
|
||||
(new SessionEntity($server))
|
||||
);
|
||||
$sessionStorage->shouldReceive('setServer');
|
||||
|
||||
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage);
|
||||
$server->shouldReceive('getStorage')->with('access_token')->andReturn($accessTokenStorage);
|
||||
|
||||
$server->setAccessTokenStorage($accessTokenStorage);
|
||||
$server->setSessionStorage($sessionStorage);
|
||||
|
||||
$entity = new AccessTokenEntity($server);
|
||||
$this->assertTrue($entity->save() instanceof AccessTokenEntity);
|
||||
}
|
||||
|
||||
public function testExpire()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
|
||||
$server->shouldReceive('setAccessTokenStorage');
|
||||
|
||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||
$accessTokenStorage->shouldReceive('delete');
|
||||
$accessTokenStorage->shouldReceive('setServer');
|
||||
|
||||
$server->shouldReceive('getStorage')->with('access_token')->andReturn($accessTokenStorage);
|
||||
|
||||
$server->setAccessTokenStorage($accessTokenStorage);
|
||||
|
||||
$entity = new AccessTokenEntity($server);
|
||||
$this->assertSame($entity->expire(), null);
|
||||
}
|
||||
}
|
||||
73
tests/unit/Entity/AuthCodeEntityTest.php
Normal file
73
tests/unit/Entity/AuthCodeEntityTest.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace LeagueTests\Entity;
|
||||
|
||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||
use League\OAuth2\Server\Entity\SessionEntity;
|
||||
use League\OAuth2\Server\Entity\AuthCodeEntity;
|
||||
use League\OAuth2\Server\AuthorizationServer;
|
||||
use \Mockery as M;
|
||||
|
||||
class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSetGet()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
|
||||
$session = M::mock('League\OAuth2\Server\Entity\SessionEntity');
|
||||
|
||||
$code = new AuthCodeEntity($server);
|
||||
$code->setRedirectUri('http://foo/bar');
|
||||
$code->setId('foobar');
|
||||
$code->setSession($session);
|
||||
|
||||
$this->assertEquals('http://foo/bar', $code->getRedirectUri());
|
||||
$this->assertEquals('http://foo/bar?code=foobar', $code->generateRedirectUri());
|
||||
$this->assertTrue($code->getSession() instanceof \League\OAuth2\Server\Entity\SessionEntity);
|
||||
}
|
||||
|
||||
public function testSave()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
$server->shouldReceive('setAuthCodeStorage');
|
||||
$server->shouldReceive('setSessionStorage');
|
||||
|
||||
$authCodeStorage = M::mock('League\OAuth2\Server\Storage\AuthCodeInterface');
|
||||
$authCodeStorage->shouldReceive('create');
|
||||
$authCodeStorage->shouldReceive('associateScope');
|
||||
$authCodeStorage->shouldReceive('setServer');
|
||||
$authCodeStorage->shouldReceive('getScopes')->andReturn([
|
||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
||||
]);
|
||||
|
||||
$server->shouldReceive('getStorage')->with('auth_code')->andReturn($authCodeStorage);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
$sessionStorage->shouldReceive('getByAuthCode')->andReturn(
|
||||
(new SessionEntity($server))
|
||||
);
|
||||
$sessionStorage->shouldReceive('setServer');
|
||||
|
||||
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage);
|
||||
|
||||
$server->setAuthCodeStorage($authCodeStorage);
|
||||
$server->setSessionStorage($sessionStorage);
|
||||
|
||||
$entity = new AuthCodeEntity($server);
|
||||
$this->assertTrue($entity->save() instanceof AuthCodeEntity);
|
||||
}
|
||||
|
||||
public function testExpire()
|
||||
{
|
||||
$server = new AuthorizationServer();
|
||||
|
||||
$authCodeStorage = M::mock('League\OAuth2\Server\Storage\AuthCodeInterface');
|
||||
$authCodeStorage->shouldReceive('delete');
|
||||
$authCodeStorage->shouldReceive('setServer');
|
||||
|
||||
$server->setAuthCodeStorage($authCodeStorage);
|
||||
|
||||
$entity = new AuthCodeEntity($server);
|
||||
$this->assertSame($entity->expire(), null);
|
||||
}
|
||||
}
|
||||
25
tests/unit/Entity/ClientEntityTest.php
Normal file
25
tests/unit/Entity/ClientEntityTest.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace LeagueTests\Entity;
|
||||
|
||||
use League\OAuth2\Server\Entity\ClientEntity;
|
||||
use \Mockery as M;
|
||||
|
||||
class ClientTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSetGet()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
$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());
|
||||
$this->assertEquals('Test Client', $client->getName());
|
||||
$this->assertEquals('http://foo/bar', $client->getRedirectUri());
|
||||
}
|
||||
}
|
||||
81
tests/unit/Entity/RefreshTokenEntityTest.php
Normal file
81
tests/unit/Entity/RefreshTokenEntityTest.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace LeagueTests\Entity;
|
||||
|
||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||
use League\OAuth2\Server\Entity\SessionEntity;
|
||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
||||
use \Mockery as M;
|
||||
|
||||
class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSetAccessToken()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
$entity = new RefreshTokenEntity($server);
|
||||
$entity->setAccessToken((new AccessTokenEntity($server)));
|
||||
|
||||
$reflector = new \ReflectionClass($entity);
|
||||
$accessTokenProperty = $reflector->getProperty('accessToken');
|
||||
$accessTokenProperty->setAccessible(true);
|
||||
|
||||
$this->assertTrue($accessTokenProperty->getValue($entity) instanceof AccessTokenEntity);
|
||||
}
|
||||
|
||||
public function testSave()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
$server->shouldReceive('setAccessTokenStorage');
|
||||
$server->shouldReceive('setRefreshTokenStorage');
|
||||
|
||||
$refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface');
|
||||
$refreshTokenStorage->shouldReceive('create');
|
||||
$refreshTokenStorage->shouldReceive('setServer');
|
||||
$refreshTokenStorage->shouldReceive('associateScope');
|
||||
|
||||
$server->shouldReceive('getStorage')->with('refresh_token')->andReturn($refreshTokenStorage);
|
||||
|
||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||
$accessTokenStorage->shouldReceive('setServer');
|
||||
$accessTokenStorage->shouldReceive('getByRefreshToken')->andReturn(
|
||||
(new AccessTokenEntity($server))->setId('foobar')
|
||||
);
|
||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
||||
]);
|
||||
|
||||
$server->shouldReceive('getStorage')->with('access_token')->andReturn($accessTokenStorage);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
|
||||
(new SessionEntity($server))
|
||||
);
|
||||
$sessionStorage->shouldReceive('setServer');
|
||||
|
||||
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage);
|
||||
|
||||
$server->setAccessTokenStorage($accessTokenStorage);
|
||||
$server->setRefreshTokenStorage($refreshTokenStorage);
|
||||
|
||||
$entity = new RefreshTokenEntity($server);
|
||||
$this->assertSame(null, $entity->save());
|
||||
}
|
||||
|
||||
public function testExpire()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
$server->shouldReceive('setRefreshTokenStorage');
|
||||
|
||||
$refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface');
|
||||
$refreshTokenStorage->shouldReceive('delete');
|
||||
$refreshTokenStorage->shouldReceive('setServer');
|
||||
|
||||
$server->shouldReceive('getStorage')->with('refresh_token')->andReturn($refreshTokenStorage);
|
||||
|
||||
$server->setRefreshTokenStorage($refreshTokenStorage);
|
||||
|
||||
$entity = new RefreshTokenEntity($server);
|
||||
$this->assertSame($entity->expire(), null);
|
||||
}
|
||||
}
|
||||
23
tests/unit/Entity/ScopeEntityTest.php
Normal file
23
tests/unit/Entity/ScopeEntityTest.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace LeagueTests\Entity;
|
||||
|
||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||
use \Mockery as M;
|
||||
|
||||
class ScopeTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSetGet()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
$scope = (new ScopeEntity($server))->hydrate([
|
||||
'id' => 'foobar',
|
||||
'description' => 'barfoo'
|
||||
]);
|
||||
|
||||
$this->assertEquals('foobar', $scope->getId());
|
||||
$this->assertEquals('barfoo', $scope->getDescription());
|
||||
|
||||
$this->assertTrue(is_array($scope->jsonSerialize()));
|
||||
}
|
||||
}
|
||||
154
tests/unit/Entity/SessionEntityTest.php
Normal file
154
tests/unit/Entity/SessionEntityTest.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
namespace LeagueTests\Entity;
|
||||
|
||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||
use League\OAuth2\Server\Entity\ClientEntity;
|
||||
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
||||
use League\OAuth2\Server\Entity\SessionEntity;
|
||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||
use League\OAuth2\Server\AuthorizationServer;
|
||||
use \Mockery as M;
|
||||
|
||||
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))->hydrate(['id' => 'foo'])
|
||||
);
|
||||
// $entity->associateAuthCode((new AuthCode($server)));
|
||||
|
||||
$this->assertEquals('foobar', $entity->getId());
|
||||
$this->assertEquals('user', $entity->getOwnerType());
|
||||
$this->assertEquals(123, $entity->getOwnerId());
|
||||
$this->assertTrue($entity->getClient() instanceof ClientEntity);
|
||||
$this->assertTrue($entity->hasScope('foo'));
|
||||
|
||||
$reflector = new \ReflectionClass($entity);
|
||||
$accessTokenProperty = $reflector->getProperty('accessToken');
|
||||
$accessTokenProperty->setAccessible(true);
|
||||
$refreshTokenProperty = $reflector->getProperty('refreshToken');
|
||||
$refreshTokenProperty->setAccessible(true);
|
||||
|
||||
$this->assertTrue($accessTokenProperty->getValue($entity) instanceof AccessTokenEntity);
|
||||
$this->assertTrue($refreshTokenProperty->getValue($entity) instanceof RefreshTokenEntity);
|
||||
// $this->assertTrue($reader($entity, 'authCode') instanceof AuthCode);
|
||||
}
|
||||
|
||||
public function testFormatScopes()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
|
||||
$entity = new SessionEntity($server);
|
||||
$reflectedEntity = new \ReflectionClass('League\OAuth2\Server\Entity\SessionEntity');
|
||||
$method = $reflectedEntity->getMethod('formatScopes');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$scopes = [
|
||||
(new ScopeEntity($server))->hydrate(['id' => 'scope1']),
|
||||
(new ScopeEntity($server))->hydrate(['id' => 'scope2'])
|
||||
];
|
||||
|
||||
$result = $method->invokeArgs($entity, [$scopes]);
|
||||
|
||||
$this->assertTrue(isset($result['scope1']));
|
||||
$this->assertTrue(isset($result['scope2']));
|
||||
$this->assertTrue($result['scope1'] instanceof ScopeEntity);
|
||||
$this->assertTrue($result['scope2'] instanceof ScopeEntity);
|
||||
}
|
||||
|
||||
public function testGetScopes()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AuthorizationServer');
|
||||
$server->shouldReceive('setAccessTokenStorage');
|
||||
$server->shouldReceive('setSessionStorage');
|
||||
|
||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||
$accessTokenStorage->shouldReceive('setServer');
|
||||
$server->setAccessTokenStorage($accessTokenStorage);
|
||||
|
||||
$server->shouldReceive('getStorage')->with('access_token')->andReturn($accessTokenStorage);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
$sessionStorage->shouldReceive('getScopes')->andReturn(
|
||||
[]
|
||||
);
|
||||
$sessionStorage->shouldReceive('setServer');
|
||||
$server->setSessionStorage($sessionStorage);
|
||||
|
||||
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage);
|
||||
|
||||
$entity = new SessionEntity($server);
|
||||
$this->assertEquals($entity->getScopes(), []);
|
||||
}
|
||||
|
||||
public function testHasScopes()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AuthorizationServer');
|
||||
$server->shouldReceive('setAccessTokenStorage');
|
||||
$server->shouldReceive('setSessionStorage');
|
||||
|
||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||
$accessTokenStorage->shouldReceive('setServer');
|
||||
$server->setAccessTokenStorage($accessTokenStorage);
|
||||
|
||||
$server->shouldReceive('getStorage')->with('access_token')->andReturn($accessTokenStorage);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
$sessionStorage->shouldReceive('getScopes')->andReturn(
|
||||
[]
|
||||
);
|
||||
$sessionStorage->shouldReceive('setServer');
|
||||
$server->setSessionStorage($sessionStorage);
|
||||
|
||||
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage);
|
||||
|
||||
$entity = new SessionEntity($server);
|
||||
$this->assertFalse($entity->hasScope('foo'));
|
||||
}
|
||||
|
||||
public function testSave()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AuthorizationServer');
|
||||
$server->shouldReceive('setSessionStorage');
|
||||
$server->shouldReceive('setClientStorage');
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
$sessionStorage->shouldReceive('create');
|
||||
$sessionStorage->shouldReceive('associateScope');
|
||||
$sessionStorage->shouldReceive('setServer');
|
||||
$sessionStorage->shouldReceive('getScopes')->andReturn([
|
||||
(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))->hydrate(['id' => 'foo'])
|
||||
);
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
|
||||
$server->shouldReceive('getStorage')->with('client')->andReturn($clientStorage);
|
||||
|
||||
$server->setSessionStorage($sessionStorage);
|
||||
$server->setClientStorage($clientStorage);
|
||||
|
||||
$entity = new SessionEntity($server);
|
||||
$this->assertEquals(null, $entity->save());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user