Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hafezdivandari committed Aug 22, 2024
1 parent 8ddef9b commit 3556921
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
8 changes: 1 addition & 7 deletions src/Bridge/AccessTokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,11 +15,6 @@ class AccessTokenRepository implements AccessTokenRepositoryInterface
{
use FormatsScopesForStorage;

/**
* The token repository instance.
*/
protected TokenRepository $tokenRepository;

/**
* The event dispatcher instance.
*/
Expand Down Expand Up @@ -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));
}
}
Expand Down
20 changes: 8 additions & 12 deletions tests/Feature/BridgeAccessTokenRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 3556921

Please sign in to comment.