From 662541cec2895c892ae5ab3bd9668a9b872a1520 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Tue, 15 Jan 2019 22:57:54 +0100 Subject: [PATCH] Optimized RequestManagement --- .../RequestedRight.php | 16 ++-- .../RequestedRightInterface.php | 3 +- .../RequestedRightService.php | 2 +- .../RequestedRightServiceInterface.php | 2 +- .../RequestedSource.php | 2 +- .../RequestedSourceInterface.php | 2 +- .../RequestedSourceService.php | 2 +- .../RequestedSourceServiceInterface.php | 10 +++ .../RequestedUserRightFacade.php | 8 +- .../RequestedUserRightFacadeInterface.php | 2 +- .../RequestedSourceServiceInterface.php | 7 -- .../UserManagement/UserSourceDirector.php | 11 ++- .../Repository/Source/SourceRepository.php | 19 ++-- .../Source/SourceRepositoryInterface.php | 32 +++++++ .../RequestedRightTest.php | 10 +-- .../RequestedUserRightFacadeTest.php | 86 +++++++++++++++++++ .../RightManagement/UserRightServiceTest.php | 23 ----- 17 files changed, 161 insertions(+), 76 deletions(-) rename application/symfony/src/Domain/{RightManagement/RightRequestManagement => RequestManagement}/RequestedRight.php (78%) rename application/symfony/src/Domain/{RightManagement/RightRequestManagement => RequestManagement}/RequestedRightInterface.php (84%) rename application/symfony/src/Domain/{RightManagement/RightRequestManagement => RequestManagement}/RequestedRightService.php (69%) rename application/symfony/src/Domain/{RightManagement/RightRequestManagement => RequestManagement}/RequestedRightServiceInterface.php (72%) rename application/symfony/src/Domain/{SourceManagement => RequestManagement}/RequestedSource.php (80%) rename application/symfony/src/Domain/{SourceManagement => RequestManagement}/RequestedSourceInterface.php (78%) rename application/symfony/src/Domain/{SourceManagement => RequestManagement}/RequestedSourceService.php (78%) create mode 100644 application/symfony/src/Domain/RequestManagement/RequestedSourceServiceInterface.php rename application/symfony/src/Domain/{RightManagement/RightRequestManagement => RequestManagement}/RequestedUserRightFacade.php (89%) rename application/symfony/src/Domain/{RightManagement/RightRequestManagement => RequestManagement}/RequestedUserRightFacadeInterface.php (73%) delete mode 100644 application/symfony/src/Domain/SourceManagement/RequestedSourceServiceInterface.php create mode 100644 application/symfony/src/Repository/Source/SourceRepositoryInterface.php rename application/symfony/tests/Unit/Domain/{RightManagement/RightRequestManagement => RequestManagement}/RequestedRightTest.php (88%) create mode 100644 application/symfony/tests/Unit/Domain/RequestManagement/RequestedUserRightFacadeTest.php delete mode 100644 application/symfony/tests/Unit/Domain/RightManagement/UserRightServiceTest.php diff --git a/application/symfony/src/Domain/RightManagement/RightRequestManagement/RequestedRight.php b/application/symfony/src/Domain/RequestManagement/RequestedRight.php similarity index 78% rename from application/symfony/src/Domain/RightManagement/RightRequestManagement/RequestedRight.php rename to application/symfony/src/Domain/RequestManagement/RequestedRight.php index 6474465..ca70df7 100644 --- a/application/symfony/src/Domain/RightManagement/RightRequestManagement/RequestedRight.php +++ b/application/symfony/src/Domain/RequestManagement/RequestedRight.php @@ -1,16 +1,14 @@ sourceRepository = $sourceRepository; } @@ -65,7 +63,7 @@ class RequestedRight implements RequestedRightInterface * * @see https://en.wikipedia.org/wiki/Lazy_loading * {@inheritdoc} - * @see \App\Domain\RightManagement\RightRequestManagement\RequestedRightInterface::getSource() + * @see \App\Domain\RequestManagement\RequestedRightInterface::getSource() */ final public function getSource(): SourceInterface { @@ -87,7 +85,7 @@ class RequestedRight implements RequestedRightInterface /** * {@inheritdoc} * - * @see \App\Domain\RightManagement\RightRequestManagement\RequestedRightInterface::setRequestedSource() + * @see \App\Domain\RequestManagement\RequestedRightInterface::setRequestedSource() */ final public function setRequestedSource(RequestedSourceInterface $requestedSource) { diff --git a/application/symfony/src/Domain/RightManagement/RightRequestManagement/RequestedRightInterface.php b/application/symfony/src/Domain/RequestManagement/RequestedRightInterface.php similarity index 84% rename from application/symfony/src/Domain/RightManagement/RightRequestManagement/RequestedRightInterface.php rename to application/symfony/src/Domain/RequestManagement/RequestedRightInterface.php index 54007af..522c1aa 100644 --- a/application/symfony/src/Domain/RightManagement/RightRequestManagement/RequestedRightInterface.php +++ b/application/symfony/src/Domain/RequestManagement/RequestedRightInterface.php @@ -1,11 +1,10 @@ requestedRight->setReciever($reciever); + throw new SetNotPossibleException('It\'s not possible to set the reciever!'); } /** @@ -103,7 +103,7 @@ final class RequestedUserRightFacade implements RequestedUserRightFacadeInterfac /** * {@inheritdoc} * - * @see \App\Domain\RightManagement\RightRequestManagement\RequestedRightInterface::setRequestedSource() + * @see \App\Domain\RequestManagement\RequestedRightInterface::setRequestedSource() */ public function setRequestedSource(RequestedSourceInterface $requestedSource) { diff --git a/application/symfony/src/Domain/RightManagement/RightRequestManagement/RequestedUserRightFacadeInterface.php b/application/symfony/src/Domain/RequestManagement/RequestedUserRightFacadeInterface.php similarity index 73% rename from application/symfony/src/Domain/RightManagement/RightRequestManagement/RequestedUserRightFacadeInterface.php rename to application/symfony/src/Domain/RequestManagement/RequestedUserRightFacadeInterface.php index a8118ef..986d4da 100644 --- a/application/symfony/src/Domain/RightManagement/RightRequestManagement/RequestedUserRightFacadeInterface.php +++ b/application/symfony/src/Domain/RequestManagement/RequestedUserRightFacadeInterface.php @@ -1,6 +1,6 @@ sourceRepository = $sourceRepository; $this->setUser($user); diff --git a/application/symfony/src/Repository/Source/SourceRepository.php b/application/symfony/src/Repository/Source/SourceRepository.php index 26e3f69..db3ba84 100644 --- a/application/symfony/src/Repository/Source/SourceRepository.php +++ b/application/symfony/src/Repository/Source/SourceRepository.php @@ -4,15 +4,13 @@ namespace App\Repository\Source; use Doctrine\ORM\EntityRepository; use App\Entity\Source\SourceInterface; -use App\Domain\SourceManagement\RequestedSourceInterface; +use App\Domain\RequestManagement\RequestedSourceInterface; -final class SourceRepository extends EntityRepository +/** + * @author kevinfrantz + */ +final class SourceRepository extends EntityRepository implements SourceRepositoryInterface { - /** - * @param string $slug - * - * @return SourceInterface|null - */ public function findOneBySlug(string $slug): ?SourceInterface { return $this->findOneBy([ @@ -20,13 +18,6 @@ final class SourceRepository extends EntityRepository ]); } - /** - * Loads a source by id or if not defined, by slug. - * - * @param RequestedSourceInterface $requestedSource - * - * @return SourceInterface|null - */ public function findOneByIdOrSlug(RequestedSourceInterface $requestedSource): ?SourceInterface { if ($requestedSource->hasId()) { diff --git a/application/symfony/src/Repository/Source/SourceRepositoryInterface.php b/application/symfony/src/Repository/Source/SourceRepositoryInterface.php new file mode 100644 index 0000000..1c0fc2a --- /dev/null +++ b/application/symfony/src/Repository/Source/SourceRepositoryInterface.php @@ -0,0 +1,32 @@ +createMock(UserSourceDirectorInterface::class); + $requestedRight = $this->createMock(RequestedRightInterface::class); + $requestedUserRightFacade = new RequestedUserRightFacade($userSourceDirector, $requestedRight); + $this->assertInstanceOf(RequestedRightInterface::class, $requestedUserRightFacade); + } + + 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; + $source = $this->createMock(AbstractSource::class); + $reciever = $this->createMock(AbstractSource::class); + $userSourceDirector = $this->createMock(UserSourceDirectorInterface::class); + $userSourceDirector->method('getUser')->willReturn($user); + $requestedRight = $this->createMock(RequestedRightInterface::class); + $requestedRight->method('getLayer')->willReturn($layer); + $requestedRight->method('getType')->willReturn($type); + $requestedRight->method('getSource')->willReturn($source); + $requestedUserRightFacade = new RequestedUserRightFacade($userSourceDirector, $requestedRight); + $this->assertEquals($layer, $requestedUserRightFacade->getLayer()); + $this->assertEquals($type, $requestedUserRightFacade->getType()); + $this->assertEquals($source, $requestedUserRightFacade->getSource()); + $this->assertEquals($reciever, $requestedUserRightFacade->getReciever()); + } + + public function testSetters(): void + { + $layer = LayerType::SOURCE; + $type = CRUDType::READ; + $requestedSource = $this->createMock(RequestedSourceInterface::class); + $requestedSource->method('getSlug')->willReturn(SystemSlugType::IMPRINT); + $requestedSource->method('hasSlug')->willReturn(true); + $sourceRepository = $this->createMock(SourceRepositoryInterface::class); + $requestedRight = new RequestedRight($sourceRepository); + $user = $this->createMock(User::class); + $userSourceDirector = new UserSourceDirector($sourceRepository, $user); + $requestedUserRightFacade = new RequestedUserRightFacade($userSourceDirector, $requestedRight); + $this->assertNull($requestedUserRightFacade->setLayer($layer)); + $this->assertNull($requestedUserRightFacade->setType($type)); + $this->assertNull($requestedUserRightFacade->setRequestedSource($requestedSource)); + $this->assertEquals($layer, $requestedRight->getLayer()); + $this->assertEquals($type, $requestedRight->getType()); + $this->expectException(NotSetException::class); + $this->assertNotInstanceOf(RequestedSourceInterface::class, $requestedRight->getSource()); + } + + public function testSetReciever(): void + { + $reciever = $this->createMock(AbstractSource::class); + $userSourceDirector = $this->createMock(UserSourceDirectorInterface::class); + $requestedRight = $this->createMock(RequestedRightInterface::class); + $requestedUserRightFacade = new RequestedUserRightFacade($userSourceDirector, $requestedRight); + $this->expectException(SetNotPossibleException::class); + $requestedUserRightFacade->setReciever($reciever); + } +} diff --git a/application/symfony/tests/Unit/Domain/RightManagement/UserRightServiceTest.php b/application/symfony/tests/Unit/Domain/RightManagement/UserRightServiceTest.php deleted file mode 100644 index d6045d5..0000000 --- a/application/symfony/tests/Unit/Domain/RightManagement/UserRightServiceTest.php +++ /dev/null @@ -1,23 +0,0 @@ -createMock(SourceInterface::class); - $user->setSource($source); - $userRight = new UserRightService($user); - $this->assertEquals($source, $userRight->getReciever()); - } -}