/** * Create a new Group * * @param string $user_id * @param string $name * @return Group */ public function create($user_id, $name) { $user = $this->findUserById($user_id); $group = $this->service->create($user, $name); /** Dispatch Domain Events */ return $group; }
/** @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()); }