change up logout test style

This commit is contained in:
Yisroel Baum 2026-05-19 19:55:49 +03:00
parent 218f885251
commit 3ebb2c14b3
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9

View file

@ -6,41 +6,51 @@ use App\Auth\CreateSessionDto;
use App\Auth\UseCases\Logout\Logout; use App\Auth\UseCases\Logout\Logout;
use App\Shared\ValueObject\EmailAddress; use App\Shared\ValueObject\EmailAddress;
use App\User\User; use App\User\User;
use PHPUnit\Framework\TestCase; use DateTimeImmutable;
use DateTimeZone;
use Tests\Fakes\FakeSessionRepository; use Tests\Fakes\FakeSessionRepository;
use Tests\TestCase;
class LogoutTest extends TestCase class LogoutTest extends TestCase
{ {
private FakeSessionRepository $sessionRepo; private FakeSessionRepository $sessionRepo;
private Logout $logout;
private Logout $useCase;
private DateTimeImmutable $now;
protected function setUp(): void protected function setUp(): void
{ {
$this->sessionRepo = new FakeSessionRepository(); $this->now = new DateTimeImmutable(
$this->logout = new Logout($this->sessionRepo); '2026-04-29T12:00:00',
new DateTimeZone('UTC')
);
$this->sessionRepo = new FakeSessionRepository;
$this->useCase = new Logout($this->sessionRepo);
} }
public function testDeletesSessionByToken(): void public function test_existing_token_session_is_removed(): void
{ {
$email = new EmailAddress('user@example.com'); $this->sessionRepo->create(new CreateSessionDto(
$user = new User(1, $email, 'hashed-password'); token: 'token-abc',
user: new User(
$session = $this->sessionRepo->create(new CreateSessionDto( id: 7,
'session-token', email: new EmailAddress('a@b.com'),
$user, passwordHash: 'password',
new \DateTimeImmutable(), ),
new \DateTimeImmutable('+1 hour') createdAt: $this->now,
expiresAt: $this->now->modify('+7 days'),
)); ));
$this->logout->execute('session-token'); $this->useCase->execute('token-abc');
$this->assertNull($this->sessionRepo->findByToken('session-token')); $this->assertNull($this->sessionRepo->findByToken('token-abc'));
} }
public function testDeletesMissingTokenIsIdempotent(): void public function test_unknown_token_does_not_throw(): void
{ {
$this->logout->execute('nonexistent-token'); $this->useCase->execute('unknown-token');
$this->assertNull($this->sessionRepo->findByToken('nonexistent-token')); $this->assertNull($this->sessionRepo->findByToken('unknown-token'));
} }
} }