test auth middleware
This commit is contained in:
parent
34e26f81f5
commit
19d930b7e8
4 changed files with 325 additions and 0 deletions
18
backend/tests/Fakes/FakeClock.php
Normal file
18
backend/tests/Fakes/FakeClock.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Auth\Clock;
|
||||
use DateTimeImmutable;
|
||||
|
||||
class FakeClock implements Clock
|
||||
{
|
||||
public function __construct(
|
||||
private DateTimeImmutable $currentTime,
|
||||
) {}
|
||||
|
||||
public function now(): DateTimeImmutable
|
||||
{
|
||||
return $this->currentTime;
|
||||
}
|
||||
}
|
||||
38
backend/tests/Fakes/FakeSessionRepository.php
Normal file
38
backend/tests/Fakes/FakeSessionRepository.php
Normal 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]);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue