test user persistence

This commit is contained in:
Yisroel Baum 2026-07-31 09:48:01 +03:00
parent a8a6177a1d
commit b5697e1e1f
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
3 changed files with 94 additions and 0 deletions

View file

@ -0,0 +1,48 @@
<?php
namespace Tests\Feature\User;
use App\Shared\ValueObject\EmailAddress;
use App\User\CreateUserDto;
use App\User\UserRepository;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class EloquentUserRepositoryTest extends TestCase
{
use RefreshDatabase;
public function test_it_creates_and_finds_a_user(): void
{
$repository = app(UserRepository::class);
$user = $repository->create(new CreateUserDto(
email: new EmailAddress('Founder@EXAMPLE.COM'),
));
$this->assertGreaterThan(0, $user->getId());
$this->assertSame(
'Founder@example.com',
$user->getEmail()->value(),
);
$this->assertDatabaseHas('users', [
'id' => $user->getId(),
'email' => 'Founder@example.com',
]);
$foundUser = $repository->find($user->getId());
$this->assertNotNull($foundUser);
$this->assertSame($user->getId(), $foundUser->getId());
$this->assertSame(
$user->getEmail()->value(),
$foundUser->getEmail()->value(),
);
}
public function test_it_returns_null_for_an_unknown_user(): void
{
$repository = app(UserRepository::class);
$this->assertNull($repository->find(999));
}
}