Rabbi_Gerzi/backend/tests/Unit/Auth/UseCases/LogoutTest.php

46 lines
1.2 KiB
PHP

<?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 PHPUnit\Framework\TestCase;
use Tests\Fakes\FakeSessionRepository;
class LogoutTest extends TestCase
{
private FakeSessionRepository $sessionRepo;
private Logout $logout;
protected function setUp(): void
{
$this->sessionRepo = new FakeSessionRepository();
$this->logout = new Logout($this->sessionRepo);
}
public function testDeletesSessionByToken(): void
{
$email = new EmailAddress('user@example.com');
$user = new User(1, $email, 'hashed-password');
$session = $this->sessionRepo->create(new CreateSessionDto(
'session-token',
$user,
new \DateTimeImmutable(),
new \DateTimeImmutable('+1 hour')
));
$this->logout->execute('session-token');
$this->assertNull($this->sessionRepo->findByToken('session-token'));
}
public function testDeletesMissingTokenIsIdempotent(): void
{
$this->logout->execute('nonexistent-token');
$this->assertNull($this->sessionRepo->findByToken('nonexistent-token'));
}
}