create(new CreateUserDto( email: new EmailAddress('Founder@EXAMPLE.COM'), password: 'correct-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->assertDatabaseMissing('users', [ 'id' => $user->getId(), 'password' => 'correct-password', ]); $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)); } public function test_it_finds_a_user_with_matching_credentials(): void { $repository = app(UserRepository::class); $createdUser = $repository->create(new CreateUserDto( email: new EmailAddress('user@example.com'), password: 'correct-password', )); $foundUser = $repository->findByCredentials( new EmailAddress('user@EXAMPLE.COM'), 'correct-password', ); $this->assertNotNull($foundUser); $this->assertSame($createdUser->getId(), $foundUser->getId()); } public function test_it_rejects_non_matching_credentials(): void { $repository = app(UserRepository::class); $repository->create(new CreateUserDto( email: new EmailAddress('user@example.com'), password: 'correct-password', )); $this->assertNull($repository->findByCredentials( new EmailAddress('user@example.com'), 'wrong-password', )); $this->assertNull($repository->findByCredentials( new EmailAddress('unknown@example.com'), 'correct-password', )); } }