infinito/application/symfony/tests/Unit/Domain/Source/SourceMemberInformationTest.php

76 lines
2.8 KiB
PHP
Raw Normal View History

2018-12-06 20:22:27 +01:00
<?php
namespace Tests\Unit\Domain\Source;
2018-12-06 20:22:27 +01:00
use Doctrine\Common\Collections\ArrayCollection;
use Infinito\Domain\Source\SourceMemberInformation;
use Infinito\Domain\Source\SourceMemberInformationInterface;
2020-04-02 21:13:35 +02:00
use Infinito\Entity\Source\Complex\FullPersonNameSource;
use Infinito\Entity\Source\Complex\UserSource;
use Infinito\Entity\Source\Primitive\Name\FirstNameSource;
use Infinito\Entity\Source\Primitive\Text\TextSource;
use Infinito\Entity\Source\PureSource;
2020-04-02 21:13:35 +02:00
use Infinito\Entity\Source\SourceInterface;
use PHPUnit\Framework\TestCase;
2018-12-06 20:22:27 +01:00
class SourceMemberInformationTest extends TestCase
{
/**
* @var SourceInterface
*/
2018-12-30 16:12:46 +01:00
private $source;
2018-12-06 20:22:27 +01:00
/**
* @var SourceMemberInformationInterface
*/
2018-12-30 16:12:46 +01:00
private $sourceMemberInformation;
2018-12-06 20:22:27 +01:00
public function setUp(): void
{
$this->source = new UserSource();
$this->sourceMemberInformation = new SourceMemberInformation($this->source);
}
public function testOneDimension(): void
{
2018-12-30 16:12:46 +01:00
$this->source->getMemberRelation()->getMembers()->add((new TextSource())->getMemberRelation());
2018-12-29 23:02:34 +01:00
$allSourceMembers = $this->sourceMemberInformation->getAllMembers();
$this->assertEquals(1, $allSourceMembers->count());
$this->assertInstanceOf(SourceInterface::class, $allSourceMembers[0]);
2018-12-06 20:22:27 +01:00
}
public function testThreeDimension(): void
{
$source1 = new TextSource();
$source2 = new FirstNameSource();
2018-12-30 16:12:46 +01:00
$source2->getMemberRelation()->setMembers(new ArrayCollection([$source1->getMemberRelation()]));
2018-12-06 20:22:27 +01:00
$source3 = new FullPersonNameSource();
2018-12-30 16:12:46 +01:00
$source3->getMemberRelation()->getMembers()->add($source2->getMemberRelation());
$this->source->getMemberRelation()->getMembers()->add($source3->getMemberRelation());
2018-12-29 23:02:34 +01:00
$allSourceMembers = $this->sourceMemberInformation->getAllMembers();
$this->assertEquals(3, $allSourceMembers->count());
foreach ($allSourceMembers as $sourceMember) {
$this->assertInstanceOf(SourceInterface::class, $sourceMember);
}
2018-12-06 20:22:27 +01:00
}
public function testRecursion(): void
{
$recursiveSource = new UserSource();
2018-12-30 16:12:46 +01:00
$recursiveSource->getMemberRelation()->getMembers()->add($this->source->getMemberRelation());
$this->source->getMemberRelation()->getMembers()->add($recursiveSource->getMemberRelation());
2018-12-29 23:02:34 +01:00
$allSourceMembers = $this->sourceMemberInformation->getAllMembers();
$this->assertEquals(2, $allSourceMembers->count());
foreach ($allSourceMembers as $sourceMember) {
$this->assertInstanceOf(SourceInterface::class, $sourceMember);
}
2018-12-06 20:22:27 +01:00
}
2018-12-30 16:12:46 +01:00
public function testError(): void
{
$this->expectException(\Error::class);
$this->source->getMemberRelation()->getMembers()->add(new PureSource());
2018-12-30 16:12:46 +01:00
$this->sourceMemberInformation->getAllMembers();
}
2018-12-06 20:22:27 +01:00
}