From a66e2c3b4615b9bb466fcd0f912acdacfe6998f6 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Fri, 2 Nov 2018 21:38:04 +0100 Subject: [PATCH] Implemented TreeCollectionSource --- .../src/Entity/Attribut/MembersAttribut.php | 4 ++ .../CollectionDimensionHelperMethod.php | 22 +++++++++ .../src/Entity/Source/AbstractSource.php | 8 ++-- .../Collection/AbstractCollectionSource.php | 2 +- .../Collection/MemberCollectionSource.php | 16 ------- .../MemberCollectionSourceInterface.php | 12 ----- .../Collection/TreeCollectionSource.php | 20 +++++++++ .../TreeCollectionSourceInterface.php | 13 ++++++ .../Attribut/MembershipsAttributTest.php | 4 +- .../Collection/MemberCollectionSourceTest.php | 42 ----------------- .../Collection/TreeCollectionSourceTest.php | 45 +++++++++++++++++++ 11 files changed, 111 insertions(+), 77 deletions(-) create mode 100644 application/src/Entity/Method/CollectionDimensionHelperMethod.php delete mode 100644 application/src/Entity/Source/Collection/MemberCollectionSource.php delete mode 100644 application/src/Entity/Source/Collection/MemberCollectionSourceInterface.php create mode 100644 application/src/Entity/Source/Collection/TreeCollectionSource.php create mode 100644 application/src/Entity/Source/Collection/TreeCollectionSourceInterface.php delete mode 100644 application/tests/Unit/Entity/Source/Collection/MemberCollectionSourceTest.php create mode 100644 application/tests/Unit/Entity/Source/Collection/TreeCollectionSourceTest.php diff --git a/application/src/Entity/Attribut/MembersAttribut.php b/application/src/Entity/Attribut/MembersAttribut.php index 17d3133..007c767 100644 --- a/application/src/Entity/Attribut/MembersAttribut.php +++ b/application/src/Entity/Attribut/MembersAttribut.php @@ -8,6 +8,8 @@ use App\Helper\DimensionHelper; /** * @author kevinfrantz * + * @deprecated use instead CollectionDimensionHelper Method + * * @todo this attribut should be refactored to mapp fully on collections instead of members */ trait MembersAttribut @@ -31,6 +33,8 @@ trait MembersAttribut * @param int $dimension The dimensions start with 1 for the members of the actuall dimension and NULL for all members * @param Collection $members A reference to a members list, to which new members should be add * + * @deprecated Use Instead CollectionDimensionHelperMethod + * * @return Collection|MembersAttributInterface[] Returns all members till the defined dimension */ public function getMembersIncludingChildren(?int $dimension = null, Collection $members = null): Collection diff --git a/application/src/Entity/Method/CollectionDimensionHelperMethod.php b/application/src/Entity/Method/CollectionDimensionHelperMethod.php new file mode 100644 index 0000000..8756bbb --- /dev/null +++ b/application/src/Entity/Method/CollectionDimensionHelperMethod.php @@ -0,0 +1,22 @@ +getDimensions($dimension, $elements); + } +} diff --git a/application/src/Entity/Source/AbstractSource.php b/application/src/Entity/Source/AbstractSource.php index c19272f..96c5d93 100644 --- a/application/src/Entity/Source/AbstractSource.php +++ b/application/src/Entity/Source/AbstractSource.php @@ -13,8 +13,8 @@ use App\Entity\Attribut\LawAttribut; use App\Entity\Meta\LawInterface; use App\Entity\Meta\Law; use Doctrine\Common\Collections\ArrayCollection; -use App\Entity\Source\Collection\MemberCollectionSource; use App\Entity\Attribut\MembershipsAttribut; +use App\Entity\Source\Collection\TreeCollectionSourceInterface; /** * @author kevinfrantz @@ -24,7 +24,7 @@ use App\Entity\Attribut\MembershipsAttribut; * @ORM\Table(name="source") * @ORM\InheritanceType("JOINED") * @ORM\DiscriminatorColumn(name="discr", type="string") - * @ORM\DiscriminatorMap({"user" = "UserSource","name" = "NameSource","group" = "App\Entity\Source\Collection\MemberCollectionSource"}) + * @ORM\DiscriminatorMap({"user" = "UserSource","name" = "NameSource","collection" = "App\Entity\Source\Collection\AbstractCollectionSource","operation"="App\Entity\Source\Operation\AbstractOperation"}) */ abstract class AbstractSource extends AbstractEntity implements SourceInterface { @@ -42,8 +42,8 @@ abstract class AbstractSource extends AbstractEntity implements SourceInterface * @todo Implement that just one table on database level is needed! * @todo Rename table to use the right schema * - * @var Collection|MemberCollectionSource[] - * @ORM\ManyToMany(targetEntity="App\Entity\Source\Collection\MemberCollectionSource",mappedBy="collection") + * @var Collection|TreeCollectionSourceInterface[] + * @ORM\ManyToMany(targetEntity="App\Entity\Source\Collection\TreeCollectionSource",mappedBy="collection") */ protected $memberships; diff --git a/application/src/Entity/Source/Collection/AbstractCollectionSource.php b/application/src/Entity/Source/Collection/AbstractCollectionSource.php index 335e43e..dfafae4 100644 --- a/application/src/Entity/Source/Collection/AbstractCollectionSource.php +++ b/application/src/Entity/Source/Collection/AbstractCollectionSource.php @@ -14,7 +14,7 @@ use Doctrine\Common\Collections\ArrayCollection; * @ORM\Table(name="source_collection") * @ORM\InheritanceType("JOINED") * @ORM\DiscriminatorColumn(name="discr", type="string") - * @ORM\DiscriminatorMap({"member" = "MemberCollectionSource"}) + * @ORM\DiscriminatorMap({"member" = "TreeCollectionSource"}) * * @author kevinfrantz */ diff --git a/application/src/Entity/Source/Collection/MemberCollectionSource.php b/application/src/Entity/Source/Collection/MemberCollectionSource.php deleted file mode 100644 index 62dab16..0000000 --- a/application/src/Entity/Source/Collection/MemberCollectionSource.php +++ /dev/null @@ -1,16 +0,0 @@ -createMock(MemberCollectionSourceInterface::class); + $membership = $this->createMock(TreeCollectionSourceInterface::class); $this->assertNull($this->memberships->setMemberships(new ArrayCollection([$membership]))); $this->assertEquals($this->memberships->getMemberships()->get(0), $membership); } diff --git a/application/tests/Unit/Entity/Source/Collection/MemberCollectionSourceTest.php b/application/tests/Unit/Entity/Source/Collection/MemberCollectionSourceTest.php deleted file mode 100644 index 7453f8b..0000000 --- a/application/tests/Unit/Entity/Source/Collection/MemberCollectionSourceTest.php +++ /dev/null @@ -1,42 +0,0 @@ -groupSource = new MemberCollectionSource(); - } - - public function testConstructor(): void - { - $this->assertInstanceOf(Collection::class, $this->groupSource->getMembers()); - } - - public function testMembers() - { - $member = new class() extends AbstractSource { - }; - $this->groupSource->setMembers(new ArrayCollection([ - $member, - ])); - $this->assertEquals($member, $this->groupSource->getMembers() - ->get(0)); - } -} diff --git a/application/tests/Unit/Entity/Source/Collection/TreeCollectionSourceTest.php b/application/tests/Unit/Entity/Source/Collection/TreeCollectionSourceTest.php new file mode 100644 index 0000000..44829c7 --- /dev/null +++ b/application/tests/Unit/Entity/Source/Collection/TreeCollectionSourceTest.php @@ -0,0 +1,45 @@ +tree = new TreeCollectionSource(); + } + + public function testConstructor(): void + { + $this->assertInstanceOf(Collection::class, $this->tree->getMembers()); + $this->assertInstanceOf(TreeCollectionSourceInterface::class, $this->tree); + $this->assertInstanceOf(DimensionHelperInterface::class, $this->tree); + } + + public function testMembers() + { + $member = new class() extends AbstractSource { + }; + $this->tree->setMembers(new ArrayCollection([ + $member, + ])); + $this->assertEquals($member, $this->tree->getMembers() + ->get(0)); + } +}