add fake session repository

This commit is contained in:
Yisroel Baum 2026-04-24 13:22:06 +03:00
parent c2ade8a601
commit 619ebd3907
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9

View file

@ -0,0 +1,48 @@
<?php
namespace Tests\Fakes;
use App\Auth\CreateSessionDto;
use App\Auth\Session;
use App\Auth\SessionRepository;
class FakeSessionRepository implements SessionRepository
{
/**
* @var Session[]
*/
private array $existingSessions = [];
public function create(CreateSessionDto $dto): Session
{
$session = new Session(
token: $dto->token,
userId: $dto->userId,
createdAt: $dto->createdAt,
expiresAt: $dto->expiresAt,
);
$this->existingSessions[$dto->token] = $session;
return $session;
}
public function findByToken(string $token): ?Session
{
$session = $this->existingSessions[$token] ?? null;
if ($session === null) {
return null;
}
return new Session(
token: $session->getToken(),
userId: $session->getUserId(),
createdAt: $session->getCreatedAt(),
expiresAt: $session->getExpiresAt(),
);
}
public function deleteByToken(string $token): void
{
unset($this->existingSessions[$token]);
}
}