Removed generic getStorage method and replaced with distinct calls to getters

This commit is contained in:
Alex Bilbie 2014-11-07 02:20:06 +00:00
parent 9bb7af6f83
commit 3815355489
18 changed files with 213 additions and 169 deletions

View File

@ -13,6 +13,12 @@ namespace League\OAuth2\Server;
use League\OAuth2\Server\Exception; use League\OAuth2\Server\Exception;
use League\OAuth2\Server\TokenType\TokenTypeInterface; use League\OAuth2\Server\TokenType\TokenTypeInterface;
use League\OAuth2\Server\Storage\SessionInterface;
use League\OAuth2\Server\Storage\AccessTokenInterface;
use League\OAuth2\Server\Storage\RefreshTokenInterface;
use League\OAuth2\Server\Storage\AuthCodeInterface;
use League\OAuth2\Server\Storage\ScopeInterface;
use League\OAuth2\Server\Storage\ClientInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use League\Event\Emitter; use League\Event\Emitter;
@ -30,10 +36,40 @@ abstract class AbstractServer
protected $request; protected $request;
/** /**
* Storage classes * Session storage
* @var array * @var \League\OAuth2\Server\Storage\SessionInterface
*/ */
protected $storages = []; protected $sessionStorage;
/**
* Access token storage
* @var \League\OAuth2\Server\Storage\AccessTokenInterface
*/
protected $accessTokenStorage;
/**
* Refresh token storage
* @var \League\OAuth2\Server\Storage\RefreshTokenInterface
*/
protected $refreshTokenStorage;
/**
* Auth code storage
* @var \League\OAuth2\Server\Storage\AuthCodeInterface
*/
protected $authCodeStorage;
/**
* Scope storage
* @var \League\OAuth2\Server\Storage\ScopeInterface
*/
protected $scopeStorage;
/**
* Client storage
* @var \League\OAuth2\Server\Storage\ClientInterface
*/
protected $clientStorage;
/** /**
* Token type * Token type
@ -113,19 +149,135 @@ abstract class AbstractServer
} }
/** /**
* Return a storage class * Set the client storage
* @param string $obj The class required * @param \League\OAuth2\Server\Storage\ClientInterface $storage
* @return Storage\ClientInterface|Storage\ScopeInterface|Storage\SessionInterface|Storage\AccessTokenInterface|Storage\AuthCodeInterface|Storage\RefreshTokenInterface * @return self
*/ */
public function getStorage($obj) public function setClientStorage(ClientInterface $storage)
{ {
if (!isset($this->storages[$obj])) { $storage->setServer($this);
throw new Exception\ServerErrorException( $this->clientStorage = $storage;
'The `'.$obj.'` storage interface has not been registered with the server'
); return $this;
} }
return $this->storages[$obj]; /**
* Set the session storage
* @param \League\OAuth2\Server\Storage\SessionInterface $storage
* @return self
*/
public function setSessionStorage(SessionInterface $storage)
{
$storage->setServer($this);
$this->sessionStorage = $storage;
return $this;
}
/**
* Set the access token storage
* @param \League\OAuth2\Server\Storage\AccessTokenInterface $storage
* @return self
*/
public function setAccessTokenStorage(AccessTokenInterface $storage)
{
$storage->setServer($this);
$this->accessTokenStorage = $storage;
return $this;
}
/**
* Set the refresh token storage
* @param \League\OAuth2\Server\Storage\RefreshTokenInteface $storage
* @return self
*/
public function setRefreshTokenStorage(RefreshTokenInterface $storage)
{
$storage->setServer($this);
$this->refreshTokenStorage = $storage;
return $this;
}
/**
* Set the auth code storage
* @param \League\OAuth2\Server\Storage\AuthCodeInterface $authCode
* @return self
*/
public function setAuthCodeStorage(AuthCodeInterface $storage)
{
$storage->setServer($this);
$this->authCodeStorage = $storage;
return $this;
}
/**
* Set the scope storage
* @param \League\OAuth2\Server\Storage\ScopeInterface $storage
* @return self
*/
public function setScopeStorage(ScopeInterface $storage)
{
$storage->setServer($this);
$this->scopeStorage = $storage;
return $this;
}
/**
* Return the client storage
* @return \League\OAuth2\Server\Storage\ClientInterface
*/
public function getClientStorage()
{
return $this->clientStorage;
}
/**
* Return the scope storage
* @return \League\OAuth2\Server\Storage\ScopeInterface
*/
public function getScopeStorage()
{
return $this->scopeStorage;
}
/**
* Return the session storage
* @return \League\OAuth2\Server\Storage\SessionInterface
*/
public function getSessionStorage()
{
return $this->sessionStorage;
}
/**
* Return the refresh token storage
* @return \League\OAuth2\Server\Storage\RefreshTokenInterface
*/
public function getRefreshTokenStorage()
{
return $this->refreshTokenStorage;
}
/**
* Return the access token storage
* @return \League\OAuth2\Server\Storage\AccessTokenInterface
*/
public function getAccessTokenStorage()
{
return $this->accessTokenStorage;
}
/**
* Return the auth code storage
* @return \League\OAuth2\Server\Storage\AuthCodeInterface
*/
public function getAuthCodeStorage()
{
return $this->authCodeStorage;
} }
/** /**

View File

@ -75,8 +75,6 @@ class AuthorizationServer extends AbstractServer
*/ */
public function __construct() public function __construct()
{ {
$this->storages = [];
// Set Bearer as the default token type // Set Bearer as the default token type
$this->setTokenType(new Bearer); $this->setTokenType(new Bearer);
@ -85,84 +83,6 @@ class AuthorizationServer extends AbstractServer
return $this; return $this;
} }
/**
* Set the client storage
* @param ClientInterface $storage
* @return self
*/
public function setClientStorage(ClientInterface $storage)
{
$storage->setServer($this);
$this->storages['client'] = $storage;
return $this;
}
/**
* Set the session storage
* @param SessionInterface $storage
* @return self
*/
public function setSessionStorage(SessionInterface $storage)
{
$storage->setServer($this);
$this->storages['session'] = $storage;
return $this;
}
/**
* Set the access token storage
* @param AccessTokenInterface $storage
* @return self
*/
public function setAccessTokenStorage(AccessTokenInterface $storage)
{
$storage->setServer($this);
$this->storages['access_token'] = $storage;
return $this;
}
/**
* Set the refresh token storage
* @param RefreshTokenInteface $storage
* @return self
*/
public function setRefreshTokenStorage(RefreshTokenInterface $storage)
{
$storage->setServer($this);
$this->storages['refresh_token'] = $storage;
return $this;
}
/**
* Set the auth code storage
* @param AuthCodeInterface $authCode
* @return self
*/
public function setAuthCodeStorage(AuthCodeInterface $storage)
{
$storage->setServer($this);
$this->storages['auth_code'] = $storage;
return $this;
}
/**
* Set the scope storage
* @param ScopeInterface $storage
* @return self
*/
public function setScopeStorage(ScopeInterface $storage)
{
$storage->setServer($this);
$this->storages['scope'] = $storage;
return $this;
}
/** /**
* Enable support for a grant * Enable support for a grant
* @param GrantTypeInterface $grantType A grant class which conforms to Interface/GrantTypeInterface * @param GrantTypeInterface $grantType A grant class which conforms to Interface/GrantTypeInterface

View File

@ -26,7 +26,7 @@ class AccessTokenEntity extends AbstractTokenEntity
return $this->session; return $this->session;
} }
$this->session = $this->server->getStorage('session')->getByAccessToken($this); $this->session = $this->server->getSessionStorage()->getByAccessToken($this);
return $this->session; return $this->session;
} }
@ -53,7 +53,7 @@ class AccessTokenEntity extends AbstractTokenEntity
{ {
if ($this->scopes === null) { if ($this->scopes === null) {
$this->scopes = $this->formatScopes( $this->scopes = $this->formatScopes(
$this->server->getStorage('access_token')->getScopes($this) $this->server->getAccessTokenStorage()->getScopes($this)
); );
} }
@ -65,7 +65,7 @@ class AccessTokenEntity extends AbstractTokenEntity
*/ */
public function save() public function save()
{ {
$this->server->getStorage('access_token')->create( $this->server->getAccessTokenStorage()->create(
$this->getId(), $this->getId(),
$this->getExpireTime(), $this->getExpireTime(),
$this->getSession()->getId() $this->getSession()->getId()
@ -73,7 +73,7 @@ class AccessTokenEntity extends AbstractTokenEntity
// Associate the scope with the token // Associate the scope with the token
foreach ($this->getScopes() as $scope) { foreach ($this->getScopes() as $scope) {
$this->server->getStorage('access_token')->associateScope($this, $scope); $this->server->getAccessTokenStorage()->associateScope($this, $scope);
} }
return $this; return $this;
@ -84,6 +84,6 @@ class AccessTokenEntity extends AbstractTokenEntity
*/ */
public function expire() public function expire()
{ {
$this->server->getStorage('access_token')->delete($this); $this->server->getAccessTokenStorage()->delete($this);
} }
} }

View File

@ -70,7 +70,7 @@ class AuthCodeEntity extends AbstractTokenEntity
return $this->session; return $this->session;
} }
$this->session = $this->server->getStorage('session')->getByAuthCode($this); $this->session = $this->server->getSessionStorage()->getByAuthCode($this);
return $this->session; return $this->session;
} }
@ -83,7 +83,7 @@ class AuthCodeEntity extends AbstractTokenEntity
{ {
if ($this->scopes === null) { if ($this->scopes === null) {
$this->scopes = $this->formatScopes( $this->scopes = $this->formatScopes(
$this->server->getStorage('auth_code')->getScopes($this) $this->server->getAuthCodeStorage()->getScopes($this)
); );
} }
@ -95,7 +95,7 @@ class AuthCodeEntity extends AbstractTokenEntity
*/ */
public function save() public function save()
{ {
$this->server->getStorage('auth_code')->create( $this->server->getAuthCodeStorage()->create(
$this->getId(), $this->getId(),
$this->getExpireTime(), $this->getExpireTime(),
$this->getSession()->getId(), $this->getSession()->getId(),
@ -104,7 +104,7 @@ class AuthCodeEntity extends AbstractTokenEntity
// Associate the scope with the token // Associate the scope with the token
foreach ($this->getScopes() as $scope) { foreach ($this->getScopes() as $scope) {
$this->server->getStorage('auth_code')->associateScope($this, $scope); $this->server->getAuthCodeStorage()->associateScope($this, $scope);
} }
return $this; return $this;
@ -115,6 +115,6 @@ class AuthCodeEntity extends AbstractTokenEntity
*/ */
public function expire() public function expire()
{ {
$this->server->getStorage('auth_code')->delete($this); $this->server->getAuthCodeStorage()->delete($this);
} }
} }

View File

@ -59,7 +59,7 @@ class RefreshTokenEntity extends AbstractTokenEntity
public function getAccessToken() public function getAccessToken()
{ {
if (! $this->accessTokenEntity instanceof AccessTokenEntity) { if (! $this->accessTokenEntity instanceof AccessTokenEntity) {
$this->accessTokenEntity = $this->server->getStorage('access_token')->get($this->accessTokenId); $this->accessTokenEntity = $this->server->getAccessTokenStorage()->get($this->accessTokenId);
} }
return $this->accessTokenEntity; return $this->accessTokenEntity;
@ -70,7 +70,7 @@ class RefreshTokenEntity extends AbstractTokenEntity
*/ */
public function save() public function save()
{ {
$this->server->getStorage('refresh_token')->create( $this->server->getRefreshTokenStorage()->create(
$this->getId(), $this->getId(),
$this->getExpireTime(), $this->getExpireTime(),
$this->getAccessToken()->getId() $this->getAccessToken()->getId()
@ -82,6 +82,6 @@ class RefreshTokenEntity extends AbstractTokenEntity
*/ */
public function expire() public function expire()
{ {
$this->server->getStorage('refresh_token')->delete($this); $this->server->getRefreshTokenStorage()->delete($this);
} }
} }

View File

@ -142,7 +142,7 @@ class SessionEntity
public function getScopes() public function getScopes()
{ {
if ($this->scopes === null) { if ($this->scopes === null) {
$this->scopes = $this->formatScopes($this->server->getStorage('session')->getScopes($this)); $this->scopes = $this->formatScopes($this->server->getSessionStorage()->getScopes($this));
} }
return $this->scopes; return $this->scopes;
@ -213,7 +213,7 @@ class SessionEntity
return $this->client; return $this->client;
} }
$this->client = $this->server->getStorage('client')->getBySession($this); $this->client = $this->server->getClientStorage()->getBySession($this);
return $this->client; return $this->client;
} }
@ -259,7 +259,7 @@ class SessionEntity
public function save() public function save()
{ {
// Save the session and get an identifier // Save the session and get an identifier
$id = $this->server->getStorage('session')->create( $id = $this->server->getSessionStorage()->create(
$this->getOwnerType(), $this->getOwnerType(),
$this->getOwnerId(), $this->getOwnerId(),
$this->getClient()->getId(), $this->getClient()->getId(),
@ -270,7 +270,7 @@ class SessionEntity
// Associate the scope with the session // Associate the scope with the session
foreach ($this->getScopes() as $scope) { foreach ($this->getScopes() as $scope) {
$this->server->getStorage('session')->associateScope($this, $scope); $this->server->getSessionStorage()->associateScope($this, $scope);
} }
} }
} }

View File

@ -153,7 +153,7 @@ abstract class AbstractGrant implements GrantTypeInterface
$scopes = []; $scopes = [];
foreach ($scopesList as $scopeItem) { foreach ($scopesList as $scopeItem) {
$scope = $this->server->getStorage('scope')->get( $scope = $this->server->getScopeStorage()->get(
$scopeItem, $scopeItem,
$this->getIdentifier(), $this->getIdentifier(),
$client->getId() $client->getId()

View File

@ -85,7 +85,7 @@ class AuthCodeGrant extends AbstractGrant
} }
// Validate client ID and redirect URI // Validate client ID and redirect URI
$client = $this->server->getStorage('client')->get( $client = $this->server->getClientStorage()->get(
$clientId, $clientId,
null, null,
$redirectUri, $redirectUri,
@ -186,7 +186,7 @@ class AuthCodeGrant extends AbstractGrant
} }
// Validate client ID and client secret // Validate client ID and client secret
$client = $this->server->getStorage('client')->get( $client = $this->server->getClientStorage()->get(
$clientId, $clientId,
$clientSecret, $clientSecret,
$redirectUri, $redirectUri,
@ -204,7 +204,7 @@ class AuthCodeGrant extends AbstractGrant
throw new Exception\InvalidRequestException('code'); throw new Exception\InvalidRequestException('code');
} }
$code = $this->server->getStorage('auth_code')->get($authCode); $code = $this->server->getAuthCodeStorage()->get($authCode);
if (($code instanceof AuthCodeEntity) === false) { if (($code instanceof AuthCodeEntity) === false) {
throw new Exception\InvalidRequestException('code'); throw new Exception\InvalidRequestException('code');
} }

View File

@ -71,7 +71,7 @@ class ClientCredentialsGrant extends AbstractGrant
} }
// Validate client ID and client secret // Validate client ID and client secret
$client = $this->server->getStorage('client')->get( $client = $this->server->getClientStorage()->get(
$clientId, $clientId,
$clientSecret, $clientSecret,
null, null,

View File

@ -95,7 +95,7 @@ class PasswordGrant extends AbstractGrant
} }
// Validate client ID and client secret // Validate client ID and client secret
$client = $this->server->getStorage('client')->get( $client = $this->server->getClientStorage()->get(
$clientId, $clientId,
$clientSecret, $clientSecret,
null, null,

View File

@ -76,7 +76,7 @@ class RefreshTokenGrant extends AbstractGrant
} }
// Validate client ID and client secret // Validate client ID and client secret
$client = $this->server->getStorage('client')->get( $client = $this->server->getClientStorage()->get(
$clientId, $clientId,
$clientSecret, $clientSecret,
null, null,
@ -94,7 +94,7 @@ class RefreshTokenGrant extends AbstractGrant
} }
// Validate refresh token // Validate refresh token
$oldRefreshToken = $this->server->getStorage('refresh_token')->get($oldRefreshTokenParam); $oldRefreshToken = $this->server->getRefreshTokenStorage()->get($oldRefreshTokenParam);
if (($oldRefreshToken instanceof RefreshTokenEntity) === false) { if (($oldRefreshToken instanceof RefreshTokenEntity) === false) {
throw new Exception\InvalidRefreshException(); throw new Exception\InvalidRefreshException();
@ -136,7 +136,7 @@ class RefreshTokenGrant extends AbstractGrant
} }
// Expire the old token and save the new one // Expire the old token and save the new one
$oldAccessToken->expire($this->server->getStorage('access_token')); $oldAccessToken->expire();
$newAccessToken->save(); $newAccessToken->save();
$this->server->getTokenType()->setSession($session); $this->server->getTokenType()->setSession($session);

View File

@ -27,7 +27,7 @@ class ResourceServer extends AbstractServer
{ {
/** /**
* The access token * The access token
* @var League\OAuth2\Server\AccessToken * @var \League\OAuth2\Server\Entity\AccessTokenEntity
*/ */
protected $accessToken; protected $accessToken;
@ -51,17 +51,10 @@ class ResourceServer extends AbstractServer
ClientInterface $clientStorage, ClientInterface $clientStorage,
ScopeInterface $scopeStorage ScopeInterface $scopeStorage
) { ) {
$sessionStorage->setServer($this); $this->setSessionStorage($sessionStorage);
$this->setStorage('session', $sessionStorage); $this->setAccessTokenStorage($accessTokenStorage);
$this->setClientStorage($clientStorage);
$accessTokenStorage->setServer($this); $this->setScopeStorage($scopeStorage);
$this->setStorage('access_token', $accessTokenStorage);
$clientStorage->setServer($this);
$this->setStorage('client', $clientStorage);
$scopeStorage->setServer($this);
$this->setStorage('scope', $scopeStorage);
// Set Bearer as the default token type // Set Bearer as the default token type
$this->setTokenType(new Bearer); $this->setTokenType(new Bearer);
@ -71,20 +64,6 @@ class ResourceServer extends AbstractServer
return $this; return $this;
} }
/**
* Set the storage
* @param string $type Storage type
* @param mixed $storage Storage class
* @return self
*/
protected function setStorage($type, $storage)
{
$storage->setServer($this);
$this->storages[$type] = $storage;
return $this;
}
/** /**
* Returns the query string key for the access token. * Returns the query string key for the access token.
* @return string * @return string
@ -185,7 +164,7 @@ class ResourceServer extends AbstractServer
: $this->determineAccessToken($headersOnly); : $this->determineAccessToken($headersOnly);
// Set the access token // Set the access token
$this->accessToken = $this->storages['access_token']->get($accessTokenString); $this->accessToken = $this->getAccessTokenStorage()->get($accessTokenString);
if (!$this->accessToken instanceof AccessTokenEntity) { if (!$this->accessToken instanceof AccessTokenEntity) {
throw new Exception\AccessDeniedException; throw new Exception\AccessDeniedException;

View File

@ -25,11 +25,4 @@ class AbstractServerTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($server2->getRequest() instanceof \Symfony\Component\HttpFoundation\Request); $this->assertTrue($server2->getRequest() instanceof \Symfony\Component\HttpFoundation\Request);
} }
public function testGetStorageException()
{
$this->setExpectedException('League\OAuth2\Server\Exception\ServerErrorException');
$server = new StubAbstractServer();
$server->getStorage('foobar');
}
} }

View File

@ -34,7 +34,7 @@ class AuthorizationServerTest extends \PHPUnit_Framework_TestCase
$this->assertSame($server->getResponseTypes(), ['foobar']); $this->assertSame($server->getResponseTypes(), ['foobar']);
$this->assertTrue($server->scopeParamRequired()); $this->assertTrue($server->scopeParamRequired());
$this->assertTrue($server->stateParamRequired()); $this->assertTrue($server->stateParamRequired());
$this->assertTrue($server->getStorage('scope') instanceof ScopeInterface); $this->assertTrue($server->getScopeStorage() instanceof ScopeInterface);
$this->assertEquals('foobar', $server->getDefaultScope()); $this->assertEquals('foobar', $server->getDefaultScope());
$this->assertEquals(',', $server->getScopeDelimeter()); $this->assertEquals(',', $server->getScopeDelimeter());
$this->assertEquals(1, $server->getAccessTokenTTL()); $this->assertEquals(1, $server->getAccessTokenTTL());

View File

@ -29,8 +29,8 @@ class AccessTokenTest extends \PHPUnit_Framework_TestCase
); );
$sessionStorage->shouldReceive('setServer'); $sessionStorage->shouldReceive('setServer');
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage); $server->shouldReceive('getSessionStorage')->andReturn($sessionStorage);
$server->shouldReceive('getStorage')->with('access_token')->andReturn($accessTokenStorage); $server->shouldReceive('getAccessTokenStorage')->andReturn($accessTokenStorage);
$server->setAccessTokenStorage($accessTokenStorage); $server->setAccessTokenStorage($accessTokenStorage);
$server->setSessionStorage($sessionStorage); $server->setSessionStorage($sessionStorage);
@ -49,7 +49,7 @@ class AccessTokenTest extends \PHPUnit_Framework_TestCase
$accessTokenStorage->shouldReceive('delete'); $accessTokenStorage->shouldReceive('delete');
$accessTokenStorage->shouldReceive('setServer'); $accessTokenStorage->shouldReceive('setServer');
$server->shouldReceive('getStorage')->with('access_token')->andReturn($accessTokenStorage); $server->shouldReceive('getAccessTokenStorage')->andReturn($accessTokenStorage);
$server->setAccessTokenStorage($accessTokenStorage); $server->setAccessTokenStorage($accessTokenStorage);

View File

@ -40,7 +40,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
(new ScopeEntity($server))->hydrate(['id' => 'foo']) (new ScopeEntity($server))->hydrate(['id' => 'foo'])
]); ]);
$server->shouldReceive('getStorage')->with('auth_code')->andReturn($authCodeStorage); $server->shouldReceive('getAuthCodeStorage')->andReturn($authCodeStorage);
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface'); $sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
$sessionStorage->shouldReceive('getByAuthCode')->andReturn( $sessionStorage->shouldReceive('getByAuthCode')->andReturn(
@ -48,7 +48,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
); );
$sessionStorage->shouldReceive('setServer'); $sessionStorage->shouldReceive('setServer');
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage); $server->shouldReceive('getSessionStorage')->andReturn($sessionStorage);
$server->setAuthCodeStorage($authCodeStorage); $server->setAuthCodeStorage($authCodeStorage);
$server->setSessionStorage($sessionStorage); $server->setSessionStorage($sessionStorage);

View File

@ -47,7 +47,7 @@ class RefreshTokenEntityTest extends \PHPUnit_Framework_TestCase
$refreshTokenStorage->shouldReceive('setServer'); $refreshTokenStorage->shouldReceive('setServer');
$refreshTokenStorage->shouldReceive('associateScope'); $refreshTokenStorage->shouldReceive('associateScope');
$server->shouldReceive('getStorage')->with('refresh_token')->andReturn($refreshTokenStorage); $server->shouldReceive('getRefreshTokenStorage')->andReturn($refreshTokenStorage);
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface'); $accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
$accessTokenStorage->shouldReceive('setServer'); $accessTokenStorage->shouldReceive('setServer');
@ -58,7 +58,7 @@ class RefreshTokenEntityTest extends \PHPUnit_Framework_TestCase
(new ScopeEntity($server))->hydrate(['id' => 'foo']) (new ScopeEntity($server))->hydrate(['id' => 'foo'])
]); ]);
$server->shouldReceive('getStorage')->with('access_token')->andReturn($accessTokenStorage); $server->shouldReceive('getAccessTokenStorage')->andReturn($accessTokenStorage);
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface'); $sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
$sessionStorage->shouldReceive('getByAccessToken')->andReturn( $sessionStorage->shouldReceive('getByAccessToken')->andReturn(
@ -66,7 +66,7 @@ class RefreshTokenEntityTest extends \PHPUnit_Framework_TestCase
); );
$sessionStorage->shouldReceive('setServer'); $sessionStorage->shouldReceive('setServer');
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage); $server->shouldReceive('getSessionStorage')->andReturn($sessionStorage);
$server->setAccessTokenStorage($accessTokenStorage); $server->setAccessTokenStorage($accessTokenStorage);
$server->setRefreshTokenStorage($refreshTokenStorage); $server->setRefreshTokenStorage($refreshTokenStorage);
@ -84,7 +84,7 @@ class RefreshTokenEntityTest extends \PHPUnit_Framework_TestCase
$refreshTokenStorage->shouldReceive('delete'); $refreshTokenStorage->shouldReceive('delete');
$refreshTokenStorage->shouldReceive('setServer'); $refreshTokenStorage->shouldReceive('setServer');
$server->shouldReceive('getStorage')->with('refresh_token')->andReturn($refreshTokenStorage); $server->shouldReceive('getRefreshTokenStorage')->andReturn($refreshTokenStorage);
$server->setRefreshTokenStorage($refreshTokenStorage); $server->setRefreshTokenStorage($refreshTokenStorage);

View File

@ -81,7 +81,7 @@ class SessionTest extends \PHPUnit_Framework_TestCase
$accessTokenStorage->shouldReceive('setServer'); $accessTokenStorage->shouldReceive('setServer');
$server->setAccessTokenStorage($accessTokenStorage); $server->setAccessTokenStorage($accessTokenStorage);
$server->shouldReceive('getStorage')->with('access_token')->andReturn($accessTokenStorage); $server->shouldReceive('getAccessTokenStorage')->andReturn($accessTokenStorage);
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface'); $sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
$sessionStorage->shouldReceive('getScopes')->andReturn( $sessionStorage->shouldReceive('getScopes')->andReturn(
@ -90,7 +90,7 @@ class SessionTest extends \PHPUnit_Framework_TestCase
$sessionStorage->shouldReceive('setServer'); $sessionStorage->shouldReceive('setServer');
$server->setSessionStorage($sessionStorage); $server->setSessionStorage($sessionStorage);
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage); $server->shouldReceive('getSessionStorage')->andReturn($sessionStorage);
$entity = new SessionEntity($server); $entity = new SessionEntity($server);
$this->assertEquals($entity->getScopes(), []); $this->assertEquals($entity->getScopes(), []);
@ -106,7 +106,7 @@ class SessionTest extends \PHPUnit_Framework_TestCase
$accessTokenStorage->shouldReceive('setServer'); $accessTokenStorage->shouldReceive('setServer');
$server->setAccessTokenStorage($accessTokenStorage); $server->setAccessTokenStorage($accessTokenStorage);
$server->shouldReceive('getStorage')->with('access_token')->andReturn($accessTokenStorage); $server->shouldReceive('getAccessTokenStorage')->andReturn($accessTokenStorage);
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface'); $sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
$sessionStorage->shouldReceive('getScopes')->andReturn( $sessionStorage->shouldReceive('getScopes')->andReturn(
@ -115,7 +115,7 @@ class SessionTest extends \PHPUnit_Framework_TestCase
$sessionStorage->shouldReceive('setServer'); $sessionStorage->shouldReceive('setServer');
$server->setSessionStorage($sessionStorage); $server->setSessionStorage($sessionStorage);
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage); $server->shouldReceive('getSessionStorage')->andReturn($sessionStorage);
$entity = new SessionEntity($server); $entity = new SessionEntity($server);
$this->assertFalse($entity->hasScope('foo')); $this->assertFalse($entity->hasScope('foo'));
@ -135,7 +135,7 @@ class SessionTest extends \PHPUnit_Framework_TestCase
(new ScopeEntity($server))->hydrate(['id' => 'foo']) (new ScopeEntity($server))->hydrate(['id' => 'foo'])
]); ]);
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage); $server->shouldReceive('getSessionStorage')->andReturn($sessionStorage);
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
$clientStorage->shouldReceive('getBySession')->andReturn( $clientStorage->shouldReceive('getBySession')->andReturn(
@ -143,7 +143,7 @@ class SessionTest extends \PHPUnit_Framework_TestCase
); );
$clientStorage->shouldReceive('setServer'); $clientStorage->shouldReceive('setServer');
$server->shouldReceive('getStorage')->with('client')->andReturn($clientStorage); $server->shouldReceive('getClientStorage')->andReturn($clientStorage);
$server->setSessionStorage($sessionStorage); $server->setSessionStorage($sessionStorage);
$server->setClientStorage($clientStorage); $server->setClientStorage($clientStorage);