oauth2-server/tests/unit/Entity/RefreshTokenEntityTest.php

95 lines
3.5 KiB
PHP
Raw Normal View History

2014-01-16 22:21:06 +05:30
<?php
2014-05-02 19:42:15 +05:30
namespace LeagueTests\Entity;
2014-01-16 22:21:06 +05:30
2014-05-02 19:42:15 +05:30
use League\OAuth2\Server\Entity\AccessTokenEntity;
use League\OAuth2\Server\Entity\RefreshTokenEntity;
2014-11-08 23:56:12 +05:30
use League\OAuth2\Server\Entity\ScopeEntity;
use League\OAuth2\Server\Entity\SessionEntity;
use Mockery as M;
2014-01-16 22:21:06 +05:30
2014-08-06 13:12:42 +05:30
class RefreshTokenEntityTest extends \PHPUnit_Framework_TestCase
2014-01-16 22:21:06 +05:30
{
2014-08-06 13:12:42 +05:30
public function testSetAccessTokenId()
{
$server = M::mock('League\OAuth2\Server\AbstractServer');
$entity = new RefreshTokenEntity($server);
$entity->setAccessTokenId('foobar');
$reflector = new \ReflectionClass($entity);
$accessTokenProperty = $reflector->getProperty('accessTokenId');
$accessTokenProperty->setAccessible(true);
$this->assertSame($accessTokenProperty->getValue($entity), 'foobar');
}
2014-05-03 15:25:25 +05:30
public function testSetAccessToken()
2014-01-16 22:21:06 +05:30
{
$server = M::mock('League\OAuth2\Server\AbstractServer');
2014-05-02 21:51:53 +05:30
$entity = new RefreshTokenEntity($server);
$entity->setAccessToken((new AccessTokenEntity($server)));
2014-01-16 22:21:06 +05:30
2014-01-16 22:57:05 +05:30
$reflector = new \ReflectionClass($entity);
2014-08-06 13:12:42 +05:30
$accessTokenProperty = $reflector->getProperty('accessTokenEntity');
2014-01-16 22:57:05 +05:30
$accessTokenProperty->setAccessible(true);
2014-05-02 21:51:53 +05:30
$this->assertTrue($accessTokenProperty->getValue($entity) instanceof AccessTokenEntity);
2014-01-16 22:21:06 +05:30
}
2014-05-03 15:25:25 +05:30
public function testSave()
2014-01-16 22:21:06 +05:30
{
2014-05-02 21:51:53 +05:30
$server = M::mock('League\OAuth2\Server\AbstractServer');
$server->shouldReceive('setAccessTokenStorage');
$server->shouldReceive('setRefreshTokenStorage');
2014-01-16 22:21:06 +05:30
$refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface');
$refreshTokenStorage->shouldReceive('create');
$refreshTokenStorage->shouldReceive('setServer');
$refreshTokenStorage->shouldReceive('associateScope');
$server->shouldReceive('getRefreshTokenStorage')->andReturn($refreshTokenStorage);
2014-05-02 21:51:53 +05:30
2014-01-16 22:21:06 +05:30
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
$accessTokenStorage->shouldReceive('setServer');
2014-08-06 13:12:42 +05:30
$accessTokenStorage->shouldReceive('get')->andReturn(
2014-07-11 22:49:10 +05:30
(new AccessTokenEntity($server))->setId('foobar')
2014-01-16 22:21:06 +05:30
);
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
2014-11-08 23:56:12 +05:30
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
2014-01-16 22:21:06 +05:30
]);
$server->shouldReceive('getAccessTokenStorage')->andReturn($accessTokenStorage);
2014-05-02 21:51:53 +05:30
2014-01-16 22:21:06 +05:30
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
2014-05-02 21:51:53 +05:30
(new SessionEntity($server))
2014-01-16 22:21:06 +05:30
);
$sessionStorage->shouldReceive('setServer');
$server->shouldReceive('getSessionStorage')->andReturn($sessionStorage);
2014-05-02 21:51:53 +05:30
2014-01-16 22:21:06 +05:30
$server->setAccessTokenStorage($accessTokenStorage);
$server->setRefreshTokenStorage($refreshTokenStorage);
2014-05-02 21:51:53 +05:30
$entity = new RefreshTokenEntity($server);
2014-01-16 22:21:06 +05:30
$this->assertSame(null, $entity->save());
}
2014-05-03 15:25:25 +05:30
public function testExpire()
2014-01-16 22:21:06 +05:30
{
2014-05-02 21:51:53 +05:30
$server = M::mock('League\OAuth2\Server\AbstractServer');
$server->shouldReceive('setRefreshTokenStorage');
2014-01-16 22:21:06 +05:30
$refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface');
$refreshTokenStorage->shouldReceive('delete');
$refreshTokenStorage->shouldReceive('setServer');
$server->shouldReceive('getRefreshTokenStorage')->andReturn($refreshTokenStorage);
2014-05-02 21:51:53 +05:30
2014-01-16 22:21:06 +05:30
$server->setRefreshTokenStorage($refreshTokenStorage);
2014-05-02 21:51:53 +05:30
$entity = new RefreshTokenEntity($server);
2014-01-16 22:21:06 +05:30
$this->assertSame($entity->expire(), null);
}
}