Beispiel #1
0
 public function setUp()
 {
     $this->id = UserId::generate();
     $this->email = new Email('*****@*****.**');
     $this->username = new Username('my_username');
     $this->firstName = new Firstname('first');
     $this->lastName = new Lastname('last');
     $this->password = new HashedPassword('super_secret_password');
 }
Beispiel #2
0
 /** @test */
 public function should_register_new_user()
 {
     $this->repository->shouldReceive('userOfEmail')->andReturn(null);
     $this->repository->shouldReceive('userOfUsername')->andReturn(null);
     $this->repository->shouldReceive('nextIdentity')->andReturn(UserId::generate());
     $this->hashing->shouldReceive('hash')->andReturn(new HashedPassword('password'));
     $this->repository->shouldReceive('add');
     $user = $this->registrar->register('*****@*****.**', 'First', 'Last', 'username', 'password');
     $this->assertInstanceOf(User::class, $user);
 }
 /** @test */
 public function should_throw_exception_user_does_not_have_permissions()
 {
     $role = $this->role;
     $user = $this->user;
     $user->shouldReceive('hasRole')->andReturn(false);
     $user->shouldReceive('id')->andReturn(UserId::generate());
     $role->shouldReceive('slug')->andReturn(RoleSlug::fromNative('asdf'));
     $this->setExpectedException(UserDoesNotHaveRolePermissions::class);
     $this->guard->handle(compact('user', 'role'));
 }
Beispiel #4
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);
 }
Beispiel #5
0
 /**
  * Set UserId
  * @param UserId $userId
  */
 private function setUserId(UserId $userId)
 {
     $this->userId = $userId->toString();
 }
Beispiel #6
0
 /**
  * Set the User's id
  *
  * @param UserId $id
  * @return void
  */
 private function setId(UserId $id)
 {
     $this->id = $id->toString();
 }
Beispiel #7
0
 /**
  * Decode Token From Encoded Token
  *
  * @param  $encodedToken
  * @return Token
  */
 public function decode(EncodedToken $encodedToken)
 {
     $stdObject = JWT::decode($encodedToken->toString(), $this->key, array('HS256'));
     return new Token(UserId::fromString($stdObject->userId));
 }
Beispiel #8
0
 /** @test */
 public function should_return_user_id_as_string()
 {
     $id = UserId::fromString('d16f9fe7-e947-460e-99f6-2d64d65f46bc');
     $this->assertEquals('d16f9fe7-e947-460e-99f6-2d64d65f46bc', $id->toString());
     $this->assertEquals('d16f9fe7-e947-460e-99f6-2d64d65f46bc', (string) $id);
 }
 /**
  * Find a user by their id
  *
  * @param UserId $id
  * @return User
  */
 public function userOfId(UserId $id)
 {
     return $this->find($id->toString());
 }