From b183af90e6ed9fe1415b19a5eb1b5b70cfc34df8 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Mon, 26 Nov 2018 21:55:54 +0100 Subject: [PATCH] Solved tests for SourceMemberManager --- .../SourceManagement/SourceMemberManager.php | 28 ++++++++----------- .../SourceMemberManagerTest.php | 16 +++++------ 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/application/src/Domain/SourceManagement/SourceMemberManager.php b/application/src/Domain/SourceManagement/SourceMemberManager.php index 36dcd63..55981e0 100644 --- a/application/src/Domain/SourceManagement/SourceMemberManager.php +++ b/application/src/Domain/SourceManagement/SourceMemberManager.php @@ -3,6 +3,8 @@ namespace App\Domain\SourceManagement; use App\Entity\Source\SourceInterface; +use App\Domain\MemberManagement\MemberManagerInterface; +use App\Domain\MemberManagement\MemberManager; final class SourceMemberManager implements SourceMemberManagerInterface { @@ -11,40 +13,34 @@ final class SourceMemberManager implements SourceMemberManagerInterface */ private $source; + /** + * @var MemberManagerInterface + */ + private $memberManager; + public function __construct(SourceInterface $source) { $this->source = $source; + $this->memberManager = new MemberManager($this->source->getMemberRelation()); } public function addMember(SourceInterface $member): void { - if (!$this->source->getMembers()->contains($member)) { - $this->source->getMembers()[] = $member; - (new self($member))->addMembership($this->source); - } + $this->memberManager->addMember($member->getMemberRelation()); } public function removeMember(SourceInterface $member): void { - if ($this->source->getMembers()->contains($member)) { - $this->source->getMembers()->removeElement($member); - (new self($member))->removeMembership($this->source); - } + $this->memberManager->removeMember($member->getMemberRelation()); } public function addMembership(SourceInterface $membership): void { - if (!$this->source->getMemberships()->contains($membership)) { - $this->source->getMemberships()[] = $membership; - (new self($membership))->addMember($this->source); - } + $this->memberManager->addMembership($membership->getMemberRelation()); } public function removeMembership(SourceInterface $membership): void { - if ($this->source->getMemberships()->contains($membership)) { - $this->source->getMemberships()->removeElement($membership); - (new self($membership))->removeMember($this->source); - } + $this->memberManager->removeMembership($membership->getMemberRelation()); } } diff --git a/application/tests/Unit/Domain/SourceManagement/SourceMemberManagerTest.php b/application/tests/Unit/Domain/SourceManagement/SourceMemberManagerTest.php index 7036b96..00e5705 100644 --- a/application/tests/Unit/Domain/SourceManagement/SourceMemberManagerTest.php +++ b/application/tests/Unit/Domain/SourceManagement/SourceMemberManagerTest.php @@ -36,21 +36,21 @@ class SourceMemberManagerTest extends TestCase { $member = $this->createSource(); $this->assertNull($this->sourceMemberManager->addMember($member)); - $this->assertEquals($member, $this->source->getMembers()->get(0)); - $this->assertEquals($this->source, $member->getMemberships()->get(0)); + $this->assertEquals($member, $this->source->getMemberRelation()->getMembers()->get(0)->getSource()); + $this->assertEquals($this->source, $member->getMemberRelation()->getMemberships()->get(0)->getSource()); $this->assertNull($this->sourceMemberManager->removeMember($member)); - $this->assertEquals(0, $this->source->getMembers()->count()); - $this->assertEquals(0, $member->getMemberships()->count()); + $this->assertEquals(0, $this->source->getMemberRelation()->getMembers()->count()); + $this->assertEquals(0, $member->getMemberRelation()->getMemberships()->count()); } public function testAddAndRemoveMembership(): void { $membership = $this->createSource(); $this->assertNull($this->sourceMemberManager->addMembership($membership)); - $this->assertEquals($membership, $this->source->getMemberships()->get(0)); - $this->assertEquals($this->source, $membership->getMembers()->get(0)); + $this->assertEquals($membership, $this->source->getMemberRelation()->getMemberships()->get(0)->getSource()); + $this->assertEquals($this->source, $membership->getMemberRelation()->getMembers()->get(0)->getSource()); $this->assertNull($this->sourceMemberManager->removeMembership($membership)); - $this->assertEquals(0, $this->source->getMemberships()->count()); - $this->assertEquals(0, $membership->getMembers()->count()); + $this->assertEquals(0, $this->source->getMemberRelation()->getMemberships()->count()); + $this->assertEquals(0, $membership->getMemberRelation()->getMembers()->count()); } }