From 5f18245b73ae0d83d8f5d74f2174713778197e09 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Thu, 1 Nov 2018 19:59:36 +0100 Subject: [PATCH] Refactored Collection Sources --- .../Attribut/GroupSourcesAttribut.php | 2 +- .../GroupSourcesAttributInterface.php | 2 +- .../Attribut/SourceCollectionAttribut.php | 23 ++++++++++ .../SourceCollectionAttributInterface.php | 18 ++++++++ .../src/Entity/Source/AbstractSource.php | 5 ++- .../Collection/AbstractCollectionSource.php | 9 ++++ .../Collection/CollectionSourceInterface.php | 8 ++++ .../MemberCollectionSource.php} | 6 +-- .../MemberCollectionSourceInterface.php | 12 ++++++ .../Collection/Queue/QueueSourceInterface.php | 17 ++++++++ .../Entity/Source/GroupSourceInterface.php | 14 ------ .../src/Entity/Source/SourceInterface.php | 2 +- .../Entity/Attribut/MembersAttributTest.php | 15 ++++--- .../Collection/MemberCollectionSourceTest.php | 43 +++++++++++++++++++ .../Unit/Entity/Source/GroupSourceTest.php | 35 --------------- 15 files changed, 148 insertions(+), 63 deletions(-) rename application/src/Entity/{Source => }/Attribut/GroupSourcesAttribut.php (93%) rename application/src/Entity/{Source => }/Attribut/GroupSourcesAttributInterface.php (91%) create mode 100644 application/src/Entity/Attribut/SourceCollectionAttribut.php create mode 100644 application/src/Entity/Attribut/SourceCollectionAttributInterface.php create mode 100644 application/src/Entity/Source/Collection/AbstractCollectionSource.php create mode 100644 application/src/Entity/Source/Collection/CollectionSourceInterface.php rename application/src/Entity/Source/{GroupSource.php => Collection/MemberCollectionSource.php} (78%) create mode 100644 application/src/Entity/Source/Collection/MemberCollectionSourceInterface.php create mode 100644 application/src/Entity/Source/Collection/Queue/QueueSourceInterface.php delete mode 100644 application/src/Entity/Source/GroupSourceInterface.php create mode 100644 application/tests/Unit/Entity/Source/Collection/MemberCollectionSourceTest.php delete mode 100644 application/tests/Unit/Entity/Source/GroupSourceTest.php diff --git a/application/src/Entity/Source/Attribut/GroupSourcesAttribut.php b/application/src/Entity/Attribut/GroupSourcesAttribut.php similarity index 93% rename from application/src/Entity/Source/Attribut/GroupSourcesAttribut.php rename to application/src/Entity/Attribut/GroupSourcesAttribut.php index cf61781..a38ab8a 100644 --- a/application/src/Entity/Source/Attribut/GroupSourcesAttribut.php +++ b/application/src/Entity/Attribut/GroupSourcesAttribut.php @@ -1,6 +1,6 @@ membersAttribut = new class() implements MembersAttributInterface { + $this->membersAttribut = $this->getMembersAttributClassMock(); + } + + private function getMembersAttributClassMock():MembersAttributInterface{ + return new class implements MembersAttributInterface{ use MembersAttribut; }; } @@ -62,7 +65,7 @@ class MembersAttributTest extends AbstractTestCase public function testFirstLevelMembersInclusiveChildren(): void { - $source1 = new GroupSource(); + $source1 = $this->getMembersAttributClassMock(); $source2 = clone $source1; $source3 = clone $source1; $source4 = clone $source1; @@ -74,13 +77,14 @@ class MembersAttributTest extends AbstractTestCase public function test3DimensionsMembersInclusiveChildren(): void { - $source1 = new GroupSource(); + $source1 = $this->getMembersAttributClassMock(); $source2 = clone $source1; $source3 = clone $source1; $source4 = clone $source1; $source1->setMembers(new ArrayCollection([$source2])); $source2->setMembers(new ArrayCollection([$source3])); $source3->setMembers(new ArrayCollection([$source4])); + $source4->setMembers(new ArrayCollection()); $this->membersAttribut->setMembers(new ArrayCollection([$source1])); $this->assertEquals(1, $this->membersAttribut->getMembers()->count()); $this->assertEquals(1, $source1->getMembers()->count()); @@ -92,7 +96,8 @@ class MembersAttributTest extends AbstractTestCase public function testMembersIncludingChildrenInfinite(): void { - $source1 = new GroupSource(); + $source1 = $this->getMembersAttributClassMock(); + $source1->setMembers(new ArrayCollection()); $source2 = clone $source1; $source3 = clone $source1; $source4 = clone $source1; diff --git a/application/tests/Unit/Entity/Source/Collection/MemberCollectionSourceTest.php b/application/tests/Unit/Entity/Source/Collection/MemberCollectionSourceTest.php new file mode 100644 index 0000000..fe567ae --- /dev/null +++ b/application/tests/Unit/Entity/Source/Collection/MemberCollectionSourceTest.php @@ -0,0 +1,43 @@ +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/GroupSourceTest.php b/application/tests/Unit/Entity/Source/GroupSourceTest.php deleted file mode 100644 index d78fa29..0000000 --- a/application/tests/Unit/Entity/Source/GroupSourceTest.php +++ /dev/null @@ -1,35 +0,0 @@ -groupSource = new GroupSource(); - } - - public function testMembers() - { - $this->assertInstanceOf(Collection::class, $this->groupSource->getMembers()); - $member = new class() extends AbstractSource { - }; - $this->groupSource->setMembers(new ArrayCollection([$member])); - $this->assertEquals($member, $this->groupSource->getMembers()->get(0)); - } -}