oauth2-server/tests/Entity/RefreshTokenTest.php

82 lines
3.1 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\ScopeEntity;
use League\OAuth2\Server\Entity\SessionEntity;
use League\OAuth2\Server\Entity\AccessTokenEntity;
use League\OAuth2\Server\Entity\RefreshTokenEntity;
2014-01-16 22:21:06 +05:30
use \Mockery as M;
2014-05-03 15:25:25 +05:30
class RefreshTokenTest extends \PHPUnit_Framework_TestCase
2014-01-16 22:21:06 +05:30
{
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);
$accessTokenProperty = $reflector->getProperty('accessToken');
$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');
2014-05-02 21:51:53 +05:30
$server->shouldReceive('getStorage')->with('refresh_token')->andReturn($refreshTokenStorage);
2014-01-16 22:21:06 +05:30
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
$accessTokenStorage->shouldReceive('setServer');
$accessTokenStorage->shouldReceive('getByRefreshToken')->andReturn(
2014-05-02 21:51:53 +05:30
(new AccessTokenEntity($server))->setToken('foobar')
2014-01-16 22:21:06 +05:30
);
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
2014-05-02 21:51:53 +05:30
(new ScopeEntity($server))->setId('foo')
2014-01-16 22:21:06 +05:30
]);
2014-05-02 21:51:53 +05:30
$server->shouldReceive('getStorage')->with('access_token')->andReturn($accessTokenStorage);
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');
2014-05-02 21:51:53 +05:30
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage);
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');
2014-05-02 21:51:53 +05:30
$server->shouldReceive('getStorage')->with('refresh_token')->andReturn($refreshTokenStorage);
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);
}
}