add fake session repository
This commit is contained in:
parent
c2ade8a601
commit
619ebd3907
1 changed files with 48 additions and 0 deletions
48
tests/Fakes/FakeSessionRepository.php
Normal file
48
tests/Fakes/FakeSessionRepository.php
Normal 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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue