2018-11-24 16:42:51 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Unit\Domain\SourceManagement;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2019-02-17 14:33:19 +01:00
|
|
|
use Infinito\Domain\SourceManagement\SourceMembershipInformationInterface;
|
|
|
|
use Infinito\Domain\SourceManagement\SourceMembershipInformation;
|
|
|
|
use Infinito\Entity\Source\SourceInterface;
|
|
|
|
use Infinito\Entity\Source\Complex\UserSource;
|
|
|
|
use Infinito\Entity\Source\Primitive\Text\TextSource;
|
|
|
|
use Infinito\Entity\Source\Primitive\Name\FirstNameSource;
|
2018-11-24 16:42:51 +01:00
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
2019-02-17 14:33:19 +01:00
|
|
|
use Infinito\Entity\Source\Complex\FullPersonNameSource;
|
2018-11-24 16:42:51 +01:00
|
|
|
|
|
|
|
class SourceMembershipInformationTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var SourceInterface
|
|
|
|
*/
|
|
|
|
protected $source;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var SourceMembershipInformationInterface
|
|
|
|
*/
|
|
|
|
protected $sourceMembershipInformation;
|
|
|
|
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
$this->source = new UserSource();
|
|
|
|
$this->sourceMembershipInformation = new SourceMembershipInformation($this->source);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testOneDimension(): void
|
|
|
|
{
|
2018-12-30 17:09:44 +01:00
|
|
|
$this->source->getMemberRelation()->getMemberships()->add((new TextSource())->getMemberRelation());
|
2018-11-24 16:42:51 +01:00
|
|
|
$this->assertEquals(1, $this->sourceMembershipInformation->getAllMemberships()->count());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testThreeDimension(): void
|
|
|
|
{
|
|
|
|
$source1 = new TextSource();
|
|
|
|
$source2 = new FirstNameSource();
|
2018-12-30 17:09:44 +01:00
|
|
|
$source2->getMemberRelation()->setMemberships(new ArrayCollection([$source1->getMemberRelation()]));
|
2018-11-24 16:42:51 +01:00
|
|
|
$source3 = new FullPersonNameSource();
|
2018-12-30 17:09:44 +01:00
|
|
|
$source3->getMemberRelation()->getMemberships()->add($source2->getMemberRelation());
|
|
|
|
$this->source->getMemberRelation()->getMemberships()->add($source3->getMemberRelation());
|
2018-11-24 16:42:51 +01:00
|
|
|
$this->assertEquals(3, $this->sourceMembershipInformation->getAllMemberships()->count());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRecursion(): void
|
|
|
|
{
|
|
|
|
$recursiveSource = new UserSource();
|
2018-12-30 17:09:44 +01:00
|
|
|
$recursiveSource->getMemberRelation()->getMemberships()->add($this->source->getMemberRelation());
|
|
|
|
$this->source->getMemberRelation()->getMemberships()->add($recursiveSource->getMemberRelation());
|
2018-11-24 16:42:51 +01:00
|
|
|
$this->assertEquals(2, $this->sourceMembershipInformation->getAllMemberships()->count());
|
|
|
|
}
|
2018-12-30 17:09:44 +01:00
|
|
|
|
|
|
|
public function testError(): void
|
|
|
|
{
|
|
|
|
$this->expectException(\Error::class);
|
|
|
|
$this->source->getMemberRelation()->getMemberships()->add($this->createSourceMock());
|
|
|
|
$this->sourceMembershipInformation->getAllMemberships();
|
|
|
|
}
|
2018-11-24 16:42:51 +01:00
|
|
|
}
|