From de8f6ff53900229c2263dac218bca5cd13ac9139 Mon Sep 17 00:00:00 2001 From: Frederik Bosch Date: Fri, 25 Mar 2016 14:09:26 +0100 Subject: [PATCH] add getNewAccessToken getNewRefreshToken and getNewAuthCode to repositories --- src/Grant/AbstractGrant.php | 13 ++--- .../AbstractAccessTokenRepository.php | 46 ++++++++++++++++ .../AbstractAuthCodeRepository.php | 53 +++++++++++++++++++ .../AbstractRefreshTokenRepository.php | 53 +++++++++++++++++++ .../AccessTokenRepositoryInterface.php | 12 +++++ .../AuthCodeRepositoryInterface.php | 7 +++ .../RefreshTokenRepositoryInterface.php | 7 +++ tests/Grant/AbstractGrantTest.php | 8 +++ tests/Grant/AuthCodeGrantTest.php | 15 +++++- tests/Grant/ClientCredentialsGrantTest.php | 2 + tests/Grant/ImplicitGrantTest.php | 2 + tests/Grant/PasswordGrantTest.php | 4 ++ tests/Grant/RefreshTokenGrantTest.php | 6 +++ .../AuthenticationServerMiddlewareTest.php | 6 ++- tests/ServerTest.php | 12 ++++- 15 files changed, 233 insertions(+), 13 deletions(-) create mode 100644 src/Repositories/AbstractAccessTokenRepository.php create mode 100644 src/Repositories/AbstractAuthCodeRepository.php create mode 100644 src/Repositories/AbstractRefreshTokenRepository.php diff --git a/src/Grant/AbstractGrant.php b/src/Grant/AbstractGrant.php index 14a46e35..7b68804e 100644 --- a/src/Grant/AbstractGrant.php +++ b/src/Grant/AbstractGrant.php @@ -12,12 +12,9 @@ namespace League\OAuth2\Server\Grant; use League\Event\EmitterAwareTrait; use League\OAuth2\Server\CryptTrait; -use League\OAuth2\Server\Entities\AccessTokenEntity; -use League\OAuth2\Server\Entities\AuthCodeEntity; use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface; use League\OAuth2\Server\Entities\Interfaces\ScopeEntityInterface; -use League\OAuth2\Server\Entities\RefreshTokenEntity; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; use League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface; @@ -291,11 +288,11 @@ abstract class AbstractGrant implements GrantTypeInterface $userIdentifier, array $scopes = [] ) { - $accessToken = new AccessTokenEntity(); - $accessToken->setIdentifier($this->generateUniqueIdentifier()); - $accessToken->setExpiryDateTime((new \DateTime())->add($accessTokenTTL)); + $accessToken = $this->accessTokenRepository->getNewToken($client, $scopes, $userIdentifier); $accessToken->setClient($client); $accessToken->setUserIdentifier($userIdentifier); + $accessToken->setIdentifier($this->generateUniqueIdentifier()); + $accessToken->setExpiryDateTime((new \DateTime())->add($accessTokenTTL)); foreach ($scopes as $scope) { $accessToken->addScope($scope); @@ -324,7 +321,7 @@ abstract class AbstractGrant implements GrantTypeInterface $redirectUri, array $scopes = [] ) { - $authCode = new AuthCodeEntity(); + $authCode = $this->authCodeRepository->getNewAuthCode(); $authCode->setIdentifier($this->generateUniqueIdentifier()); $authCode->setExpiryDateTime((new \DateTime())->add($authCodeTTL)); $authCode->setClient($client); @@ -347,7 +344,7 @@ abstract class AbstractGrant implements GrantTypeInterface */ protected function issueRefreshToken(AccessTokenEntityInterface $accessToken) { - $refreshToken = new RefreshTokenEntity(); + $refreshToken = $this->refreshTokenRepository->getNewRefreshToken(); $refreshToken->setIdentifier($this->generateUniqueIdentifier()); $refreshToken->setExpiryDateTime((new \DateTime())->add($this->refreshTokenTTL)); $refreshToken->setAccessToken($accessToken); diff --git a/src/Repositories/AbstractAccessTokenRepository.php b/src/Repositories/AbstractAccessTokenRepository.php new file mode 100644 index 00000000..321abc65 --- /dev/null +++ b/src/Repositories/AbstractAccessTokenRepository.php @@ -0,0 +1,46 @@ + + * @copyright Copyright (c) Alex Bilbie + * @license http://mit-license.org/ + * + * @link https://github.com/thephpleague/oauth2-server + */ +namespace League\OAuth2\Server\Repositories; + +use League\OAuth2\Server\Entities\AuthCodeEntity; +use League\OAuth2\Server\Entities\Interfaces\AuthCodeEntityInterface; + +/** + * Auth code storage abstract class. + */ +abstract class AbstractAuthCodeRepository implements AuthCodeRepositoryInterface +{ + /** + * Creates a new AuthCode + * + * @return \League\OAuth2\Server\Entities\Interfaces\AuthCodeEntityInterface + */ + public function getNewAuthCode() + { + return new AuthCodeEntity(); + } + + /** + * Persists a new auth code to permanent storage. + * + * @param \League\OAuth2\Server\Entities\Interfaces\AuthCodeEntityInterface $authCodeEntity + */ + abstract public function persistNewAuthCode(AuthCodeEntityInterface $authCodeEntity); + + /** + * Revoke an auth code. + * + * @param string $codeId + */ + abstract public function revokeAuthCode($codeId); + + /** + * Check if the auth code has been revoked. + * + * @param string $codeId + * + * @return bool Return true if this code has been revoked + */ + abstract public function isAuthCodeRevoked($codeId); +} diff --git a/src/Repositories/AbstractRefreshTokenRepository.php b/src/Repositories/AbstractRefreshTokenRepository.php new file mode 100644 index 00000000..ff786f94 --- /dev/null +++ b/src/Repositories/AbstractRefreshTokenRepository.php @@ -0,0 +1,53 @@ + + * @copyright Copyright (c) Alex Bilbie + * @license http://mit-license.org/ + * + * @link https://github.com/thephpleague/oauth2-server + */ +namespace League\OAuth2\Server\Repositories; + +use League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface; +use League\OAuth2\Server\Entities\RefreshTokenEntity; + +/** + * Refresh token abstract class. + */ +abstract class AbstractRefreshTokenRepository implements RefreshTokenRepositoryInterface +{ + /** + * Creates a new refresh token + * + * @return RefreshTokenEntityInterface + */ + public function getNewRefreshToken() + { + return new RefreshTokenEntity(); + } + + /** + * Create a new refresh token_name. + * + * @param \League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface $refreshTokenEntity + */ + abstract public function persistNewRefreshToken(RefreshTokenEntityInterface $refreshTokenEntity); + + /** + * Revoke the refresh token. + * + * @param string $tokenId + */ + abstract public function revokeRefreshToken($tokenId); + + /** + * Check if the refresh token has been revoked. + * + * @param string $tokenId + * + * @return bool Return true if this token has been revoked + */ + abstract public function isRefreshTokenRevoked($tokenId); +} diff --git a/src/Repositories/AccessTokenRepositoryInterface.php b/src/Repositories/AccessTokenRepositoryInterface.php index d9e054d8..a6d725a2 100644 --- a/src/Repositories/AccessTokenRepositoryInterface.php +++ b/src/Repositories/AccessTokenRepositoryInterface.php @@ -11,12 +11,24 @@ namespace League\OAuth2\Server\Repositories; use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface; +use League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface; /** * Access token interface. */ interface AccessTokenRepositoryInterface extends RepositoryInterface { + /** + * Create a new access token + * + * @param \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface $clientEntity + * @param \League\OAuth2\Server\Entities\Interfaces\ScopeEntityInterface[] $scopes + * @param mixed $userIdentifier + * + * @return AccessTokenEntityInterface + */ + public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, $userIdentifier = null); + /** * Persists a new access token to permanent storage. * diff --git a/src/Repositories/AuthCodeRepositoryInterface.php b/src/Repositories/AuthCodeRepositoryInterface.php index 16c48742..d1da7d44 100644 --- a/src/Repositories/AuthCodeRepositoryInterface.php +++ b/src/Repositories/AuthCodeRepositoryInterface.php @@ -17,6 +17,13 @@ use League\OAuth2\Server\Entities\Interfaces\AuthCodeEntityInterface; */ interface AuthCodeRepositoryInterface extends RepositoryInterface { + /** + * Creates a new AuthCode + * + * @return \League\OAuth2\Server\Entities\Interfaces\AuthCodeEntityInterface + */ + public function getNewAuthCode(); + /** * Persists a new auth code to permanent storage. * diff --git a/src/Repositories/RefreshTokenRepositoryInterface.php b/src/Repositories/RefreshTokenRepositoryInterface.php index d987ab22..e857e2ff 100644 --- a/src/Repositories/RefreshTokenRepositoryInterface.php +++ b/src/Repositories/RefreshTokenRepositoryInterface.php @@ -17,6 +17,13 @@ use League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface; */ interface RefreshTokenRepositoryInterface extends RepositoryInterface { + /** + * Creates a new refresh token + * + * @return RefreshTokenEntityInterface + */ + public function getNewRefreshToken(); + /** * Create a new refresh token_name. * diff --git a/tests/Grant/AbstractGrantTest.php b/tests/Grant/AbstractGrantTest.php index 1161ebc4..ac5c2a0a 100644 --- a/tests/Grant/AbstractGrantTest.php +++ b/tests/Grant/AbstractGrantTest.php @@ -4,9 +4,11 @@ namespace LeagueTests\Grant; use League\Event\Emitter; use League\OAuth2\Server\Entities\AccessTokenEntity; +use League\OAuth2\Server\Entities\AuthCodeEntity; use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\Interfaces\AuthCodeEntityInterface; use League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface; +use League\OAuth2\Server\Entities\RefreshTokenEntity; use League\OAuth2\Server\Grant\AbstractGrant; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; use League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface; @@ -227,6 +229,10 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase public function testIssueRefreshToken() { $refreshTokenRepoMock = $this->getMock(RefreshTokenRepositoryInterface::class); + $refreshTokenRepoMock + ->expects($this->once()) + ->method('getNewRefreshToken') + ->willReturn(new RefreshTokenEntity()); /** @var AbstractGrant $grantMock */ $grantMock = $this->getMockForAbstractClass(AbstractGrant::class); @@ -248,6 +254,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase public function testIssueAccessToken() { $accessTokenRepoMock = $this->getMock(AccessTokenRepositoryInterface::class); + $accessTokenRepoMock->method('getNewToken')->willReturn(new AccessTokenEntity()); /** @var AbstractGrant $grantMock */ $grantMock = $this->getMockForAbstractClass(AbstractGrant::class); @@ -272,6 +279,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase public function testIssueAuthCode() { $authCodeRepoMock = $this->getMock(AuthCodeRepositoryInterface::class); + $authCodeRepoMock->expects($this->once())->method('getNewAuthCode')->willReturn(new AuthCodeEntity()); /** @var AbstractGrant $grantMock */ $grantMock = $this->getMockForAbstractClass(AbstractGrant::class); diff --git a/tests/Grant/AuthCodeGrantTest.php b/tests/Grant/AuthCodeGrantTest.php index 1dfb6974..f56c64e6 100644 --- a/tests/Grant/AuthCodeGrantTest.php +++ b/tests/Grant/AuthCodeGrantTest.php @@ -2,8 +2,11 @@ namespace LeagueTests\Grant; +use League\OAuth2\Server\Entities\AccessTokenEntity; +use League\OAuth2\Server\Entities\AuthCodeEntity; use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface; +use League\OAuth2\Server\Entities\RefreshTokenEntity; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Grant\AuthCodeGrant; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; @@ -90,8 +93,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase $scopeRepositoryMock = $this->getMockBuilder(ScopeRepositoryInterface::class)->getMock(); $scopeRepositoryMock->method('finalizeScopes')->willReturnArgument(0); + $authCodeRepoMock = $this->getMock(AuthCodeRepositoryInterface::class); + $authCodeRepoMock->expects($this->once())->method('getNewAuthCode')->willReturn(new AuthCodeEntity()); + $grant = new AuthCodeGrant( - $this->getMock(AuthCodeRepositoryInterface::class), + $authCodeRepoMock, $this->getMock(RefreshTokenRepositoryInterface::class), $userRepositoryMock, new \DateInterval('PT10M') @@ -417,8 +423,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase $scopeRepositoryMock = $this->getMockBuilder(ScopeRepositoryInterface::class)->getMock(); $scopeRepositoryMock->method('finalizeScopes')->willReturnArgument(0); + $authCodeRepoMock = $this->getMock(AuthCodeRepositoryInterface::class); + $authCodeRepoMock->expects($this->once())->method('getNewAuthCode')->willReturn(new AuthCodeEntity()); + $grant = new AuthCodeGrant( - $this->getMock(AuthCodeRepositoryInterface::class), + $authCodeRepoMock, $this->getMock(RefreshTokenRepositoryInterface::class), $userRepositoryMock, new \DateInterval('PT10M') @@ -592,10 +601,12 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase $scopeRepositoryMock->method('getScopeEntityByIdentifier')->willReturn($scopeEntity); $accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(); + $accessTokenRepositoryMock->method('getNewToken')->willReturn(new AccessTokenEntity()); $accessTokenRepositoryMock->method('persistNewAccessToken')->willReturnSelf(); $refreshTokenRepositoryMock = $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(); $refreshTokenRepositoryMock->method('persistNewRefreshToken')->willReturnSelf(); + $refreshTokenRepositoryMock->method('getNewRefreshToken')->willReturn(new RefreshTokenEntity()); $grant = new AuthCodeGrant( $this->getMock(AuthCodeRepositoryInterface::class), diff --git a/tests/Grant/ClientCredentialsGrantTest.php b/tests/Grant/ClientCredentialsGrantTest.php index c41528c5..a6b66dcd 100644 --- a/tests/Grant/ClientCredentialsGrantTest.php +++ b/tests/Grant/ClientCredentialsGrantTest.php @@ -2,6 +2,7 @@ namespace LeagueTests\Grant; +use League\OAuth2\Server\Entities\AccessTokenEntity; use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface; use League\OAuth2\Server\Grant\ClientCredentialsGrant; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; @@ -27,6 +28,7 @@ class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase $clientRepositoryMock->method('getClientEntity')->willReturn($client); $accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(); + $accessTokenRepositoryMock->method('getNewToken')->willReturn(new AccessTokenEntity()); $accessTokenRepositoryMock->method('persistNewAccessToken')->willReturnSelf(); $scopeRepositoryMock = $this->getMockBuilder(ScopeRepositoryInterface::class)->getMock(); diff --git a/tests/Grant/ImplicitGrantTest.php b/tests/Grant/ImplicitGrantTest.php index 06525b9c..58da9213 100644 --- a/tests/Grant/ImplicitGrantTest.php +++ b/tests/Grant/ImplicitGrantTest.php @@ -2,6 +2,7 @@ namespace LeagueTests\Grant; +use League\OAuth2\Server\Entities\AccessTokenEntity; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Grant\ImplicitGrant; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; @@ -68,6 +69,7 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase $userRepositoryMock->method('getUserEntityByUserCredentials')->willReturn($userEntity); $accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(); + $accessTokenRepositoryMock->method('getNewToken')->willReturn(new AccessTokenEntity()); $accessTokenRepositoryMock->method('persistNewAccessToken')->willReturnSelf(); $scopeRepositoryMock = $this->getMockBuilder(ScopeRepositoryInterface::class)->getMock(); diff --git a/tests/Grant/PasswordGrantTest.php b/tests/Grant/PasswordGrantTest.php index 31043d1a..eb72c905 100644 --- a/tests/Grant/PasswordGrantTest.php +++ b/tests/Grant/PasswordGrantTest.php @@ -2,8 +2,10 @@ namespace LeagueTests\Grant; +use League\OAuth2\Server\Entities\AccessTokenEntity; use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface; +use League\OAuth2\Server\Entities\RefreshTokenEntity; use League\OAuth2\Server\Grant\PasswordGrant; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; use League\OAuth2\Server\Repositories\ClientRepositoryInterface; @@ -34,6 +36,7 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase $clientRepositoryMock->method('getClientEntity')->willReturn($client); $accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(); + $accessTokenRepositoryMock->method('getNewToken')->willReturn(new AccessTokenEntity()); $accessTokenRepositoryMock->method('persistNewAccessToken')->willReturnSelf(); $userRepositoryMock = $this->getMockBuilder(UserRepositoryInterface::class)->getMock(); @@ -42,6 +45,7 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase $refreshTokenRepositoryMock = $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(); $refreshTokenRepositoryMock->method('persistNewRefreshToken')->willReturnSelf(); + $refreshTokenRepositoryMock->method('getNewRefreshToken')->willReturn(new RefreshTokenEntity()); $scopeRepositoryMock = $this->getMockBuilder(ScopeRepositoryInterface::class)->getMock(); $scopeRepositoryMock->method('finalizeScopes')->willReturnArgument(0); diff --git a/tests/Grant/RefreshTokenGrantTest.php b/tests/Grant/RefreshTokenGrantTest.php index 719b28c3..acd77a39 100644 --- a/tests/Grant/RefreshTokenGrantTest.php +++ b/tests/Grant/RefreshTokenGrantTest.php @@ -2,8 +2,10 @@ namespace LeagueTests\Grant; +use League\OAuth2\Server\Entities\AccessTokenEntity; use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface; +use League\OAuth2\Server\Entities\RefreshTokenEntity; use League\OAuth2\Server\Grant\RefreshTokenGrant; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; use League\OAuth2\Server\Repositories\ClientRepositoryInterface; @@ -48,11 +50,13 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase $scopeRepositoryMock->method('getScopeEntityByIdentifier')->willReturn($scopeEntity); $accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(); + $accessTokenRepositoryMock->method('getNewToken')->willReturn(new AccessTokenEntity()); $accessTokenRepositoryMock ->expects($this->once()) ->method('persistNewAccessToken')->willReturnSelf(); $refreshTokenRepositoryMock = $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(); + $refreshTokenRepositoryMock->method('getNewRefreshToken')->willReturn(new RefreshTokenEntity()); $refreshTokenRepositoryMock ->expects($this->once()) ->method('persistNewRefreshToken')->willReturnSelf(); @@ -102,10 +106,12 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase $clientRepositoryMock->method('getClientEntity')->willReturn($client); $accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(); + $accessTokenRepositoryMock->method('getNewToken')->willReturn(new AccessTokenEntity()); $accessTokenRepositoryMock->method('persistNewAccessToken')->willReturnSelf(); $refreshTokenRepositoryMock = $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(); $refreshTokenRepositoryMock->method('persistNewRefreshToken')->willReturnSelf(); + $refreshTokenRepositoryMock->method('getNewRefreshToken')->willReturn(new RefreshTokenEntity()); $scope = new ScopeEntity(); $scope->setIdentifier('foo'); diff --git a/tests/Middleware/AuthenticationServerMiddlewareTest.php b/tests/Middleware/AuthenticationServerMiddlewareTest.php index 4acd5c89..9b259699 100644 --- a/tests/Middleware/AuthenticationServerMiddlewareTest.php +++ b/tests/Middleware/AuthenticationServerMiddlewareTest.php @@ -2,6 +2,7 @@ namespace LeagueTests\Middleware; +use League\OAuth2\Server\Entities\AccessTokenEntity; use League\OAuth2\Server\Grant\ClientCredentialsGrant; use League\OAuth2\Server\Middleware\AuthenticationServerMiddleware; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; @@ -23,9 +24,12 @@ class AuthenticationServerMiddlewareTest extends \PHPUnit_Framework_TestCase $scopeRepositoryMock = $this->getMockBuilder(ScopeRepositoryInterface::class)->getMock(); $scopeRepositoryMock->method('finalizeScopes')->willReturnArgument(0); + $accessRepositoryMock = $this->getMock(AccessTokenRepositoryInterface::class); + $accessRepositoryMock->method('getNewToken')->willReturn(new AccessTokenEntity()); + $server = new Server( $clientRepository, - $this->getMock(AccessTokenRepositoryInterface::class), + $accessRepositoryMock, $scopeRepositoryMock, '', '', diff --git a/tests/ServerTest.php b/tests/ServerTest.php index f61818cf..d8367e85 100644 --- a/tests/ServerTest.php +++ b/tests/ServerTest.php @@ -2,6 +2,8 @@ namespace LeagueTests; +use League\OAuth2\Server\Entities\AccessTokenEntity; +use League\OAuth2\Server\Entities\AuthCodeEntity; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Grant\AuthCodeGrant; use League\OAuth2\Server\Grant\ClientCredentialsGrant; @@ -51,9 +53,12 @@ class ServerTest extends \PHPUnit_Framework_TestCase $scopeRepositoryMock = $this->getMockBuilder(ScopeRepositoryInterface::class)->getMock(); $scopeRepositoryMock->method('finalizeScopes')->willReturnArgument(0); + $accessTokenRepositoryMock = $this->getMock(AccessTokenRepositoryInterface::class); + $accessTokenRepositoryMock->method('getNewToken')->willReturn(new AccessTokenEntity()); + $server = new Server( $clientRepository, - $this->getMock(AccessTokenRepositoryInterface::class), + $accessTokenRepositoryMock, $scopeRepositoryMock, '', '', @@ -93,9 +98,12 @@ class ServerTest extends \PHPUnit_Framework_TestCase $userRepository = $this->getMock(UserRepositoryInterface::class); $userRepository->method('getUserEntityByUserCredentials')->willReturn(new UserEntity()); + $authCodeRepoMock = $this->getMock(AuthCodeRepositoryInterface::class); + $authCodeRepoMock->expects($this->once())->method('getNewAuthCode')->willReturn(new AuthCodeEntity()); + $server->enableGrantType( new AuthCodeGrant( - $this->getMock(AuthCodeRepositoryInterface::class), + $authCodeRepoMock, $this->getMock(RefreshTokenRepositoryInterface::class), $userRepository, new \DateInterval('PT1H')