test fake user repo find by email
This commit is contained in:
parent
cbeb43f18c
commit
b2fc6a7ded
1 changed files with 50 additions and 0 deletions
50
tests/Unit/User/FakeUserRepositoryTest.php
Normal file
50
tests/Unit/User/FakeUserRepositoryTest.php
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Unit\User;
|
||||||
|
|
||||||
|
use App\User\UseCases\CreateUserDto;
|
||||||
|
use App\User\User;
|
||||||
|
use App\ValueObjects\EmailAddress;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Tests\Fakes\FakeUserRepository;
|
||||||
|
|
||||||
|
class FakeUserRepositoryTest extends TestCase
|
||||||
|
{
|
||||||
|
public function test_find_by_email_returns_user(): void
|
||||||
|
{
|
||||||
|
$userRepo = new FakeUserRepository();
|
||||||
|
$userRepo->create(new CreateUserDto(
|
||||||
|
email: new EmailAddress('test@test.com'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$user = $userRepo->findByEmail(new EmailAddress('test@test.com'));
|
||||||
|
|
||||||
|
$this->assertInstanceOf(User::class, $user);
|
||||||
|
$this->assertEquals('test@test.com', (string) $user->getEmail());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_find_by_email_returns_null_when_not_found(): void
|
||||||
|
{
|
||||||
|
$userRepo = new FakeUserRepository();
|
||||||
|
|
||||||
|
$user = $userRepo->findByEmail(
|
||||||
|
new EmailAddress('missing@test.com')
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertNull($user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_find_by_email_returns_fresh_instance(): void
|
||||||
|
{
|
||||||
|
$userRepo = new FakeUserRepository();
|
||||||
|
$created = $userRepo->create(new CreateUserDto(
|
||||||
|
email: new EmailAddress('test@test.com'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$fetched = $userRepo->findByEmail(
|
||||||
|
new EmailAddress('test@test.com')
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertNotSame($created, $fetched);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue