diff --git a/src/app/Packages/Features/CommandUseCases/UseCase/User/LogoutUseCase.php b/src/app/Packages/Features/CommandUseCases/UseCase/User/LogoutUseCase.php new file mode 100644 index 0000000..432496b --- /dev/null +++ b/src/app/Packages/Features/CommandUseCases/UseCase/User/LogoutUseCase.php @@ -0,0 +1,17 @@ +tokenService->revokeCurrentToken($plainTextToken); + } +} diff --git a/src/app/Packages/Features/Tests/CommandUseCases/LogoutUseCaseTest.php b/src/app/Packages/Features/Tests/CommandUseCases/LogoutUseCaseTest.php new file mode 100644 index 0000000..ad1b7d9 --- /dev/null +++ b/src/app/Packages/Features/Tests/CommandUseCases/LogoutUseCaseTest.php @@ -0,0 +1,45 @@ +shouldReceive('revokeCurrentToken') + ->once() + ->with('plain-text-token'); + + (new LogoutUseCase($tokenService))->handle('plain-text-token'); + } + + public function test_handle_propagates_exception_when_revocation_fails(): void + { + /** @var TokenServiceInterface|MockInterface $tokenService */ + $tokenService = Mockery::mock(TokenServiceInterface::class); + $tokenService->shouldReceive('revokeCurrentToken') + ->once() + ->andThrow(new RuntimeException('Revocation failed.')); + + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('Revocation failed.'); + + (new LogoutUseCase($tokenService))->handle('plain-text-token'); + } +}