From 35569211b99461291e7522a01345f0d4560f006b Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Thu, 22 Aug 2024 17:08:35 +0330 Subject: [PATCH] fix tests --- src/Bridge/AccessTokenRepository.php | 8 +------- .../BridgeAccessTokenRepositoryTest.php | 20 ++++++++----------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/Bridge/AccessTokenRepository.php b/src/Bridge/AccessTokenRepository.php index 4e406564..f1ddf6ef 100644 --- a/src/Bridge/AccessTokenRepository.php +++ b/src/Bridge/AccessTokenRepository.php @@ -7,7 +7,6 @@ use Laravel\Passport\Events\AccessTokenCreated; use Laravel\Passport\Events\AccessTokenRevoked; use Laravel\Passport\Passport; -use Laravel\Passport\TokenRepository; use League\OAuth2\Server\Entities\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\ClientEntityInterface; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; @@ -16,11 +15,6 @@ class AccessTokenRepository implements AccessTokenRepositoryInterface { use FormatsScopesForStorage; - /** - * The token repository instance. - */ - protected TokenRepository $tokenRepository; - /** * The event dispatcher instance. */ @@ -69,7 +63,7 @@ public function persistNewAccessToken(AccessTokenEntityInterface $accessTokenEnt */ public function revokeAccessToken(string $tokenId): void { - if (Passport::token()->whereKey($tokenId)->update(['revoked' => true])) { + if (Passport::token()->newQuery()->whereKey($tokenId)->update(['revoked' => true])) { $this->events->dispatch(new AccessTokenRevoked($tokenId)); } } diff --git a/tests/Feature/BridgeAccessTokenRepositoryTest.php b/tests/Feature/BridgeAccessTokenRepositoryTest.php index 8efbb5e5..7a570eba 100644 --- a/tests/Feature/BridgeAccessTokenRepositoryTest.php +++ b/tests/Feature/BridgeAccessTokenRepositoryTest.php @@ -43,30 +43,26 @@ public function test_access_tokens_can_be_persisted() public function test_access_tokens_can_be_revoked() { - $tokenRepository = m::mock(TokenRepository::class); $events = m::mock(Dispatcher::class); + $events->shouldReceive('dispatch')->twice(); - $tokenRepository->shouldReceive('revokeAccessToken')->with('token-id')->once()->andReturn(1); - $events->shouldReceive('dispatch')->once(); + $accessToken = new AccessToken(2, [], new Client('client-id', 'name', ['redirect'])); + $accessToken->setIdentifier('token-id'); + $accessToken->setExpiryDateTime(CarbonImmutable::now()); - $repository = new AccessTokenRepository($tokenRepository, $events); - $repository->revokeAccessToken('token-id'); + $repository = new AccessTokenRepository($events); + $repository->persistNewAccessToken($accessToken); - $this->expectNotToPerformAssertions(); + $repository->revokeAccessToken('token-id'); } public function test_access_token_revoke_event_is_not_dispatched_when_nothing_happened() { - $tokenRepository = m::mock(TokenRepository::class); $events = m::mock(Dispatcher::class); - - $tokenRepository->shouldReceive('revokeAccessToken')->with('token-id')->once()->andReturn(0); $events->shouldNotReceive('dispatch'); - $repository = new AccessTokenRepository($tokenRepository, $events); + $repository = new AccessTokenRepository($events); $repository->revokeAccessToken('token-id'); - - $this->expectNotToPerformAssertions(); } public function test_can_get_new_access_token()