mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 14:07:25 +01:00
Optimized SourceMemberInformation
This commit is contained in:
parent
713ddae0df
commit
3a6ed4d54d
@ -5,9 +5,7 @@ namespace App\Domain\SourceManagement;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use App\Entity\Attribut\MemberRelationAttributInterface;
|
||||
use App\Entity\Meta\Relation\Member\MemberRelationInterface;
|
||||
use App\Entity\EntityInterface;
|
||||
|
||||
final class SourceMemberInformation implements SourceMemberInformationInterface
|
||||
{
|
||||
@ -27,52 +25,19 @@ final class SourceMemberInformation implements SourceMemberInformationInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection|MemberRelationAttributInterface[] $members
|
||||
* @param Collection|MemberRelationInterface[] $members
|
||||
*/
|
||||
private function itterateOverMembers(Collection $members): void
|
||||
{
|
||||
foreach ($members as $member) {
|
||||
if (!$this->members->contains($member)) {
|
||||
$this->addMemberSource($member);
|
||||
$this->itterateOverMembers($this->getMemberMembers($member));
|
||||
if (!$this->members->contains($member->getSource())) {
|
||||
$this->members->add($member->getSource());
|
||||
$memberMembers = $member->getMembers();
|
||||
$this->itterateOverMembers($memberMembers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement tests!
|
||||
*
|
||||
* @deprecated The input data should be correct!
|
||||
*
|
||||
* @param EntityInterface $member
|
||||
*/
|
||||
private function addMemberSource(EntityInterface $member): void
|
||||
{
|
||||
if ($member instanceof MemberRelationInterface) {
|
||||
$this->members->add($member->getSource());
|
||||
} else {
|
||||
$this->members->add($member);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement tests
|
||||
*
|
||||
* @deprecated The input data should be correct!
|
||||
*
|
||||
* @param EntityInterface $member
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
private function getMemberMembers(EntityInterface $member): Collection
|
||||
{
|
||||
if ($member instanceof MemberRelationInterface) {
|
||||
return $member->getMembers();
|
||||
}
|
||||
|
||||
return $member->getMemberRelation()->getMembers();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
|
@ -75,7 +75,7 @@ class RightCheckerTest extends TestCase
|
||||
public function testSecondDimension(): void
|
||||
{
|
||||
$secondSource = $this->getSourceMock();
|
||||
$this->source->getMemberRelation()->getMembers()->add($secondSource);
|
||||
$this->source->getMemberRelation()->getMembers()->add($secondSource->getMemberRelation());
|
||||
$granted = $this->rightManager->isGranted($this->layer, $this->type, $secondSource);
|
||||
$this->assertTrue($granted);
|
||||
$notGranted = $this->rightManager->isGranted(LayerType::SOURCE, $this->type, $secondSource);
|
||||
@ -91,8 +91,8 @@ class RightCheckerTest extends TestCase
|
||||
{
|
||||
$thirdSource = $this->getSourceMock();
|
||||
$secondSource = $this->getSourceMock();
|
||||
$secondSource->getMemberRelation()->getMembers()->add($thirdSource);
|
||||
$this->source->getMemberRelation()->getMembers()->add($secondSource);
|
||||
$secondSource->getMemberRelation()->getMembers()->add($thirdSource->getMemberRelation());
|
||||
$this->source->getMemberRelation()->getMembers()->add($secondSource->getMemberRelation());
|
||||
$granted = $this->rightManager->isGranted($this->layer, $this->type, $thirdSource);
|
||||
$this->assertTrue($granted);
|
||||
$notGranted = $this->rightManager->isGranted(LayerType::SOURCE, $this->type, $thirdSource);
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ use App\Entity\Source\SourceInterface;
|
||||
use App\Domain\SourceManagement\SourceMemberManagerInterface;
|
||||
use App\Entity\Source\AbstractSource;
|
||||
use App\Domain\SourceManagement\SourceMemberManager;
|
||||
use App\Domain\SourceManagement\SourceMemberInformation;
|
||||
|
||||
class SourceMemberManagerTest extends TestCase
|
||||
{
|
||||
@ -53,4 +54,17 @@ class SourceMemberManagerTest extends TestCase
|
||||
$this->assertEquals(0, $this->source->getMemberRelation()->getMemberships()->count());
|
||||
$this->assertEquals(0, $membership->getMemberRelation()->getMembers()->count());
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Move this function to an own integration test class
|
||||
*/
|
||||
public function testSourceMemberInformationIntegration(): void
|
||||
{
|
||||
$childSource = $this->createSource();
|
||||
$sourceMemberInformation = new SourceMemberInformation($this->source);
|
||||
$this->sourceMemberManager->addMember($childSource);
|
||||
$this->assertEquals($childSource, $sourceMemberInformation->getAllMembers()->get(0));
|
||||
$this->sourceMemberManager->removeMember($childSource);
|
||||
$this->assertEquals(0, $sourceMemberInformation->getAllMembers()->count());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user