infinito/application/tests/Unit/Domain/SourceManagement/SourceMemberManagerTest.php

51 lines
1.9 KiB
PHP
Raw Normal View History

2018-11-25 21:27:25 +01:00
<?php
namespace Tests\Unit\Domain\SourceManagement;
use PHPUnit\Framework\TestCase;
use App\Entity\Source\SourceInterface;
use App\Domain\SourceManagement\SourceMemberManagerInterface;
use App\Domain\SourceManagement\SourceMemberManager;
use App\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
{
$this->source = new PureSource();
2018-11-25 21:27:25 +01:00
$this->sourceMemberManager = new SourceMemberManager($this->source);
}
public function testAddAndRemoveMember(): void
{
$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
{
$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
}
}