47 lines
1 KiB
PHP
47 lines
1 KiB
PHP
<?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]);
|
|
}
|
|
}
|