test auth middleware

This commit is contained in:
Yisroel Baum 2026-07-31 09:53:12 +03:00
parent 34e26f81f5
commit 19d930b7e8
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
4 changed files with 325 additions and 0 deletions

View file

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