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,47 @@
<?php
namespace Tests\Fakes;
use App\Auth\CreateSessionDto;
use App\Auth\Session;
use App\Auth\SessionRepository;
use DateTimeImmutable;
class FakeSessionRepository implements SessionRepository
{
private array $sessionsByToken = [];
public function create(CreateSessionDto $dto): Session
{
$session = new Session(
$dto->token,
$dto->user,
$dto->createdAt,
$dto->expiresAt
);
$this->sessionsByToken[$dto->token] = $session;
return $session;
}
public function findByToken(string $token): ?Session
{
if (! isset($this->sessionsByToken[$token])) {
return null;
}
$stored = $this->sessionsByToken[$token];
return new Session(
$stored->getToken(),
$stored->getUser(),
$stored->getCreatedAt(),
$stored->getExpiresAt()
);
}
public function deleteByToken(string $token): void
{
unset($this->sessionsByToken[$token]);
}
}