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); }
/** @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)); }
/** * 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; }
public function transform(User $user) { return ['id' => $user->id()->toString(), 'email' => $user->email()->toString(), 'firstName' => $user->firstName()->toString(), 'lastName' => $user->lastName()->toString(), 'username' => $user->username()->toString()]; }
/** * Create a new instance from a native form * * @param User $user * @return ValueObject */ public static function fromUser(User $user) { return new Token($user->id()); }