Example #1
0
 /**
  * Find a User by their id
  *
  * @param string $id
  * @return User
  */
 private function findUserById($id)
 {
     $user = $this->users->userById(UserId::fromString($id));
     if ($user) {
         return $user;
     }
     throw new ValueNotFoundException("{$id} is not a valid user id");
 }
Example #2
0
 /** @test */
 public function should_create_new_group()
 {
     $user = m::mock('Cribbb\\Domain\\Model\\Identity\\User');
     $this->users->shouldReceive('userById')->once()->andReturn($user);
     $this->groups->shouldReceive('groupOfName')->once()->andReturn(null);
     $this->groups->shouldReceive('add')->once();
     $group = $this->service->create('7c5e8127-3f77-496c-9bb4-5cb092969d89', 'Cribbb');
     $this->assertInstanceOf('Cribbb\\Domain\\Model\\Groups\\Group', $group);
 }
Example #3
0
 /** @test */
 public function should_follow_other_user()
 {
     $user = m::mock('Cribbb\\Domain\\Model\\Identity\\User');
     $user->shouldReceive('follow')->once();
     $friend = m::mock('Cribbb\\Domain\\Model\\Identity\\User');
     $this->users->shouldReceive('userById')->times(2)->andReturn($user, $friend);
     $user = $this->service->follow('7c5e8127-3f77-496c-9bb4-5cb092969d89', 'a3d9e532-0ea8-4572-8e83-119fc49e4c6f');
     $this->assertInstanceOf('Cribbb\\Domain\\Model\\Identity\\User', $user);
 }
 /**
  * Register a new User
  *
  * @param string $email
  * @param string $username
  * @param string $password
  * @return void
  */
 public function register($email, $username, $password)
 {
     $email = new Email($email);
     $username = new Username($username);
     $password = new Password($password);
     $this->checkEmailIsUnique($email);
     $this->checkUsernameIsUnique($username);
     $id = $this->userRepository->nextIdentity();
     $password = $this->hashingService->hash($password);
     $user = User::register($id, $email, $username, $password);
     $this->userRepository->add($user);
     return $user;
 }
Example #5
0
 /**
  * Attempt to find a user by their email address
  *
  * @param Email $email
  * @return User
  */
 private function findUserByEmail(Email $email)
 {
     $user = $this->users->userOfEmail($email);
     if ($user) {
         return $user;
     }
     throw new ValueNotFoundException("{$email} is not a registered email address");
 }
Example #6
0
 /** @test */
 public function should_return_false_when_not_unique()
 {
     $this->repository->shouldReceive('userOfEmail')->andReturn(['id' => 1]);
     $this->assertFalse($this->spec->isSatisfiedBy(new Email('*****@*****.**')));
 }
 /** @test */
 public function should_return_false_when_not_unique()
 {
     $this->repository->shouldReceive('userOfUsername')->andReturn(['id' => 1]);
     $this->assertFalse($this->spec->isSatisfiedBy(new Username('philipbrown')));
 }