test user login and create fake user repo
This commit is contained in:
parent
7ece9dd072
commit
5566395dfb
2 changed files with 84 additions and 0 deletions
35
tests/Fakes/User/FakeUserRepository.php
Normal file
35
tests/Fakes/User/FakeUserRepository.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Fakes\User;
|
||||
|
||||
use FreightQuote\User\User;
|
||||
use FreightQuote\User\UserRepository;
|
||||
|
||||
class FakeUserRepository implements UserRepository
|
||||
{
|
||||
/**
|
||||
* @var User[] $existingUsers
|
||||
*/
|
||||
private array $existingUsers = [];
|
||||
|
||||
public function findByEmail(string $email): ?User
|
||||
{
|
||||
foreach ($this->existingUsers as $user) {
|
||||
if ($user->getEmail() === $email) {
|
||||
return new User(
|
||||
$user->getEmail(),
|
||||
$user->getPassword()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function save(User $user): User
|
||||
{
|
||||
$this->existingUsers[$user->getEmail()] = $user;
|
||||
|
||||
return new User($user->getEmail(), $user->getPassword());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue