From 17a6ee1dc6a5ccf4130d43ab265d3b4d442888b6 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Sun, 27 Jan 2019 18:38:21 +0100 Subject: [PATCH] Optimized Tests and attributes --- application/symfony/src/Attribut/LawAttribut.php | 8 ++++++++ application/symfony/src/Attribut/LayerAttribut.php | 4 +++- .../symfony/src/Attribut/LayerAttributInterface.php | 6 ++++++ .../Domain/ActionManagement/ActionFactoryService.php | 8 ++++++-- .../symfony/src/Exception/NoDefaultClassException.php | 10 ++++++++++ .../ActionManagement/ActionFactoryServiceTest.php | 5 ++--- .../RequestManagement/Action/RequestedActionTest.php | 10 ++++++++++ 7 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 application/symfony/src/Exception/NoDefaultClassException.php diff --git a/application/symfony/src/Attribut/LawAttribut.php b/application/symfony/src/Attribut/LawAttribut.php index ea740cf..eb9102e 100644 --- a/application/symfony/src/Attribut/LawAttribut.php +++ b/application/symfony/src/Attribut/LawAttribut.php @@ -6,6 +6,8 @@ use App\Entity\Meta\LawInterface; /** * @author kevinfrantz + * + * @see LawAttributInterface */ trait LawAttribut { @@ -14,11 +16,17 @@ trait LawAttribut */ protected $law; + /** + * @param LawInterface $law + */ public function setLaw(LawInterface $law): void { $this->law = $law; } + /** + * @return LawInterface + */ public function getLaw(): LawInterface { return $this->law; diff --git a/application/symfony/src/Attribut/LayerAttribut.php b/application/symfony/src/Attribut/LayerAttribut.php index e10ee7f..35033a5 100644 --- a/application/symfony/src/Attribut/LayerAttribut.php +++ b/application/symfony/src/Attribut/LayerAttribut.php @@ -7,6 +7,8 @@ use App\Exception\NoValidChoiceException; /** * @author kevinfrantz + * + * @see LayerAttributInterface */ trait LayerAttribut { @@ -25,7 +27,7 @@ trait LayerAttribut public function setLayer(string $layer): void { if (!array_key_exists($layer, LayerType::getChoices())) { - throw new NoValidChoiceException(); + throw new NoValidChoiceException("'$layer' is not a correct layer type."); } $this->layer = $layer; } diff --git a/application/symfony/src/Attribut/LayerAttributInterface.php b/application/symfony/src/Attribut/LayerAttributInterface.php index 2a2ed71..88e822e 100644 --- a/application/symfony/src/Attribut/LayerAttributInterface.php +++ b/application/symfony/src/Attribut/LayerAttributInterface.php @@ -7,7 +7,13 @@ namespace App\Attribut; */ interface LayerAttributInterface { + /** + * @param string $layer + */ public function setLayer(string $layer): void; + /** + * @return string + */ public function getLayer(): string; } diff --git a/application/symfony/src/Domain/ActionManagement/ActionFactoryService.php b/application/symfony/src/Domain/ActionManagement/ActionFactoryService.php index a14e266..b27ccf3 100644 --- a/application/symfony/src/Domain/ActionManagement/ActionFactoryService.php +++ b/application/symfony/src/Domain/ActionManagement/ActionFactoryService.php @@ -2,6 +2,8 @@ namespace App\Domain\ActionManagement; +use App\Exception\NoDefaultClassException; + /** * @author kevinfrantz */ @@ -56,8 +58,10 @@ final class ActionFactoryService extends AbstractActionConstructor implements Ac return $class; } $defaultClass = $this->getActionNamespace($action); - - return $defaultClass; + if (class_exists($defaultClass)) { + return $defaultClass; + } + throw new NoDefaultClassException("There is no default substitution class for $class with attributes {layer:\"$layer\",action:\"$action\"}"); } /** diff --git a/application/symfony/src/Exception/NoDefaultClassException.php b/application/symfony/src/Exception/NoDefaultClassException.php new file mode 100644 index 0000000..b5e4f9c --- /dev/null +++ b/application/symfony/src/Exception/NoDefaultClassException.php @@ -0,0 +1,10 @@ +createMock(RequestedRightInterface::class); + $requestedRight = new RequestedRight(); $this->requestedAction = new RequestedAction($requestedRight); $this->actionService = $this->createMock(ActionServiceInterface::class); $this->actionService->method('getRequestedAction')->willReturn($this->requestedAction); $this->actionFactoryService = new ActionFactoryService($this->actionService); } - public function testCreate(): void { foreach (ActionType::getChoices() as $action) { diff --git a/application/symfony/tests/Unit/Domain/RequestManagement/Action/RequestedActionTest.php b/application/symfony/tests/Unit/Domain/RequestManagement/Action/RequestedActionTest.php index 53336f9..a4452d4 100644 --- a/application/symfony/tests/Unit/Domain/RequestManagement/Action/RequestedActionTest.php +++ b/application/symfony/tests/Unit/Domain/RequestManagement/Action/RequestedActionTest.php @@ -10,6 +10,7 @@ use App\Domain\RequestManagement\Action\RequestedAction; use App\DBAL\Types\ActionType; use App\DBAL\Types\Meta\Right\CRUDType; use App\Repository\Source\SourceRepositoryInterface; +use App\DBAL\Types\Meta\Right\LayerType; /** * @author kevinfrantz @@ -54,4 +55,13 @@ class RequestedActionTest extends TestCase $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()); + } + } }