fake user repo
This commit is contained in:
parent
9f38708f7b
commit
1c6fd5047a
1 changed files with 45 additions and 0 deletions
45
tests/Fakes/FakeUserRepository.php
Normal file
45
tests/Fakes/FakeUserRepository.php
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\User\UseCases\CreateUserDto;
|
||||
use App\User\User;
|
||||
use App\User\UserRepository;
|
||||
|
||||
class FakeUserRepository implements UserRepository
|
||||
{
|
||||
/**
|
||||
* @var User[]
|
||||
*/
|
||||
private array $existingUsers = [];
|
||||
|
||||
public function find(int $id): ?User
|
||||
{
|
||||
$user = $this->existingUsers[$id];
|
||||
if ($user === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new User(
|
||||
id: $user->getId(),
|
||||
email: $user->getEmail(),
|
||||
);
|
||||
}
|
||||
|
||||
public function create(CreateUserDto $dto): User
|
||||
{
|
||||
$id = $this->nextId();
|
||||
$user = new User(
|
||||
id: $id,
|
||||
email: $dto->email,
|
||||
);
|
||||
$this->existingUsers[$id] = $user;
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
private function nextId(): int
|
||||
{
|
||||
return count($this->existingUsers);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue