add unit tests for user and auth
This commit is contained in:
parent
613180d459
commit
410b752183
6 changed files with 315 additions and 0 deletions
47
backend/tests/Fakes/FakeSessionRepository.php
Normal file
47
backend/tests/Fakes/FakeSessionRepository.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?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]);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue