test logout flow

This commit is contained in:
Yisroel Baum 2026-08-03 19:41:51 +03:00
parent 2e140cd8d8
commit 89f448bd42
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
3 changed files with 150 additions and 0 deletions

View file

@ -0,0 +1,58 @@
<?php
namespace Tests\Unit\Auth\UseCases;
use App\Auth\CreateSessionDto;
use App\Auth\UseCases\Logout\Logout;
use App\Shared\ValueObject\EmailAddress;
use App\User\User;
use DateTimeImmutable;
use DateTimeZone;
use PHPUnit\Framework\TestCase;
use Tests\Fakes\FakeSessionRepository;
class LogoutTest extends TestCase
{
private FakeSessionRepository $sessionRepository;
private Logout $useCase;
protected function setUp(): void
{
$this->sessionRepository = new FakeSessionRepository;
$this->useCase = new Logout($this->sessionRepository);
}
public function test_existing_token_session_is_removed(): void
{
$now = new DateTimeImmutable(
'2026-07-31T12:00:00',
new DateTimeZone('UTC'),
);
$this->sessionRepository->create(new CreateSessionDto(
token: 'session-token',
user: new User(
id: 7,
email: new EmailAddress('user@example.com'),
passwordHash: 'hashed-password',
),
createdAt: $now,
expiresAt: $now->modify('+7 days'),
));
$this->useCase->execute('session-token');
$this->assertNull(
$this->sessionRepository->findByToken('session-token'),
);
}
public function test_unknown_token_does_not_throw(): void
{
$this->useCase->execute('unknown-token');
$this->assertNull(
$this->sessionRepository->findByToken('unknown-token'),
);
}
}