2018-11-25 21:27:25 +01:00
|
|
|
<?php
|
|
|
|
|
2019-05-30 17:04:46 +02:00
|
|
|
namespace Tests\Unit\Domain\Source;
|
2018-11-25 21:27:25 +01:00
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2019-02-17 14:33:19 +01:00
|
|
|
use Infinito\Entity\Source\SourceInterface;
|
2019-05-30 17:04:46 +02:00
|
|
|
use Infinito\Domain\Source\SourceMemberManagerInterface;
|
|
|
|
use Infinito\Domain\Source\SourceMemberManager;
|
2019-02-17 14:33:19 +01:00
|
|
|
use Infinito\Entity\Source\PureSource;
|
2018-11-25 21:27:25 +01:00
|
|
|
|
|
|
|
class SourceMemberManagerTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var SourceInterface
|
|
|
|
*/
|
|
|
|
private $source;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var SourceMemberManagerInterface
|
|
|
|
*/
|
|
|
|
private $sourceMemberManager;
|
|
|
|
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
2019-01-04 22:09:05 +01:00
|
|
|
$this->source = new PureSource();
|
2018-11-25 21:27:25 +01:00
|
|
|
$this->sourceMemberManager = new SourceMemberManager($this->source);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddAndRemoveMember(): void
|
|
|
|
{
|
2019-01-04 22:09:05 +01:00
|
|
|
$member = new PureSource();
|
2018-11-25 21:27:25 +01:00
|
|
|
$this->assertNull($this->sourceMemberManager->addMember($member));
|
2018-11-26 21:55:54 +01:00
|
|
|
$this->assertEquals($member, $this->source->getMemberRelation()->getMembers()->get(0)->getSource());
|
|
|
|
$this->assertEquals($this->source, $member->getMemberRelation()->getMemberships()->get(0)->getSource());
|
2018-11-25 21:27:25 +01:00
|
|
|
$this->assertNull($this->sourceMemberManager->removeMember($member));
|
2018-11-26 21:55:54 +01:00
|
|
|
$this->assertEquals(0, $this->source->getMemberRelation()->getMembers()->count());
|
|
|
|
$this->assertEquals(0, $member->getMemberRelation()->getMemberships()->count());
|
2018-11-25 21:27:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddAndRemoveMembership(): void
|
|
|
|
{
|
2019-01-04 22:09:05 +01:00
|
|
|
$membership = new PureSource();
|
2018-11-25 21:27:25 +01:00
|
|
|
$this->assertNull($this->sourceMemberManager->addMembership($membership));
|
2018-11-26 21:55:54 +01:00
|
|
|
$this->assertEquals($membership, $this->source->getMemberRelation()->getMemberships()->get(0)->getSource());
|
|
|
|
$this->assertEquals($this->source, $membership->getMemberRelation()->getMembers()->get(0)->getSource());
|
2018-11-25 21:27:25 +01:00
|
|
|
$this->assertNull($this->sourceMemberManager->removeMembership($membership));
|
2018-11-26 21:55:54 +01:00
|
|
|
$this->assertEquals(0, $this->source->getMemberRelation()->getMemberships()->count());
|
|
|
|
$this->assertEquals(0, $membership->getMemberRelation()->getMembers()->count());
|
2018-11-25 21:27:25 +01:00
|
|
|
}
|
|
|
|
}
|