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'); }
/** @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')); }
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); }
/** * Set UserId * @param UserId $userId */ private function setUserId(UserId $userId) { $this->userId = $userId->toString(); }
/** * Set the User's id * * @param UserId $id * @return void */ private function setId(UserId $id) { $this->id = $id->toString(); }
/** * 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)); }
/** @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()); }