Optimized Tests and attributes

This commit is contained in:
Kevin Frantz 2019-01-27 18:38:21 +01:00
parent 0593a8f1c3
commit 17a6ee1dc6
7 changed files with 45 additions and 6 deletions

View File

@ -6,6 +6,8 @@ use App\Entity\Meta\LawInterface;
/** /**
* @author kevinfrantz * @author kevinfrantz
*
* @see LawAttributInterface
*/ */
trait LawAttribut trait LawAttribut
{ {
@ -14,11 +16,17 @@ trait LawAttribut
*/ */
protected $law; protected $law;
/**
* @param LawInterface $law
*/
public function setLaw(LawInterface $law): void public function setLaw(LawInterface $law): void
{ {
$this->law = $law; $this->law = $law;
} }
/**
* @return LawInterface
*/
public function getLaw(): LawInterface public function getLaw(): LawInterface
{ {
return $this->law; return $this->law;

View File

@ -7,6 +7,8 @@ use App\Exception\NoValidChoiceException;
/** /**
* @author kevinfrantz * @author kevinfrantz
*
* @see LayerAttributInterface
*/ */
trait LayerAttribut trait LayerAttribut
{ {
@ -25,7 +27,7 @@ trait LayerAttribut
public function setLayer(string $layer): void public function setLayer(string $layer): void
{ {
if (!array_key_exists($layer, LayerType::getChoices())) { if (!array_key_exists($layer, LayerType::getChoices())) {
throw new NoValidChoiceException(); throw new NoValidChoiceException("'$layer' is not a correct layer type.");
} }
$this->layer = $layer; $this->layer = $layer;
} }

View File

@ -7,7 +7,13 @@ namespace App\Attribut;
*/ */
interface LayerAttributInterface interface LayerAttributInterface
{ {
/**
* @param string $layer
*/
public function setLayer(string $layer): void; public function setLayer(string $layer): void;
/**
* @return string
*/
public function getLayer(): string; public function getLayer(): string;
} }

View File

@ -2,6 +2,8 @@
namespace App\Domain\ActionManagement; namespace App\Domain\ActionManagement;
use App\Exception\NoDefaultClassException;
/** /**
* @author kevinfrantz * @author kevinfrantz
*/ */
@ -56,8 +58,10 @@ final class ActionFactoryService extends AbstractActionConstructor implements Ac
return $class; return $class;
} }
$defaultClass = $this->getActionNamespace($action); $defaultClass = $this->getActionNamespace($action);
if (class_exists($defaultClass)) {
return $defaultClass; return $defaultClass;
}
throw new NoDefaultClassException("There is no default substitution class for $class with attributes {layer:\"$layer\",action:\"$action\"}");
} }
/** /**

View File

@ -0,0 +1,10 @@
<?php
namespace App\Exception;
/**
* @author kevinfrantz
*/
final class NoDefaultClassException extends \Exception
{
}

View File

@ -11,7 +11,7 @@ use App\DBAL\Types\ActionType;
use App\Domain\ActionManagement\ActionInterface; use App\Domain\ActionManagement\ActionInterface;
use App\Domain\RequestManagement\Action\RequestedActionInterface; use App\Domain\RequestManagement\Action\RequestedActionInterface;
use App\Domain\RequestManagement\Action\RequestedAction; use App\Domain\RequestManagement\Action\RequestedAction;
use App\Domain\RequestManagement\Right\RequestedRightInterface; use App\Domain\RequestManagement\Right\RequestedRight;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -35,14 +35,13 @@ class ActionFactoryServiceTest extends TestCase
public function setUp(): void public function setUp(): void
{ {
$requestedRight = $this->createMock(RequestedRightInterface::class); $requestedRight = new RequestedRight();
$this->requestedAction = new RequestedAction($requestedRight); $this->requestedAction = new RequestedAction($requestedRight);
$this->actionService = $this->createMock(ActionServiceInterface::class); $this->actionService = $this->createMock(ActionServiceInterface::class);
$this->actionService->method('getRequestedAction')->willReturn($this->requestedAction); $this->actionService->method('getRequestedAction')->willReturn($this->requestedAction);
$this->actionFactoryService = new ActionFactoryService($this->actionService); $this->actionFactoryService = new ActionFactoryService($this->actionService);
} }
public function testCreate(): void public function testCreate(): void
{ {
foreach (ActionType::getChoices() as $action) { foreach (ActionType::getChoices() as $action) {

View File

@ -10,6 +10,7 @@ use App\Domain\RequestManagement\Action\RequestedAction;
use App\DBAL\Types\ActionType; use App\DBAL\Types\ActionType;
use App\DBAL\Types\Meta\Right\CRUDType; use App\DBAL\Types\Meta\Right\CRUDType;
use App\Repository\Source\SourceRepositoryInterface; use App\Repository\Source\SourceRepositoryInterface;
use App\DBAL\Types\Meta\Right\LayerType;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -54,4 +55,13 @@ class RequestedActionTest extends TestCase
$this->assertEquals($crud, $this->requestedRight->getCrud()); $this->assertEquals($crud, $this->requestedRight->getCrud());
} }
} }
public function testLayer(): void
{
foreach (LayerType::getChoices() as $LayerType) {
$this->action->setLayer($LayerType);
$this->assertEquals($LayerType, $this->action->getLayer());
$this->assertEquals($LayerType, $this->requestedRight->getLayer());
}
}
} }