diff --git a/application/src/Entity/Attribut/MembersAttribut.php b/application/src/Entity/Attribut/MembersAttribut.php new file mode 100644 index 0000000..9b47c25 --- /dev/null +++ b/application/src/Entity/Attribut/MembersAttribut.php @@ -0,0 +1,33 @@ +memberships; + } + + /** + * @param Collection|SourceInterface[] $members + */ + public function setMembers(Collection $members): void + { + $this->memberships = $members; + } +} diff --git a/application/src/Entity/Attribut/MembersAttributInterface.php b/application/src/Entity/Attribut/MembersAttributInterface.php new file mode 100644 index 0000000..9eaff9a --- /dev/null +++ b/application/src/Entity/Attribut/MembersAttributInterface.php @@ -0,0 +1,22 @@ +relation->setSource($this); $this->law = new Law(); $this->memberships = new ArrayCollection(); + $this->members = new ArrayCollection(); } } diff --git a/application/src/Entity/Source/Complex/Collection/AbstractCollectionSource.php b/application/src/Entity/Source/Complex/Collection/AbstractCollectionSource.php index f7aa1d7..56023fe 100644 --- a/application/src/Entity/Source/Complex/Collection/AbstractCollectionSource.php +++ b/application/src/Entity/Source/Complex/Collection/AbstractCollectionSource.php @@ -18,8 +18,11 @@ abstract class AbstractCollectionSource extends AbstractSource implements Collec /** * @var Collection|SourceInterface[] - * @ORM\ManyToMany(targetEntity="App\Entity\Source\AbstractSource",inversedBy="memberships") - * @ORM\JoinTable(name="source_group_members") + * @ORM\ManyToMany(targetEntity="App\Entity\Source\AbstractSource") + * @ORM\JoinTable(name="collection_source", + * joinColumns={@ORM\JoinColumn(name="collection_id", referencedColumnName="id")}, + * inverseJoinColumns={@ORM\JoinColumn(name="source_id", referencedColumnName="id")} + * ) */ protected $collection; diff --git a/application/src/Entity/Source/Complex/Collection/TreeCollectionSource.php b/application/src/Entity/Source/Complex/Collection/TreeCollectionSource.php index 4601f84..326f7fe 100644 --- a/application/src/Entity/Source/Complex/Collection/TreeCollectionSource.php +++ b/application/src/Entity/Source/Complex/Collection/TreeCollectionSource.php @@ -3,7 +3,6 @@ namespace App\Entity\Source\Complex\Collection; use Doctrine\ORM\Mapping as ORM; -use App\Entity\Attribut\CollectionAttribut; /** * @author kevinfrantz @@ -11,5 +10,4 @@ use App\Entity\Attribut\CollectionAttribut; */ class TreeCollectionSource extends AbstractCollectionSource implements TreeCollectionSourceInterface { - use CollectionAttribut; } diff --git a/application/src/Entity/Source/SourceInterface.php b/application/src/Entity/Source/SourceInterface.php index f7702c5..608fa39 100644 --- a/application/src/Entity/Source/SourceInterface.php +++ b/application/src/Entity/Source/SourceInterface.php @@ -8,10 +8,11 @@ use App\Entity\Attribut\LawAttributInterface; use App\Entity\Attribut\RelationAttributInterface; use App\Entity\Attribut\MembershipsAttributInterface; use App\Entity\Attribut\SlugAttributInterface; +use App\Entity\Attribut\MembersAttributInterface; /** * @author kevinfrantz */ -interface SourceInterface extends IdAttributInterface, EntityInterface, MembershipsAttributInterface, LawAttributInterface, RelationAttributInterface, SlugAttributInterface +interface SourceInterface extends IdAttributInterface, EntityInterface, MembershipsAttributInterface, LawAttributInterface, RelationAttributInterface, SlugAttributInterface, MembersAttributInterface { } diff --git a/application/tests/Unit/Entity/Attribut/MembersAttributTest.php b/application/tests/Unit/Entity/Attribut/MembersAttributTest.php new file mode 100644 index 0000000..e5dd68d --- /dev/null +++ b/application/tests/Unit/Entity/Attribut/MembersAttributTest.php @@ -0,0 +1,37 @@ +members = new class() implements MembersAttributInterface { + use MembersAttribut; + }; + } + + public function testConstructor(): void + { + $this->expectException(\TypeError::class); + $this->members->getMembers(); + } + + public function testAccessors(): void + { + $membership = $this->createMock(SourceInterface::class); + $this->assertNull($this->members->setMembers(new ArrayCollection([$membership]))); + $this->assertEquals($this->members->getMembers()->get(0), $membership); + } +} diff --git a/application/tests/Unit/Entity/Source/AbstractSourceTest.php b/application/tests/Unit/Entity/Source/AbstractSourceTest.php index 26dada2..362d253 100644 --- a/application/tests/Unit/Entity/Source/AbstractSourceTest.php +++ b/application/tests/Unit/Entity/Source/AbstractSourceTest.php @@ -32,6 +32,7 @@ class AbstractSourceTest extends TestCase $this->assertInstanceOf(RelationInterface::class, $this->source->getRelation()); $this->assertInstanceOf(Collection::class, $this->source->getMemberships()); $this->assertInstanceOf(LawInterface::class, $this->source->getLaw()); + $this->assertInstanceOf(Collection::class, $this->source->getMembers()); } public function testSlugInit(): void diff --git a/application/tests/Unit/Repository/UserSourceRepositoryTest.php b/application/tests/Unit/Repository/UserSourceRepositoryTest.php index 102144e..b7734d8 100644 --- a/application/tests/Unit/Repository/UserSourceRepositoryTest.php +++ b/application/tests/Unit/Repository/UserSourceRepositoryTest.php @@ -1,4 +1,5 @@