From f3c2286a64a2c04cd8a5a5c37e66d68b3fdc11fa Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Sun, 3 Feb 2019 01:01:26 +0100 Subject: [PATCH] Optimized RequestManagement --- .../Action/RequestedAction.php | 11 ++-- .../Action/RequestedActionService.php | 10 +-- .../RequestedActionServiceInterface.php | 2 +- .../src/Domain/RequestManagement/README.md | 13 ++-- .../Right/RequestedRightService.php | 2 +- .../UserManagement/UserSourceDirector.php | 4 +- .../CreateSourceActionIntegrationTest.php | 64 +++++++++++++++++++ .../ActionFactoryServiceTest.php | 6 +- .../Action/RequestedActionServiceTest.php | 8 ++- .../Action/RequestedActionTest.php | 12 +++- 10 files changed, 109 insertions(+), 23 deletions(-) create mode 100644 application/symfony/tests/Integration/Domain/ActionManagement/Create/CreateSourceActionIntegrationTest.php diff --git a/application/symfony/src/Domain/RequestManagement/Action/RequestedAction.php b/application/symfony/src/Domain/RequestManagement/Action/RequestedAction.php index 23cd767..b5dd70d 100644 --- a/application/symfony/src/Domain/RequestManagement/Action/RequestedAction.php +++ b/application/symfony/src/Domain/RequestManagement/Action/RequestedAction.php @@ -6,7 +6,8 @@ use App\Attribut\ActionTypeAttribut; use App\DBAL\Types\ActionType; use App\DBAL\Types\Meta\Right\CRUDType; use App\Domain\RequestManagement\User\RequestedUser; -use App\Domain\RequestManagement\Right\RequestedRightInterface; +use App\Domain\RequestManagement\User\RequestedUserInterface; +use App\Domain\UserManagement\UserSourceDirectorInterface; /** * @author kevinfrantz @@ -27,11 +28,13 @@ class RequestedAction extends RequestedUser implements RequestedActionInterface ]; /** - * @param RequestedRightInterface $requestedRight + * {@inheritdoc} + * + * @see \App\Domain\RequestManagement\User\RequestedUser::__construct() */ - public function __construct(RequestedRightInterface $requestedRight) + public function __construct(UserSourceDirectorInterface $userSourceDirector, RequestedUserInterface $requestedUser) { - $this->requestedRight = $requestedRight; + parent::__construct($userSourceDirector, $requestedUser); } /** diff --git a/application/symfony/src/Domain/RequestManagement/Action/RequestedActionService.php b/application/symfony/src/Domain/RequestManagement/Action/RequestedActionService.php index c26c3ff..941a728 100644 --- a/application/symfony/src/Domain/RequestManagement/Action/RequestedActionService.php +++ b/application/symfony/src/Domain/RequestManagement/Action/RequestedActionService.php @@ -2,7 +2,8 @@ namespace App\Domain\RequestManagement\Action; -use App\Domain\RequestManagement\Right\RequestedRightServiceInterface; +use App\Domain\RequestManagement\User\RequestedUserServiceInterface; +use App\Domain\UserManagement\UserSourceDirectorInterface; /** * @author kevinfrantz @@ -10,10 +11,11 @@ use App\Domain\RequestManagement\Right\RequestedRightServiceInterface; final class RequestedActionService extends RequestedAction implements RequestedActionServiceInterface { /** - * @param RequestedRightServiceInterface $requestedRightService + * @param UserSourceDirectorInterface $userSourceDirector + * @param RequestedUserServiceInterface $requestedUserService */ - public function __construct(RequestedRightServiceInterface $requestedRightService) + public function __construct(UserSourceDirectorInterface $userSourceDirector, RequestedUserServiceInterface $requestedUserService) { - parent::__construct($requestedRightService); + parent::__construct($userSourceDirector, $requestedUserService); } } diff --git a/application/symfony/src/Domain/RequestManagement/Action/RequestedActionServiceInterface.php b/application/symfony/src/Domain/RequestManagement/Action/RequestedActionServiceInterface.php index be8e944..d7dc186 100644 --- a/application/symfony/src/Domain/RequestManagement/Action/RequestedActionServiceInterface.php +++ b/application/symfony/src/Domain/RequestManagement/Action/RequestedActionServiceInterface.php @@ -9,6 +9,6 @@ namespace App\Domain\RequestManagement\Action; * * @author kevinfrantz */ -interface RequestedActionServiceInterface +interface RequestedActionServiceInterface extends RequestedActionInterface { } diff --git a/application/symfony/src/Domain/RequestManagement/README.md b/application/symfony/src/Domain/RequestManagement/README.md index e5bca2a..864c98a 100644 --- a/application/symfony/src/Domain/RequestManagement/README.md +++ b/application/symfony/src/Domain/RequestManagement/README.md @@ -3,10 +3,13 @@ The request management works with different layers. ### Layers Each layer contains out of __2 classes__ and __2 interfaces__ for it. -One class contains the __logic__ and the other class contains the __service__. This makes the classes easier testable and mockable and follows the [SOLID Design Principles](https://en.wikipedia.org/wiki/SOLID). The layer order you can keep in mind with the acronym __RUAE__: __R__ight__U__ser__A__ction__E__ntity. +One class contains the __logic__ and the other class contains the __service__. This makes the classes easier testable and mockable and follows the [SOLID Design Principles](https://en.wikipedia.org/wiki/SOLID). -#### Right -This is the basic request layer from which the other layers inhiere. -#### User -#### Action #### Entity +A **requested entity** contains the attributes to manage the entity which should be handled by an action +#### Right +This is the basic request layer from which the other layers inhiere. The relation from a **requested right** to a **requested entity** is 1:0,1 +#### User +A **requested user** contains is a parent of **requested action**. +#### Action +A **requested action** contains inhieres from **requested user**. diff --git a/application/symfony/src/Domain/RequestManagement/Right/RequestedRightService.php b/application/symfony/src/Domain/RequestManagement/Right/RequestedRightService.php index e9ae81d..490933f 100644 --- a/application/symfony/src/Domain/RequestManagement/Right/RequestedRightService.php +++ b/application/symfony/src/Domain/RequestManagement/Right/RequestedRightService.php @@ -7,6 +7,6 @@ namespace App\Domain\RequestManagement\Right; * * @author kevinfrantz */ -final class RequestedRightService extends RequestedRight +final class RequestedRightService extends RequestedRight implements RequestedRightServiceInterface { } diff --git a/application/symfony/src/Domain/UserManagement/UserSourceDirector.php b/application/symfony/src/Domain/UserManagement/UserSourceDirector.php index 497cdc4..716bc3e 100644 --- a/application/symfony/src/Domain/UserManagement/UserSourceDirector.php +++ b/application/symfony/src/Domain/UserManagement/UserSourceDirector.php @@ -3,9 +3,9 @@ namespace App\Domain\UserManagement; use App\Entity\UserInterface; -use App\DBAL\Types\SystemSlugType; use App\Entity\User; use App\Repository\Source\SourceRepositoryInterface; +use App\Domain\FixtureManagement\FixtureSource\GuestUserFixtureSource; /** * @author kevinfrantz @@ -33,7 +33,7 @@ final class UserSourceDirector implements UserSourceDirectorInterface return; } $this->user = new User(); - $this->user->setSource($this->sourceRepository->findOneBySlug(SystemSlugType::GUEST_USER)); + $this->user->setSource($this->sourceRepository->findOneBySlug(GuestUserFixtureSource::getSlug())); } /** diff --git a/application/symfony/tests/Integration/Domain/ActionManagement/Create/CreateSourceActionIntegrationTest.php b/application/symfony/tests/Integration/Domain/ActionManagement/Create/CreateSourceActionIntegrationTest.php new file mode 100644 index 0000000..dc37ff8 --- /dev/null +++ b/application/symfony/tests/Integration/Domain/ActionManagement/Create/CreateSourceActionIntegrationTest.php @@ -0,0 +1,64 @@ +getContainer()->get('doctrine')->getManager(); +// $requestedRightService = new RequestedRightService(); +// $this->requestedActionService = new RequestedActionService($requestedRightService); +// $this->requestedActionService->setActionType(ActionType::CREATE); +// $entityFormBuilderService = $this->createMock(EntityFormBuilderServiceInterface::class); +// $requestStack = $this->createMock(RequestStack::class); +// $layerRepositoryFactoryService = $this->createMock(LayerRepositoryFactoryServiceInterface::class); +// $secureRequestedRightChecker = $this->createMock(SecureRequestedRightCheckerInterface::class); +// $this->actionService = new ActionService($this->requestedActionService, $secureRequestedRightChecker, $requestStack, $layerRepositoryFactoryService, $entityFormBuilderService, $entityManager); +// $this->createSourceAction = new CreateSourceAction($this->actionService); +// } + +// public function testCreateWithGuestUser(): void +// { +// $this->requestedActionService->setReciever($reciever); +// $this->assertInstanceOf(PureSourceInterface::class, $this->createSourceAction->execute()); +// } + +// public function testCreatedWithKnownUser(): void +// { +// } +} diff --git a/application/symfony/tests/Unit/Domain/ActionManagement/ActionFactoryServiceTest.php b/application/symfony/tests/Unit/Domain/ActionManagement/ActionFactoryServiceTest.php index a2dc9d0..fca61b1 100644 --- a/application/symfony/tests/Unit/Domain/ActionManagement/ActionFactoryServiceTest.php +++ b/application/symfony/tests/Unit/Domain/ActionManagement/ActionFactoryServiceTest.php @@ -11,6 +11,8 @@ use App\Domain\RequestManagement\Action\RequestedActionInterface; use App\Domain\RequestManagement\Action\RequestedAction; use App\Domain\RequestManagement\Right\RequestedRight; use App\Domain\LayerManagement\LayerActionMap; +use App\Domain\RequestManagement\User\RequestedUser; +use App\Domain\UserManagement\UserSourceDirectorInterface; /** * @author kevinfrantz @@ -35,7 +37,9 @@ class ActionFactoryServiceTest extends TestCase public function setUp(): void { $requestedRight = new RequestedRight(); - $this->requestedAction = new RequestedAction($requestedRight); + $userSourceDirector = $this->createMock(UserSourceDirectorInterface::class); + $requestedUser = new RequestedUser($userSourceDirector, $requestedRight); + $this->requestedAction = new RequestedAction($userSourceDirector, $requestedUser); $this->actionService = $this->createMock(ActionServiceInterface::class); $this->actionService->method('getRequestedAction')->willReturn($this->requestedAction); $this->actionFactoryService = new ActionFactoryService($this->actionService); diff --git a/application/symfony/tests/Unit/Domain/RequestManagement/Action/RequestedActionServiceTest.php b/application/symfony/tests/Unit/Domain/RequestManagement/Action/RequestedActionServiceTest.php index 74c0c7d..5cb18f3 100644 --- a/application/symfony/tests/Unit/Domain/RequestManagement/Action/RequestedActionServiceTest.php +++ b/application/symfony/tests/Unit/Domain/RequestManagement/Action/RequestedActionServiceTest.php @@ -3,9 +3,10 @@ namespace tests\Unit\Domain\RequestManagement\Action; use PHPUnit\Framework\TestCase; -use App\Domain\RequestManagement\Right\RequestedRightServiceInterface; use App\Domain\RequestManagement\Action\RequestedActionService; use App\Domain\RequestManagement\Action\RequestedActionServiceInterface; +use App\Domain\RequestManagement\User\RequestedUserServiceInterface; +use App\Domain\UserManagement\UserSourceDirectorInterface; /** * @author kevinfrantz @@ -14,8 +15,9 @@ class RequestedActionServiceTest extends TestCase { public function testConstructorSet(): void { - $requestedRightService = $this->createMock(RequestedRightServiceInterface::class); - $service = new RequestedActionService($requestedRightService); + $userSourceDirector = $this->createMock(UserSourceDirectorInterface::class); + $requestedUserService = $this->createMock(RequestedUserServiceInterface::class); + $service = new RequestedActionService($userSourceDirector, $requestedUserService); $this->assertInstanceOf(RequestedActionServiceInterface::class, $service); } } diff --git a/application/symfony/tests/Unit/Domain/RequestManagement/Action/RequestedActionTest.php b/application/symfony/tests/Unit/Domain/RequestManagement/Action/RequestedActionTest.php index e06ed55..afff0cd 100644 --- a/application/symfony/tests/Unit/Domain/RequestManagement/Action/RequestedActionTest.php +++ b/application/symfony/tests/Unit/Domain/RequestManagement/Action/RequestedActionTest.php @@ -11,6 +11,9 @@ use App\DBAL\Types\ActionType; use App\DBAL\Types\Meta\Right\CRUDType; use App\Repository\Source\SourceRepositoryInterface; use App\DBAL\Types\Meta\Right\LayerType; +use App\Domain\UserManagement\UserSourceDirector; +use App\Domain\RequestManagement\User\RequestedUser; +use App\Entity\Source\Complex\UserSourceInterface; /** * @author kevinfrantz @@ -34,9 +37,14 @@ class RequestedActionTest extends TestCase */ public function setUp(): void { + $userSource = $this->createMock(UserSourceInterface::class); $sourceRepository = $this->createMock(SourceRepositoryInterface::class); - $this->requestedRight = new RequestedRight($sourceRepository); - $this->action = new RequestedAction($this->requestedRight); + $sourceRepository->method('findOneBySlug')->willReturn($userSource); + $user = null; + $userSourceDirector = new UserSourceDirector($sourceRepository, $user); + $requestedRight = new RequestedRight(); + $this->requestedRight = new RequestedUser($userSourceDirector, $requestedRight); + $this->action = new RequestedAction($userSourceDirector, $this->requestedRight); } public function testList(): void