create(new CreateUserDto( email: new EmailAddress('Founder@EXAMPLE.COM'), passwordHash: 'hashed-password', )); $this->assertGreaterThan(0, $user->getId()); $this->assertSame( 'Founder@example.com', $user->getEmail()->value(), ); $this->assertDatabaseHas('users', [ 'id' => $user->getId(), 'email' => 'Founder@example.com', ]); $this->assertDatabaseHas('users', [ 'id' => $user->getId(), 'passwordHash' => 'hashed-password', ]); $foundUser = $repository->find($user->getId()); $this->assertNotNull($foundUser); $this->assertSame($user->getId(), $foundUser->getId()); $this->assertSame( $user->getEmail()->value(), $foundUser->getEmail()->value(), ); $this->assertSame( $user->getPasswordHash(), $foundUser->getPasswordHash(), ); } public function test_it_returns_null_for_an_unknown_user(): void { $repository = app(UserRepository::class); $this->assertNull($repository->find(999)); } public function test_it_finds_a_user_by_email(): void { $repository = app(UserRepository::class); $createdUser = $repository->create(new CreateUserDto( email: new EmailAddress('user@example.com'), passwordHash: 'hashed-password', )); $foundUser = $repository->findByEmail( new EmailAddress('user@EXAMPLE.COM'), ); $this->assertNotNull($foundUser); $this->assertSame($createdUser->getId(), $foundUser->getId()); } public function test_it_returns_null_for_an_unknown_email(): void { $repository = app(UserRepository::class); $this->assertNull($repository->findByEmail( new EmailAddress('unknown@example.com'), )); } }