My team is trying to find out the best way to test one of our components; the main scope is to check if the user/actor has the right to complete the operation requested. The component is formed by many functions that usually have the following structure (simplified): Example language: PHP
public function addGroup($idEntity, $nameGroup){
if (!$this->logic->isEntityActive($idEntity)){
throw new EntityNotActiveException();
}
if ($idEntity != $this->getServiceLocator()->get('request')->getQuery()->get('idEntity')){
throw new NoRightsException();
}
if ($this->logic->isGroupWithNameAlreadyInDB($idEntity, $nameGroup)){
throw new GroupAlreadyExistException();
}
return $this->logic->addGroupToEntity($idEntity, $nameGroup);
}
As you can see this method has no "logic" per se (apart from the checks) and in the end it just forwards the request to the logic underneath. We are conflicted about how to correctly test this function. Do we mock everything? We can do it and in each test fake some "failures", but the problem remains that to test the correctness of the function you mock everything. Every single function. In that case you are not testing anything. We could really use some advice on this problem. Can anybody show us examples of a good way to test a function like this?
We use phpunit. Thank in advance for your help.