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

60 lines
2.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-11-08 23:56:12 +05:30
use League\OAuth2\Server\Entity\AccessTokenEntity;
2014-05-02 19:42:15 +05:30
use League\OAuth2\Server\Entity\ScopeEntity;
use League\OAuth2\Server\Entity\SessionEntity;
2014-11-08 23:56:12 +05:30
use Mockery as M;
2014-01-16 22:21:06 +05:30
2014-11-08 23:56:12 +05:30
class AccessTokenEntityTest extends \PHPUnit_Framework_TestCase
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 19:42:15 +05:30
$server = M::mock('League\OAuth2\Server\AbstractServer');
$server->shouldReceive('setAccessTokenStorage');
$server->shouldReceive('setSessionStorage');
2014-01-16 22:21:06 +05:30
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
$accessTokenStorage->shouldReceive('create');
$accessTokenStorage->shouldReceive('associateScope');
$accessTokenStorage->shouldReceive('setServer');
$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
]);
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
2014-05-02 19:42:15 +05:30
(new SessionEntity($server))
2014-01-16 22:21:06 +05:30
);
$sessionStorage->shouldReceive('setServer');
$server->shouldReceive('getSessionStorage')->andReturn($sessionStorage);
$server->shouldReceive('getAccessTokenStorage')->andReturn($accessTokenStorage);
2014-05-02 19:42:15 +05:30
2014-01-16 22:21:06 +05:30
$server->setAccessTokenStorage($accessTokenStorage);
$server->setSessionStorage($sessionStorage);
2014-05-02 19:42:15 +05:30
$entity = new AccessTokenEntity($server);
$this->assertTrue($entity->save() instanceof AccessTokenEntity);
2014-01-16 22:21:06 +05:30
}
2014-05-03 15:25:25 +05:30
public function testExpire()
2014-01-16 22:21:06 +05:30
{
2014-05-02 19:42:15 +05:30
$server = M::mock('League\OAuth2\Server\AbstractServer');
$server->shouldReceive('setAccessTokenStorage');
2014-01-16 22:21:06 +05:30
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
$accessTokenStorage->shouldReceive('delete');
$accessTokenStorage->shouldReceive('setServer');
$server->shouldReceive('getAccessTokenStorage')->andReturn($accessTokenStorage);
2014-05-02 19:42:15 +05:30
2014-01-16 22:21:06 +05:30
$server->setAccessTokenStorage($accessTokenStorage);
2014-05-02 19:42:15 +05:30
$entity = new AccessTokenEntity($server);
2014-01-16 22:21:06 +05:30
$this->assertSame($entity->expire(), null);
}
}