implement find by email in fake user repo
This commit is contained in:
parent
ee271e162e
commit
64edec5141
1 changed files with 20 additions and 0 deletions
|
|
@ -5,6 +5,7 @@ namespace Tests\Fakes;
|
|||
use App\User\UseCases\CreateUserDto;
|
||||
use App\User\User;
|
||||
use App\User\UserRepository;
|
||||
use App\ValueObjects\EmailAddress;
|
||||
|
||||
class FakeUserRepository implements UserRepository
|
||||
{
|
||||
|
|
@ -32,6 +33,25 @@ class FakeUserRepository implements UserRepository
|
|||
);
|
||||
}
|
||||
|
||||
public function findByEmail(EmailAddress $email): ?User
|
||||
{
|
||||
$user = array_find(
|
||||
$this->existingUsers,
|
||||
function (User $user) use ($email) {
|
||||
return (string) $user->getEmail() === (string) $email;
|
||||
}
|
||||
);
|
||||
if ($user === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new User(
|
||||
id: $user->getId(),
|
||||
email: $user->getEmail(),
|
||||
isAdmin: $user->isAdmin(),
|
||||
);
|
||||
}
|
||||
|
||||
public function create(CreateUserDto $dto): User
|
||||
{
|
||||
$id = $this->nextId();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue