Example #1
0
 /**
  * Find a Group by its id
  *
  * @param string $id
  * @return Group
  */
 private function findGroupById($id)
 {
     $group = $this->groups->groupById(GroupId::fromString($id));
     if ($group) {
         return $group;
     }
     throw new ValueNotFoundException("{$id} is not a valid group id");
 }
Example #2
0
 /**
  * Create a new Group
  *
  * @param User $user
  * @param string $name
  * @return Group
  */
 public function create(User $user, $name)
 {
     $this->checkNameIsUnique($name);
     $group = new Group(GroupId::generate(), $name);
     $group->addAdmin($user);
     $this->groups->add($group);
     return $group;
 }
Example #3
0
 /**
  * Find a Group by it's slug
  *
  * @param string $slug
  * @return Group
  */
 public function find($slug)
 {
     $group = $this->groups->groupBySlug($slug);
     if ($group) {
         return $group;
     }
     throw new ValueNotFoundException("{$slug} is not a valid Group slug");
 }
Example #4
0
 /** @test */
 public function should_create_new_group()
 {
     $this->groups->shouldReceive('groupOfName')->once()->andReturn(null);
     $this->groups->shouldReceive('add')->once()->andReturn(null);
     $this->user->shouldReceive('id')->once()->andReturn(UserId::generate());
     $this->user->shouldReceive('email')->once()->andReturn(new Email('*****@*****.**'));
     $this->user->shouldReceive('username')->once()->andReturn(new Username('username'));
     $group = $this->service->create($this->user, 'Cribbb');
     $this->assertInstanceOf('Cribbb\\Domain\\Model\\Groups\\Group', $group);
     $this->assertEquals('Cribbb', $group->name());
     $this->assertEquals(1, $group->admins()->count());
 }