Add display_name (unique) and email_confirmed_at columns plus matching getters, DTO fields, repo methods (findByDisplayName, update), and migration. Existing auth tests updated to construct User with the new params.
60 lines
1.6 KiB
PHP
60 lines
1.6 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 DateTimeImmutable;
|
|
use DateTimeZone;
|
|
use Tests\Fakes\FakeSessionRepository;
|
|
use Tests\TestCase;
|
|
|
|
class LogoutTest extends TestCase
|
|
{
|
|
private FakeSessionRepository $sessionRepo;
|
|
|
|
private Logout $useCase;
|
|
|
|
private DateTimeImmutable $now;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->now = new DateTimeImmutable(
|
|
'2026-05-06T12:00:00',
|
|
new DateTimeZone('UTC')
|
|
);
|
|
$this->sessionRepo = new FakeSessionRepository;
|
|
$this->useCase = new Logout($this->sessionRepo);
|
|
}
|
|
|
|
public function test_existing_token_session_is_removed(): void
|
|
{
|
|
$user = new User(
|
|
id: 7,
|
|
email: new EmailAddress('user@example.com'),
|
|
displayName: 'user',
|
|
passwordHash: 'hashed:irrelevant',
|
|
isAdmin: false,
|
|
emailConfirmedAt: null,
|
|
);
|
|
$this->sessionRepo->create(new CreateSessionDto(
|
|
token: 'token-abc',
|
|
user: $user,
|
|
createdAt: $this->now,
|
|
expiresAt: $this->now->modify('+7 days'),
|
|
));
|
|
|
|
$this->useCase->execute('token-abc');
|
|
|
|
$this->assertNull($this->sessionRepo->findByToken('token-abc'));
|
|
}
|
|
|
|
public function test_unknown_token_does_not_throw(): void
|
|
{
|
|
$this->useCase->execute('unknown-token');
|
|
|
|
$this->assertNull($this->sessionRepo->findByToken('unknown-token'));
|
|
}
|
|
}
|