mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 14:07:25 +01:00
Solved tests for SourceMemberManager
This commit is contained in:
parent
b23f507da8
commit
b183af90e6
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user