change up logout test style
This commit is contained in:
parent
218f885251
commit
3ebb2c14b3
1 changed files with 28 additions and 18 deletions
|
|
@ -6,41 +6,51 @@ use App\Auth\CreateSessionDto;
|
|||
use App\Auth\UseCases\Logout\Logout;
|
||||
use App\Shared\ValueObject\EmailAddress;
|
||||
use App\User\User;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeZone;
|
||||
use Tests\Fakes\FakeSessionRepository;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LogoutTest extends TestCase
|
||||
{
|
||||
private FakeSessionRepository $sessionRepo;
|
||||
private Logout $logout;
|
||||
|
||||
private Logout $useCase;
|
||||
|
||||
private DateTimeImmutable $now;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->sessionRepo = new FakeSessionRepository();
|
||||
$this->logout = new Logout($this->sessionRepo);
|
||||
$this->now = new DateTimeImmutable(
|
||||
'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');
|
||||
$user = new User(1, $email, 'hashed-password');
|
||||
|
||||
$session = $this->sessionRepo->create(new CreateSessionDto(
|
||||
'session-token',
|
||||
$user,
|
||||
new \DateTimeImmutable(),
|
||||
new \DateTimeImmutable('+1 hour')
|
||||
$this->sessionRepo->create(new CreateSessionDto(
|
||||
token: 'token-abc',
|
||||
user: new User(
|
||||
id: 7,
|
||||
email: new EmailAddress('a@b.com'),
|
||||
passwordHash: 'password',
|
||||
),
|
||||
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'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue