Example #1
0
 public static function create()
 {
     //        return 'here';
     $faker = Factory::create();
     $identifier = UserId::generate();
     $email = Email::fromNative($faker->email);
     $first = FirstName::fromNative($faker->word);
     $last = LastName::fromNative($faker->word);
     $username = Username::fromNative($faker->word);
     $password = HashedPassword::fromNative(str_random(10));
     return User::create($identifier, $email, $first, $last, $username, $password);
 }
Example #2
0
 /** @test */
 public function should_grant_and_revoke_roles()
 {
     $user = User::create($this->id, $this->email, $this->firstName, $this->lastName, $this->username, $this->password);
     $role1 = RoleStub::create();
     $role2 = RoleStub::create();
     $role3 = RoleStub::create();
     $user->grantRole($role1);
     $user->grantRole($role2);
     $user->grantRole($role3);
     $user->revokeRole($role2);
     $this->assertTrue($user->hasRole($role1));
     $this->assertTrue($role1->users()->contains($user));
     $this->assertFalse($user->hasRole($role2));
     $this->assertFalse($role2->users()->contains($user));
     $this->assertTrue($user->hasRole($role3));
     $this->assertTrue($role3->users()->contains($user));
 }
Example #3
0
 /**
  * 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;
 }