50 lines
1.3 KiB
PHP
50 lines
1.3 KiB
PHP
<?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);
|
|
}
|
|
}
|