Skip to content

Commit 9217137

Browse files
add tests
1 parent 981c4da commit 9217137

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

tests/Grant/RefreshTokenGrantTest.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace LeagueTests\Grant;
66

77
use DateInterval;
8+
use Laminas\Diactoros\Response;
89
use Laminas\Diactoros\ServerRequest;
910
use League\OAuth2\Server\CryptKey;
1011
use League\OAuth2\Server\Entities\RefreshTokenEntityInterface;
@@ -14,6 +15,7 @@
1415
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
1516
use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
1617
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
18+
use League\OAuth2\Server\ResponseTypes\BearerTokenResponse;
1719
use LeagueTests\Stubs\AccessTokenEntity;
1820
use LeagueTests\Stubs\ClientEntity;
1921
use LeagueTests\Stubs\CryptTraitStub;
@@ -688,11 +690,15 @@ public function testUnrevokedRefreshToken(): void
688690
$scopeRepositoryMock->method('getScopeEntityByIdentifier')->willReturn($scopeEntity);
689691
$scopeRepositoryMock->method('finalizeScopes')->willReturn([$scopeEntity]);
690692

693+
$accessTokenEntity = new AccessTokenEntity();
694+
$accessTokenEntity->setClient($client);
695+
691696
$accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock();
692-
$accessTokenRepositoryMock->method('getNewToken')->willReturn(new AccessTokenEntity());
697+
$accessTokenRepositoryMock->method('getNewToken')->willReturn($accessTokenEntity);
693698
$accessTokenRepositoryMock->expects(self::once())->method('persistNewAccessToken')->willReturnSelf();
694699

695700
$refreshTokenRepositoryMock = $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock();
701+
$refreshTokenRepositoryMock->method('getNewRefreshToken')->willReturn(new RefreshTokenEntity());
696702
$refreshTokenRepositoryMock->method('isRefreshTokenRevoked')->willReturn(false);
697703
$refreshTokenRepositoryMock->expects(self::never())->method('revokeRefreshToken');
698704

@@ -727,11 +733,22 @@ public function testUnrevokedRefreshToken(): void
727733
$grant->setScopeRepository($scopeRepositoryMock);
728734
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
729735
$grant->setEncryptionKey($this->cryptStub->getKey());
730-
$grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
736+
$grant->setPrivateKey($privateKey = new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
731737
$grant->revokeRefreshTokens(false);
732738

733-
$grant->respondToAccessTokenRequest($serverRequest, new StubResponseType(), new DateInterval('PT5M'));
739+
$responseType = new BearerTokenResponse();
740+
$responseType->setPrivateKey($privateKey);
741+
$responseType->setEncryptionKey($this->cryptStub->getKey());
742+
743+
$response = $grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M'))
744+
->generateHttpResponse(new Response());
745+
746+
$json = json_decode((string) $response->getBody());
734747

735748
self::assertFalse($refreshTokenRepositoryMock->isRefreshTokenRevoked($refreshTokenId));
749+
self::assertEquals('Bearer', $json->token_type);
750+
self::assertObjectHasProperty('expires_in', $json);
751+
self::assertObjectHasProperty('access_token', $json);
752+
self::assertObjectHasProperty('refresh_token', $json);
736753
}
737754
}

0 commit comments

Comments
 (0)