/** @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()); }
/** * register * @param $email * @param $firstName * @param $lastName * @param $username * @param $password * @return User * @throws ValueIsNotUniqueException */ public function register($email, $firstName, $lastName, $password) { $email = new Email($email); $firstName = new FirstName($firstName); $lastName = new LastName($lastName); $password = new Password($password); $id = $this->userRepository->nextIdentity(); $password = $this->hashingService->hash($password); $username = $this->generateUsername($firstName, $lastName); $user = User::create($id, $email, $firstName, $lastName, $username, $password); $userRepo = $this->userRepository; $args = compact("user", "userRepo"); // $emailGuard = new UserEmailIsUniqueGuard($this->userRepository); // $usernameGuard = new UsernameIsUniqueGuard($this->userRepository); // $emailGuard->handle($args); // $usernameGuard->handle($args); // Not sure how to test with this // Guard trait will inject from app container // Maybe could try service provider gymnastics $this->guard([UserEmailIsUniqueGuard::class, UsernameIsUniqueGuard::class], $args); $this->userRepository->add($user); return $user; }