From f931f824fb11886b967a3b576f74a8364899eae4 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Fri, 4 Jan 2019 22:09:05 +0100 Subject: [PATCH] Refactored code through substituting by PureSource --- .../src/Controller/DefaultController.php | 4 ++-- .../SourceMemberManagerIntegrationTest.php | 14 ++++---------- .../LawManagement/LawPermissionCheckerTest.php | 16 +++++----------- .../RightManagement/RightCheckerTest.php | 18 ++++++------------ .../SecureSourceCheckerTest.php | 2 +- .../SourceMemberInformationTest.php | 10 ++-------- .../SourceMemberManagerTest.php | 14 ++++---------- .../SourceRightManagerTest.php | 12 +++--------- .../Unit/Entity/Source/AbstractSourceTest.php | 10 ++-------- .../Collection/TreeCollectionSourceTest.php | 5 ++--- .../Unit/Entity/Source/PureSourceTest.php | 3 +++ 11 files changed, 34 insertions(+), 74 deletions(-) rename application/tests/Unit/Domain/{ => SecureSourceManagement}/SecureSourceCheckerTest.php (98%) diff --git a/application/src/Controller/DefaultController.php b/application/src/Controller/DefaultController.php index b157898..4abe19c 100644 --- a/application/src/Controller/DefaultController.php +++ b/application/src/Controller/DefaultController.php @@ -12,6 +12,7 @@ use App\DBAL\Types\LayerType; use App\DBAL\Types\RightType; use App\Domain\UserManagement\UserIdentityManager; use Doctrine\ORM\EntityManagerInterface; +use App\Entity\Source\PureSource; /** * This controller offers the standart routes for the template. @@ -28,8 +29,7 @@ final class DefaultController extends AbstractEntityController { $userIdentityManager = new UserIdentityManager($entityManager, $this->getUser()); $user = $userIdentityManager->getUser(); - $requestedSource = new class() extends AbstractSource { - }; + $requestedSource = new PureSource(); $requestedSource->setSlug(SystemSlugType::IMPRINT); $requestedRight = new Right(); $requestedRight->setSource($requestedSource); diff --git a/application/tests/Integration/Domain/SourceManagement/SourceMemberManagerIntegrationTest.php b/application/tests/Integration/Domain/SourceManagement/SourceMemberManagerIntegrationTest.php index 5b352c5..43efd0a 100644 --- a/application/tests/Integration/Domain/SourceManagement/SourceMemberManagerIntegrationTest.php +++ b/application/tests/Integration/Domain/SourceManagement/SourceMemberManagerIntegrationTest.php @@ -5,10 +5,10 @@ namespace Tests\Integration\Domain\SourceManagement; use PHPUnit\Framework\TestCase; use App\Entity\Source\SourceInterface; use App\Domain\SourceManagement\SourceMemberManagerInterface; -use App\Entity\Source\AbstractSource; use App\Domain\SourceManagement\SourceMemberManager; use App\Domain\SourceManagement\SourceMemberInformation; use App\Domain\SourceManagement\SourceMembershipInformation; +use App\Entity\Source\PureSource; class SourceMemberManagerIntegrationTest extends TestCase { @@ -22,21 +22,15 @@ class SourceMemberManagerIntegrationTest extends TestCase */ private $sourceMemberManager; - private function createSource(): SourceInterface - { - return new class() extends AbstractSource { - }; - } - public function setUp(): void { - $this->source = $this->createSource(); + $this->source = new PureSource(); $this->sourceMemberManager = new SourceMemberManager($this->source); } public function testSourceMemberInformationIntegration(): void { - $childSource = $this->createSource(); + $childSource = new PureSource(); $sourceMemberInformation = new SourceMemberInformation($this->source); $this->sourceMemberManager->addMember($childSource); $this->assertEquals($childSource, $sourceMemberInformation->getAllMembers()->get(0)); @@ -46,7 +40,7 @@ class SourceMemberManagerIntegrationTest extends TestCase public function testSourceMembershipInformationIntegration(): void { - $parentSource = $this->createSource(); + $parentSource = new PureSource(); $sourceMemberInformation = new SourceMembershipInformation($this->source); $this->sourceMemberManager->addMembership($parentSource); $this->assertEquals($parentSource, $sourceMemberInformation->getAllMemberships()->get(0)); diff --git a/application/tests/Unit/Domain/LawManagement/LawPermissionCheckerTest.php b/application/tests/Unit/Domain/LawManagement/LawPermissionCheckerTest.php index 6b144a7..8a410ff 100644 --- a/application/tests/Unit/Domain/LawManagement/LawPermissionCheckerTest.php +++ b/application/tests/Unit/Domain/LawManagement/LawPermissionCheckerTest.php @@ -6,7 +6,6 @@ use PHPUnit\Framework\TestCase; use App\Domain\LawManagement\LawPermissionCheckerService; use App\Domain\LawManagement\LawPermissionCheckerServiceInterface; use App\Entity\Source\SourceInterface; -use App\Entity\Source\AbstractSource; use App\Entity\Meta\Right; use App\DBAL\Types\LayerType; use App\DBAL\Types\RightType; @@ -15,6 +14,7 @@ use App\Entity\Meta\LawInterface; use App\Entity\Meta\RightInterface; use Doctrine\Common\Collections\ArrayCollection; use App\Domain\SourceManagement\SourceMemberManager; +use App\Entity\Source\PureSource; /** * @author kevinfrantz @@ -46,12 +46,6 @@ class LawPermissionCheckerTest extends TestCase */ private $source; - private function getSourceMock(): SourceInterface - { - return new class() extends AbstractSource { - }; - } - private function checkClientPermission(): bool { return $this->lawPermissionChecker->hasPermission($this->clientRight); @@ -79,13 +73,13 @@ class LawPermissionCheckerTest extends TestCase private function setSourceDummy(): void { - $this->source = $this->getSourceMock(); + $this->source = new PureSource(); $this->source->setSlug('Requested Source'); } private function setClientSourceDummy(): void { - $this->clientSource = $this->getSourceMock(); + $this->clientSource = new PureSource(); $this->clientSource->setSlug('Client Source'); } @@ -119,7 +113,7 @@ class LawPermissionCheckerTest extends TestCase public function testChildMemberPermission(): void { - $parentSource = $this->getSourceMock(); + $parentSource = new PureSource(); $parentSource->setSlug('Parent Source'); $parentSourceMemberManager = new SourceMemberManager($parentSource); $parentSourceMemberManager->addMember($this->clientSource); @@ -190,7 +184,7 @@ class LawPermissionCheckerTest extends TestCase $right1 = $this->getClonedClientRight(); $right1->setPriority(123); $right1->setGrant(false); - $right1->setReciever($this->getSourceMock()); + $right1->setReciever(new PureSource()); $right1->getReciever()->setSlug('Rigth1 Reciever'); $right2 = $this->getClonedClientRight(); $right2->setPriority(456); diff --git a/application/tests/Unit/Domain/RightManagement/RightCheckerTest.php b/application/tests/Unit/Domain/RightManagement/RightCheckerTest.php index 513ac46..e5ea8e6 100644 --- a/application/tests/Unit/Domain/RightManagement/RightCheckerTest.php +++ b/application/tests/Unit/Domain/RightManagement/RightCheckerTest.php @@ -6,11 +6,11 @@ use PHPUnit\Framework\TestCase; use App\Entity\Meta\RightInterface; use App\Entity\Meta\Right; use App\Entity\Source\SourceInterface; -use App\Entity\Source\AbstractSource; use App\DBAL\Types\LayerType; use App\Domain\RightManagement\RightCheckerInterface; use App\Domain\RightManagement\RightChecker; use App\DBAL\Types\RightType; +use App\Entity\Source\PureSource; class RightCheckerTest extends TestCase { @@ -39,17 +39,11 @@ class RightCheckerTest extends TestCase */ private $rightManager; - private function getSourceMock(): SourceInterface - { - return new class() extends AbstractSource { - }; - } - public function setUp(): void { $this->layer = LayerType::RELATION; $this->type = RightType::READ; - $this->source = $this->getSourceMock(); + $this->source = new PureSource(); $this->right = new Right(); $this->right->setReciever($this->source); $this->right->setType($this->type); @@ -68,13 +62,13 @@ class RightCheckerTest extends TestCase $this->right->setGrant(false); $notGranted3 = $this->rightManager->isGranted($this->layer, $this->type, $this->source); $this->assertFalse($notGranted3); - $notGranted4 = $this->rightManager->isGranted($this->layer, $this->type, $this->getSourceMock()); + $notGranted4 = $this->rightManager->isGranted($this->layer, $this->type, new PureSource()); $this->assertFalse($notGranted4); } public function testSecondDimension(): void { - $secondSource = $this->getSourceMock(); + $secondSource = new PureSource(); $this->source->getMemberRelation()->getMembers()->add($secondSource->getMemberRelation()); $granted = $this->rightManager->isGranted($this->layer, $this->type, $secondSource); $this->assertTrue($granted); @@ -89,8 +83,8 @@ class RightCheckerTest extends TestCase public function testThirdDimension(): void { - $thirdSource = $this->getSourceMock(); - $secondSource = $this->getSourceMock(); + $thirdSource = new PureSource(); + $secondSource = new PureSource(); $secondSource->getMemberRelation()->getMembers()->add($thirdSource->getMemberRelation()); $this->source->getMemberRelation()->getMembers()->add($secondSource->getMemberRelation()); $granted = $this->rightManager->isGranted($this->layer, $this->type, $thirdSource); diff --git a/application/tests/Unit/Domain/SecureSourceCheckerTest.php b/application/tests/Unit/Domain/SecureSourceManagement/SecureSourceCheckerTest.php similarity index 98% rename from application/tests/Unit/Domain/SecureSourceCheckerTest.php rename to application/tests/Unit/Domain/SecureSourceManagement/SecureSourceCheckerTest.php index 464cfda..d322d22 100644 --- a/application/tests/Unit/Domain/SecureSourceCheckerTest.php +++ b/application/tests/Unit/Domain/SecureSourceManagement/SecureSourceCheckerTest.php @@ -1,6 +1,6 @@ source = new UserSource(); @@ -75,7 +69,7 @@ class SourceMemberInformationTest extends TestCase public function testError(): void { $this->expectException(\Error::class); - $this->source->getMemberRelation()->getMembers()->add($this->createSourceMock()); + $this->source->getMemberRelation()->getMembers()->add(new PureSource()); $this->sourceMemberInformation->getAllMembers(); } } diff --git a/application/tests/Unit/Domain/SourceManagement/SourceMemberManagerTest.php b/application/tests/Unit/Domain/SourceManagement/SourceMemberManagerTest.php index 00e5705..912a121 100644 --- a/application/tests/Unit/Domain/SourceManagement/SourceMemberManagerTest.php +++ b/application/tests/Unit/Domain/SourceManagement/SourceMemberManagerTest.php @@ -5,8 +5,8 @@ namespace Tests\Unit\Domain\SourceManagement; use PHPUnit\Framework\TestCase; use App\Entity\Source\SourceInterface; use App\Domain\SourceManagement\SourceMemberManagerInterface; -use App\Entity\Source\AbstractSource; use App\Domain\SourceManagement\SourceMemberManager; +use App\Entity\Source\PureSource; class SourceMemberManagerTest extends TestCase { @@ -20,21 +20,15 @@ class SourceMemberManagerTest extends TestCase */ private $sourceMemberManager; - private function createSource(): SourceInterface - { - return new class() extends AbstractSource { - }; - } - public function setUp(): void { - $this->source = $this->createSource(); + $this->source = new PureSource(); $this->sourceMemberManager = new SourceMemberManager($this->source); } public function testAddAndRemoveMember(): void { - $member = $this->createSource(); + $member = new PureSource(); $this->assertNull($this->sourceMemberManager->addMember($member)); $this->assertEquals($member, $this->source->getMemberRelation()->getMembers()->get(0)->getSource()); $this->assertEquals($this->source, $member->getMemberRelation()->getMemberships()->get(0)->getSource()); @@ -45,7 +39,7 @@ class SourceMemberManagerTest extends TestCase public function testAddAndRemoveMembership(): void { - $membership = $this->createSource(); + $membership = new PureSource(); $this->assertNull($this->sourceMemberManager->addMembership($membership)); $this->assertEquals($membership, $this->source->getMemberRelation()->getMemberships()->get(0)->getSource()); $this->assertEquals($this->source, $membership->getMemberRelation()->getMembers()->get(0)->getSource()); diff --git a/application/tests/Unit/Domain/SourceManagement/SourceRightManagerTest.php b/application/tests/Unit/Domain/SourceManagement/SourceRightManagerTest.php index 1040127..d0eed83 100644 --- a/application/tests/Unit/Domain/SourceManagement/SourceRightManagerTest.php +++ b/application/tests/Unit/Domain/SourceManagement/SourceRightManagerTest.php @@ -5,7 +5,6 @@ namespace Unit\Domain\SourceManagement; use PHPUnit\Framework\TestCase; use App\Entity\Source\SourceInterface; use App\Domain\SourceManagement\SourceRightManagerInterface; -use App\Entity\Source\AbstractSource; use App\Domain\SourceManagement\SourceRightManager; use App\Entity\Meta\RightInterface; use App\Entity\Meta\Right; @@ -13,6 +12,7 @@ use App\Entity\Meta\Law; use App\Exception\AllreadySetException; use App\Exception\NotSetException; use App\Exception\AllreadyDefinedException; +use App\Entity\Source\PureSource; class SourceRightManagerTest extends TestCase { @@ -31,15 +31,9 @@ class SourceRightManagerTest extends TestCase */ private $right; - private function createSourceMock() - { - return new class() extends AbstractSource { - }; - } - public function setUp(): void { - $this->source = $this->createSourceMock(); + $this->source = new PureSource(); $this->sourceRightManager = new SourceRightManager($this->source); $this->right = new Right(); } @@ -53,7 +47,7 @@ class SourceRightManagerTest extends TestCase public function testSourceException(): void { - $this->right->setSource($this->createSourceMock()); + $this->right->setSource(new PureSource()); $this->expectException(AllreadyDefinedException::class); $this->sourceRightManager->addRight($this->right); } diff --git a/application/tests/Unit/Entity/Source/AbstractSourceTest.php b/application/tests/Unit/Entity/Source/AbstractSourceTest.php index 9ba854e..4d8f421 100644 --- a/application/tests/Unit/Entity/Source/AbstractSourceTest.php +++ b/application/tests/Unit/Entity/Source/AbstractSourceTest.php @@ -6,9 +6,9 @@ use PHPUnit\Framework\TestCase; use App\Entity\Source\SourceInterface; use App\Entity\Meta\LawInterface; use Doctrine\Common\Collections\Collection; -use App\Entity\Source\AbstractSource; use App\Entity\EntityInterface; use App\Entity\Meta\Relation\Parent\CreatorRelationInterface; +use App\Entity\Source\PureSource; /** * @author kevinfrantz @@ -20,15 +20,9 @@ class AbstractSourceTest extends TestCase */ protected $source; - private function getSourceDummy(): SourceInterface - { - return new class() extends AbstractSource { - }; - } - public function setUp() { - $this->source = $this->getSourceDummy(); + $this->source = new PureSource(); } public function testConstructor(): void diff --git a/application/tests/Unit/Entity/Source/Complex/Collection/TreeCollectionSourceTest.php b/application/tests/Unit/Entity/Source/Complex/Collection/TreeCollectionSourceTest.php index a61c629..ba4c773 100644 --- a/application/tests/Unit/Entity/Source/Complex/Collection/TreeCollectionSourceTest.php +++ b/application/tests/Unit/Entity/Source/Complex/Collection/TreeCollectionSourceTest.php @@ -5,9 +5,9 @@ namespace Tests\Unit\Entity\Source\Complex\Collection; use PHPUnit\Framework\TestCase; use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\ArrayCollection; -use App\Entity\Source\AbstractSource; use App\Entity\Source\Complex\Collection\TreeCollectionSourceInterface; use App\Entity\Source\Complex\Collection\TreeCollectionSource; +use App\Entity\Source\PureSource; /** * @author kevinfrantz @@ -32,8 +32,7 @@ class TreeCollectionSourceTest extends TestCase public function testAccessors() { - $member = new class() extends AbstractSource { - }; + $member = new PureSource(); $this->tree->setCollection(new ArrayCollection([ $member, ])); diff --git a/application/tests/Unit/Entity/Source/PureSourceTest.php b/application/tests/Unit/Entity/Source/PureSourceTest.php index 3dbfce0..2165bc5 100644 --- a/application/tests/Unit/Entity/Source/PureSourceTest.php +++ b/application/tests/Unit/Entity/Source/PureSourceTest.php @@ -8,6 +8,9 @@ use App\Entity\Source\PureSource; use App\Entity\Source\AbstractSource; use PHPUnit\Framework\TestCase; +/** + * @author kevinfrantz + */ class PureSourceTest extends TestCase { /**