From b2d50e3cfd49fc81c09604e217d8d27203ff2ad7 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Sun, 20 Jan 2019 12:54:39 +0100 Subject: [PATCH] Implemented AbstractRequestedRightFacade --- .../Action/RequestedAction.php | 5 - .../Right/AbstractRequestedRightFacade.php | 117 ++++++++++++++++++ .../Right/RequestedRight.php | 3 +- .../Right/RequestedRightInterface.php | 9 +- .../RequestManagement/User/RequestedUser.php | 69 +---------- .../AbstractRequestedRightFacadeTest.php | 89 +++++++++++++ 6 files changed, 213 insertions(+), 79 deletions(-) create mode 100644 application/symfony/src/Domain/RequestManagement/Right/AbstractRequestedRightFacade.php create mode 100644 application/symfony/tests/Unit/Domain/RequestManagement/Right/AbstractRequestedRightFacadeTest.php diff --git a/application/symfony/src/Domain/RequestManagement/Action/RequestedAction.php b/application/symfony/src/Domain/RequestManagement/Action/RequestedAction.php index 511204c..21a962b 100644 --- a/application/symfony/src/Domain/RequestManagement/Action/RequestedAction.php +++ b/application/symfony/src/Domain/RequestManagement/Action/RequestedAction.php @@ -26,11 +26,6 @@ class RequestedAction extends RequestedUser implements RequestedActionInterface ActionType::LIST => CRUDType::READ, ]; - /** - * @var RequestedRightInterface - */ - private $requestedRight; - /** * @param RequestedRightInterface $requestedRight */ diff --git a/application/symfony/src/Domain/RequestManagement/Right/AbstractRequestedRightFacade.php b/application/symfony/src/Domain/RequestManagement/Right/AbstractRequestedRightFacade.php new file mode 100644 index 0000000..8ab41e2 --- /dev/null +++ b/application/symfony/src/Domain/RequestManagement/Right/AbstractRequestedRightFacade.php @@ -0,0 +1,117 @@ +requestedRight = $requestedRight; + } + + /** + * {@inheritdoc} + * + * @see \App\Attribut\RecieverAttributInterface::getReciever() + */ + public function getReciever(): SourceInterface + { + return $this->requestedRight->getReciever(); + } + + /** + * {@inheritdoc} + * + * @see \App\Attribut\LayerAttributInterface::setLayer() + */ + public function setLayer(string $layer): void + { + $this->requestedRight->setLayer($layer); + } + + /** + * @deprecated + * {@inheritdoc} + * @see \App\Domain\RequestManagement\Right\RequestedRightInterface::getSource() + */ + public function getSource(): SourceInterface + { + return $this->requestedRight->getSource(); + } + + /** + * {@inheritdoc} + * + * @see \App\Attribut\LayerAttributInterface::getLayer() + */ + public function getLayer(): string + { + return $this->requestedRight->getLayer(); + } + + /** + * {@inheritdoc} + * + * @see \App\Attribut\RequestedEntityAttributInterface::setRequestedEntity() + */ + public function setRequestedEntity(RequestedEntityInterface $requestedEntity): void + { + $this->requestedRight->setRequestedEntity($requestedEntity); + } + + /** + * {@inheritdoc} + * + * @see \App\Attribut\CrudAttributInterface::setCrud() + */ + public function setCrud(string $crud): void + { + $this->requestedRight->setCrud($crud); + } + + /** + * {@inheritdoc} + * + * @see \App\Attribut\CrudAttributInterface::getCrud() + */ + public function getCrud(): string + { + return $this->requestedRight->getCrud(); + } + + /** + * {@inheritdoc} + * + * @see \App\Attribut\RequestedEntityAttributInterface::getRequestedEntity() + */ + public function getRequestedEntity(): RequestedEntityInterface + { + return $this->requestedRight->getRequestedEntity(); + } + + /** + * {@inheritdoc} + * + * @see \App\Attribut\RecieverAttributInterface::setReciever() + */ + public function setReciever(SourceInterface $reciever): void + { + $this->requestedRight->setReciever($reciever); + } +} diff --git a/application/symfony/src/Domain/RequestManagement/Right/RequestedRight.php b/application/symfony/src/Domain/RequestManagement/Right/RequestedRight.php index 4728a9f..f190da6 100644 --- a/application/symfony/src/Domain/RequestManagement/Right/RequestedRight.php +++ b/application/symfony/src/Domain/RequestManagement/Right/RequestedRight.php @@ -10,6 +10,7 @@ use App\Exception\PreconditionFailedException; use App\Exception\NotSetException; use App\Repository\Source\SourceRepositoryInterface; use App\Domain\RequestManagement\Entity\RequestedEntityInterface; +use App\Attribut\RequestedEntityAttribut; /** * @author kevinfrantz @@ -18,7 +19,7 @@ use App\Domain\RequestManagement\Entity\RequestedEntityInterface; */ class RequestedRight implements RequestedRightInterface { - use CrudAttribut, LayerAttribut, RecieverAttribut; + use CrudAttribut, LayerAttribut, RecieverAttribut, RequestedEntityAttribut; /** * @var SourceRepositoryInterface diff --git a/application/symfony/src/Domain/RequestManagement/Right/RequestedRightInterface.php b/application/symfony/src/Domain/RequestManagement/Right/RequestedRightInterface.php index c65d176..2eb4ad3 100644 --- a/application/symfony/src/Domain/RequestManagement/Right/RequestedRightInterface.php +++ b/application/symfony/src/Domain/RequestManagement/Right/RequestedRightInterface.php @@ -6,18 +6,13 @@ use App\Attribut\CrudAttributInterface; use App\Attribut\RecieverAttributInterface; use App\Attribut\LayerAttributInterface; use App\Entity\Source\SourceInterface; -use App\Domain\RequestManagement\Entity\RequestedEntityInterface; +use App\Attribut\RequestedEntityAttributInterface; /** * @author kevinfrantz */ -interface RequestedRightInterface extends CrudAttributInterface, RecieverAttributInterface, LayerAttributInterface +interface RequestedRightInterface extends CrudAttributInterface, RecieverAttributInterface, LayerAttributInterface, RequestedEntityAttributInterface { - /** - * @param RequestedEntityInterface $requestedSource - */ - public function setRequestedEntity(RequestedEntityInterface $requestedSource): void; - /** * {@inheritdoc} * diff --git a/application/symfony/src/Domain/RequestManagement/User/RequestedUser.php b/application/symfony/src/Domain/RequestManagement/User/RequestedUser.php index 5699cde..c14ed12 100644 --- a/application/symfony/src/Domain/RequestManagement/User/RequestedUser.php +++ b/application/symfony/src/Domain/RequestManagement/User/RequestedUser.php @@ -6,30 +6,25 @@ use App\Entity\Source\SourceInterface; use App\Domain\UserManagement\UserSourceDirectorInterface; use App\Exception\SetNotPossibleException; use App\Domain\RequestManagement\Right\RequestedRightInterface; -use App\Domain\RequestManagement\Entity\RequestedEntityInterface; +use App\Domain\RequestManagement\Right\AbstractRequestedRightFacade; /** * @author kevinfrantz */ -class RequestedUser implements RequestedUserInterface +class RequestedUser extends AbstractRequestedRightFacade implements RequestedUserInterface { /** * @var UserSourceDirectorInterface */ private $userSourceDirector; - /** - * @var RequestedRightInterface - */ - private $requestedRight; - /** * @param UserSourceDirectorInterface $userSourceDirector */ public function __construct(UserSourceDirectorInterface $userSourceDirector, RequestedRightInterface $requestedRight) { $this->userSourceDirector = $userSourceDirector; - $this->requestedRight = $requestedRight; + parent::__construct($requestedRight); } /** @@ -51,62 +46,4 @@ class RequestedUser implements RequestedUserInterface { return $this->userSourceDirector->getUser()->getSource(); } - - /** - * {@inheritdoc} - * - * @see \App\Attribut\LayerAttributInterface::setLayer() - */ - public function setLayer(string $layer): void - { - $this->requestedRight->setLayer($layer); - } - - /** - * {@inheritdoc} - * - * @see \App\Attribut\CrudAttributInterface::getCrud() - */ - public function getCrud(): string - { - return $this->requestedRight->getCrud(); - } - - /** - * {@inheritdoc} - * - * @see \App\Attribut\LayerAttributInterface::getLayer() - */ - public function getLayer(): string - { - return $this->requestedRight->getLayer(); - } - - /** - * {@inheritdoc} - * - * @see \App\Attribut\SourceAttributInterface::getSource() - */ - public function getSource(): SourceInterface - { - return $this->requestedRight->getSource(); - } - - /** - * {@inheritdoc} - * - * @see \App\Attribut\CrudAttributInterface::setCrud() - */ - public function setCrud(string $type): void - { - $this->requestedRight->setCrud($type); - } - - /** - * @param RequestedEntityInterface $requestedSource - */ - public function setRequestedEntity(RequestedEntityInterface $requestedSource): void - { - $this->requestedRight->setRequestedEntity($requestedSource); - } } diff --git a/application/symfony/tests/Unit/Domain/RequestManagement/Right/AbstractRequestedRightFacadeTest.php b/application/symfony/tests/Unit/Domain/RequestManagement/Right/AbstractRequestedRightFacadeTest.php new file mode 100644 index 0000000..1c965e9 --- /dev/null +++ b/application/symfony/tests/Unit/Domain/RequestManagement/Right/AbstractRequestedRightFacadeTest.php @@ -0,0 +1,89 @@ +requestedRight = $requestedRight; +// } + }; + } + + public function testGetters(): void + { + $reciever = $this->createMock(AbstractSource::class); + $user = $this->createMock(User::class); + $user->method('getSource')->willReturn($reciever); + $layer = LayerType::SOURCE; + $type = CRUDType::READ; + $requestedEntity = $this->createMock(RequestedEntityInterface::class); + $source = $this->createMock(AbstractSource::class); + $reciever = $this->createMock(AbstractSource::class); + $requestedRight = $this->createMock(RequestedRightInterface::class); + $requestedRight->method('getLayer')->willReturn($layer); + $requestedRight->method('getCrud')->willReturn($type); + $requestedRight->method('getSource')->willReturn($source); + $requestedRight->method('getReciever')->willReturn($reciever); + $requestedRight->method('getRequestedEntity')->willReturn($requestedEntity); + $requestedRightFacade = $this->getRequestedRightFacade($requestedRight); + $this->assertEquals($layer, $requestedRightFacade->getLayer()); + $this->assertEquals($type, $requestedRightFacade->getCrud()); + $this->assertEquals($source, $requestedRightFacade->getSource()); + $this->assertEquals($reciever, $requestedRightFacade->getReciever()); + $this->assertEquals($requestedEntity, $requestedRightFacade->getRequestedEntity()); + } + + public function testSetters(): void + { + $layer = LayerType::SOURCE; + $type = CRUDType::READ; + $reciever = $this->createMock(SourceInterface::class); + $requestedEntity = $this->createMock(RequestedEntityInterface::class); + $requestedEntity->method('getSlug')->willReturn(SystemSlugType::IMPRINT); + $requestedEntity->method('hasSlug')->willReturn(true); + $sourceRepository = $this->createMock(SourceRepositoryInterface::class); + $requestedRight = new RequestedRight($sourceRepository); + $requestedRightFacade = $this->getRequestedRightFacade($requestedRight); + $this->assertNull($requestedRightFacade->setLayer($layer)); + $this->assertNull($requestedRightFacade->setCrud($type)); + $this->assertNull($requestedRightFacade->setRequestedEntity($requestedEntity)); + $this->assertNull($requestedRightFacade->setReciever($reciever)); + $this->assertEquals($layer, $requestedRight->getLayer()); + $this->assertEquals($type, $requestedRight->getCrud()); + $this->assertEquals($requestedEntity, $requestedRight->getRequestedEntity()); + $this->assertEquals($reciever, $requestedRight->getReciever()); + } + + public function testSetReciever(): void + { + $reciever = $this->createMock(AbstractSource::class); + $userSourceDirector = $this->createMock(UserSourceDirectorInterface::class); + $requestedRight = $this->createMock(RequestedRightInterface::class); + $requestedUserRightFacade = new RequestedUser($userSourceDirector, $requestedRight); + $this->expectException(SetNotPossibleException::class); + $requestedUserRightFacade->setReciever($reciever); + } +}