test email signup flow
This commit is contained in:
parent
a95903ed05
commit
9945163a2f
12 changed files with 631 additions and 0 deletions
69
backend/tests/Fakes/FakeEmailConfirmationTokenRepository.php
Normal file
69
backend/tests/Fakes/FakeEmailConfirmationTokenRepository.php
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Email\EmailConfirmationToken\CreateEmailConfirmationTokenDto;
|
||||
use App\Email\EmailConfirmationToken\EmailConfirmationToken;
|
||||
use App\Email\EmailConfirmationToken\EmailConfirmationTokenRepository;
|
||||
use App\User\User;
|
||||
|
||||
class FakeEmailConfirmationTokenRepository implements EmailConfirmationTokenRepository
|
||||
{
|
||||
/**
|
||||
* @var array<int, EmailConfirmationToken>
|
||||
*/
|
||||
private array $tokens = [];
|
||||
|
||||
public function create(
|
||||
CreateEmailConfirmationTokenDto $dto,
|
||||
): EmailConfirmationToken {
|
||||
$id = count($this->tokens) + 1;
|
||||
$token = new EmailConfirmationToken(
|
||||
id: $id,
|
||||
user: $dto->user,
|
||||
availableTo: $dto->availableTo,
|
||||
token: $dto->token,
|
||||
);
|
||||
$this->tokens[$id] = $token;
|
||||
|
||||
return $this->copy($token);
|
||||
}
|
||||
|
||||
public function findByToken(string $token): ?EmailConfirmationToken
|
||||
{
|
||||
foreach ($this->tokens as $candidate) {
|
||||
if ($candidate->getToken() === $token) {
|
||||
return $this->copy($candidate);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function findByUser(User $user): ?EmailConfirmationToken
|
||||
{
|
||||
foreach ($this->tokens as $candidate) {
|
||||
if ($candidate->getUser()->getId() === $user->getId()) {
|
||||
return $this->copy($candidate);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function delete(int $id): void
|
||||
{
|
||||
unset($this->tokens[$id]);
|
||||
}
|
||||
|
||||
private function copy(
|
||||
EmailConfirmationToken $token,
|
||||
): EmailConfirmationToken {
|
||||
return new EmailConfirmationToken(
|
||||
id: $token->getId(),
|
||||
user: $token->getUser(),
|
||||
availableTo: $token->getAvailableTo(),
|
||||
token: $token->getToken(),
|
||||
);
|
||||
}
|
||||
}
|
||||
22
backend/tests/Fakes/FakeEmailFactory.php
Normal file
22
backend/tests/Fakes/FakeEmailFactory.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Email\EmailFactory;
|
||||
|
||||
class FakeEmailFactory implements EmailFactory
|
||||
{
|
||||
private ?string $lastToken = null;
|
||||
|
||||
public function makeConfirmationEmail(string $token): string
|
||||
{
|
||||
$this->lastToken = $token;
|
||||
|
||||
return "confirm with {$token}";
|
||||
}
|
||||
|
||||
public function getLastToken(): ?string
|
||||
{
|
||||
return $this->lastToken;
|
||||
}
|
||||
}
|
||||
48
backend/tests/Fakes/FakeEmailer.php
Normal file
48
backend/tests/Fakes/FakeEmailer.php
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Email\Emailer;
|
||||
use App\Shared\ValueObject\EmailAddress;
|
||||
|
||||
class FakeEmailer implements Emailer
|
||||
{
|
||||
private int $sendCount = 0;
|
||||
|
||||
private ?EmailAddress $lastRecipient = null;
|
||||
|
||||
private ?string $lastSubject = null;
|
||||
|
||||
private ?string $lastBody = null;
|
||||
|
||||
public function send(
|
||||
EmailAddress $recipient,
|
||||
string $subject,
|
||||
string $body,
|
||||
): void {
|
||||
$this->sendCount++;
|
||||
$this->lastRecipient = $recipient;
|
||||
$this->lastSubject = $subject;
|
||||
$this->lastBody = $body;
|
||||
}
|
||||
|
||||
public function getSendCount(): int
|
||||
{
|
||||
return $this->sendCount;
|
||||
}
|
||||
|
||||
public function getLastRecipient(): ?EmailAddress
|
||||
{
|
||||
return $this->lastRecipient;
|
||||
}
|
||||
|
||||
public function getLastSubject(): ?string
|
||||
{
|
||||
return $this->lastSubject;
|
||||
}
|
||||
|
||||
public function getLastBody(): ?string
|
||||
{
|
||||
return $this->lastBody;
|
||||
}
|
||||
}
|
||||
|
|
@ -45,6 +45,13 @@ class FakeUserRepository implements UserRepository
|
|||
return null;
|
||||
}
|
||||
|
||||
public function update(User $user): User
|
||||
{
|
||||
$this->users[$user->getId()] = $this->copy($user);
|
||||
|
||||
return $this->copy($user);
|
||||
}
|
||||
|
||||
private function copy(User $user): User
|
||||
{
|
||||
return new User(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue