private function findUserByEmail(Email $email) { $user = $this->userRepository->userOfEmail($email); if (!$user) { throw new NotFoundException('user_email_not_found', $email); } return $user; }
/** @test */ public function should_add_new_user() { $userStub = UserStub::create(); $user = $this->repository->add($userStub); $this->em->clear(); $user = $this->repository->userOfEmail($userStub->email()); $this->assertEquals($userStub->id(), $user->id()); $this->assertEquals($userStub->email(), $user->email()); $this->assertEquals($userStub->username(), $user->username()); $this->assertEquals($userStub->firstName(), $user->firstName()); $this->assertEquals($userStub->lastName(), $user->lastName()); }
/** * Attempt to find a user by their email address * * @param Email $email * @return User * @throws ValueNotFoundException */ private function findUserByEmail(Email $email) { $user = $this->users->userOfEmail($email); if ($user) { return $user; } throw new ValueNotFoundException("{$email} is not a registered email address"); }