Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Packages\Features\CommandUseCases\UseCase\User;

use App\Packages\Domains\User\Interface\TokenServiceInterface;

class LogoutUseCase
{
public function __construct(
private readonly TokenServiceInterface $tokenService,
) {}

public function handle(string $plainTextToken): void
{
$this->tokenService->revokeCurrentToken($plainTextToken);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace App\Packages\Features\Tests\CommandUseCases;

use App\Packages\Domains\User\Interface\TokenServiceInterface;
use App\Packages\Features\CommandUseCases\UseCase\User\LogoutUseCase;
use Mockery;
use Mockery\MockInterface;
use RuntimeException;
use Tests\TestCase;

class LogoutUseCaseTest extends TestCase
{
protected function tearDown(): void
{
Mockery::close();
parent::tearDown();
}

#[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
public function test_handle_revokes_current_token(): void
{
/** @var TokenServiceInterface|MockInterface $tokenService */
$tokenService = Mockery::mock(TokenServiceInterface::class);
$tokenService->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');
}
}
Loading