add unit tests for user and auth

This commit is contained in:
Yisroel Baum 2026-05-18 21:36:10 +03:00
parent 613180d459
commit 410b752183
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
6 changed files with 315 additions and 0 deletions

View file

@ -0,0 +1,38 @@
<?php
namespace Tests\Unit\Auth\UseCases;
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 \App\Auth\CreateSessionDto(
'session-token',
$user,
new \DateTimeImmutable(),
new \DateTimeImmutable('+1 hour')
));
$this->logout->execute('session-token');
$this->assertNull($this->sessionRepo->findByToken('session-token'));
}
}