Updated tests

This commit is contained in:
Alex Bilbie
2014-07-11 18:19:10 +01:00
parent 48dea185d8
commit c6bc1b0cfc
13 changed files with 115 additions and 101 deletions

View File

@@ -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);
}
}

View File

@@ -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');

View File

@@ -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);

View File

@@ -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());

View File

@@ -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);

View File

@@ -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());

View File

@@ -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');