oauth2-server/tests/Entity/AccessTokenEntityTest.php
2014-07-11 18:19:10 +01:00

60 lines
2.2 KiB
PHP

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