Optimized SourceMemberInformation

This commit is contained in:
Kevin Frantz
2018-12-30 16:12:46 +01:00
parent 713ddae0df
commit 3a6ed4d54d
4 changed files with 44 additions and 51 deletions

View File

@@ -11,18 +11,25 @@ use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Source\Complex\FullPersonNameSource;
use App\Domain\SourceManagement\SourceMemberInformation;
use App\Domain\SourceManagement\SourceMemberInformationInterface;
use App\Entity\Source\AbstractSource;
class SourceMemberInformationTest extends TestCase
{
/**
* @var SourceInterface
*/
protected $source;
private $source;
/**
* @var SourceMemberInformationInterface
*/
protected $sourceMemberInformation;
private $sourceMemberInformation;
private function createSourceMock(): SourceInterface
{
return new class() extends AbstractSource {
};
}
public function setUp(): void
{
@@ -32,7 +39,7 @@ class SourceMemberInformationTest extends TestCase
public function testOneDimension(): void
{
$this->source->getMemberRelation()->getMembers()->add(new TextSource());
$this->source->getMemberRelation()->getMembers()->add((new TextSource())->getMemberRelation());
$allSourceMembers = $this->sourceMemberInformation->getAllMembers();
$this->assertEquals(1, $allSourceMembers->count());
$this->assertInstanceOf(SourceInterface::class, $allSourceMembers[0]);
@@ -42,10 +49,10 @@ class SourceMemberInformationTest extends TestCase
{
$source1 = new TextSource();
$source2 = new FirstNameSource();
$source2->getMemberRelation()->setMembers(new ArrayCollection([$source1]));
$source2->getMemberRelation()->setMembers(new ArrayCollection([$source1->getMemberRelation()]));
$source3 = new FullPersonNameSource();
$source3->getMemberRelation()->getMembers()->add($source2);
$this->source->getMemberRelation()->getMembers()->add($source3);
$source3->getMemberRelation()->getMembers()->add($source2->getMemberRelation());
$this->source->getMemberRelation()->getMembers()->add($source3->getMemberRelation());
$allSourceMembers = $this->sourceMemberInformation->getAllMembers();
$this->assertEquals(3, $allSourceMembers->count());
foreach ($allSourceMembers as $sourceMember) {
@@ -56,12 +63,19 @@ class SourceMemberInformationTest extends TestCase
public function testRecursion(): void
{
$recursiveSource = new UserSource();
$recursiveSource->getMemberRelation()->getMembers()->add($this->source);
$this->source->getMemberRelation()->getMembers()->add($recursiveSource);
$recursiveSource->getMemberRelation()->getMembers()->add($this->source->getMemberRelation());
$this->source->getMemberRelation()->getMembers()->add($recursiveSource->getMemberRelation());
$allSourceMembers = $this->sourceMemberInformation->getAllMembers();
$this->assertEquals(2, $allSourceMembers->count());
foreach ($allSourceMembers as $sourceMember) {
$this->assertInstanceOf(SourceInterface::class, $sourceMember);
}
}
public function testError(): void
{
$this->expectException(\Error::class);
$this->source->getMemberRelation()->getMembers()->add($this->createSourceMock());
$this->sourceMemberInformation->getAllMembers();
}
}