test: add failing authenticate user test
Red phase: write AuthenticateUserTest with cases for valid credentials, empty email/password (null and empty string), unknown email, wrong password, and fresh instance guarantee. Fakes included.
This commit is contained in:
parent
9d9771de6e
commit
57c75f64c4
9 changed files with 2175 additions and 2 deletions
46
backend/tests/Fakes/FakeSessionRepository.php
Normal file
46
backend/tests/Fakes/FakeSessionRepository.php
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Auth\CreateSessionDto;
|
||||
use App\Auth\Session;
|
||||
use App\Auth\SessionRepository;
|
||||
|
||||
class FakeSessionRepository implements SessionRepository
|
||||
{
|
||||
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
|
||||
{
|
||||
$session = $this->sessions[$token] ?? null;
|
||||
|
||||
if ($session === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Session(
|
||||
token: $session->getToken(),
|
||||
user: $session->getUser(),
|
||||
createdAt: $session->getCreatedAt(),
|
||||
expiresAt: $session->getExpiresAt(),
|
||||
);
|
||||
}
|
||||
|
||||
public function deleteByToken(string $token): void
|
||||
{
|
||||
unset($this->sessions[$token]);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue