2018-10-31 18:10:54 +01:00
|
|
|
<?php
|
|
|
|
|
2018-10-31 19:15:07 +01:00
|
|
|
namespace App\Tests\Unit\Entity\Attribut;
|
2018-10-31 18:10:54 +01:00
|
|
|
|
|
|
|
use App\Entity\Attribut\MembersAttribut;
|
|
|
|
use App\Entity\Attribut\MembersAttributInterface;
|
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
|
use App\Entity\Source\AbstractSource;
|
|
|
|
use App\Entity\Source\GroupSource;
|
2018-10-31 19:15:07 +01:00
|
|
|
use App\Tests\AbstractTestCase;
|
2018-10-31 18:10:54 +01:00
|
|
|
|
2018-10-31 19:15:07 +01:00
|
|
|
class MembersAttributTest extends AbstractTestCase
|
2018-10-31 18:10:54 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var MembersAttributInterface
|
|
|
|
*/
|
|
|
|
protected $membersAttribut;
|
|
|
|
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
$this->membersAttribut = new class() implements MembersAttributInterface {
|
|
|
|
use MembersAttribut;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-10-31 19:15:07 +01:00
|
|
|
public function testConstructor(): void
|
|
|
|
{
|
2018-10-31 18:10:54 +01:00
|
|
|
$this->expectException(\TypeError::class);
|
|
|
|
$this->membersAttribut->getMembers();
|
|
|
|
$this->membersAttribut->getMembersInclusiveChildren();
|
|
|
|
}
|
2018-10-31 20:39:41 +01:00
|
|
|
|
|
|
|
private function getContinueIncludeMemberLoopResult($dimension): bool
|
|
|
|
{
|
2018-10-31 19:31:55 +01:00
|
|
|
return $this->invokeMethod($this->membersAttribut, 'continueIncludeMembersLoop', [$dimension]);
|
|
|
|
}
|
2018-10-31 20:39:41 +01:00
|
|
|
|
|
|
|
public function testContinueIncludeMemberLoop()
|
|
|
|
{
|
2018-10-31 19:31:55 +01:00
|
|
|
$this->assertTrue($this->getContinueIncludeMemberLoopResult(null));
|
|
|
|
$this->assertTrue($this->getContinueIncludeMemberLoopResult(2));
|
2018-10-31 20:27:36 +01:00
|
|
|
$this->assertTrue($this->getContinueIncludeMemberLoopResult(1));
|
2018-10-31 19:31:55 +01:00
|
|
|
$this->assertFalse($this->getContinueIncludeMemberLoopResult(0));
|
|
|
|
$this->assertFalse($this->getContinueIncludeMemberLoopResult(-1));
|
2018-10-31 19:15:07 +01:00
|
|
|
}
|
|
|
|
|
2018-10-31 18:10:54 +01:00
|
|
|
public function testMembersAccessors()
|
|
|
|
{
|
|
|
|
$source1 = new class() extends AbstractSource {
|
|
|
|
};
|
|
|
|
$source2 = clone $source1;
|
|
|
|
$source3 = clone $source1;
|
|
|
|
$members = new ArrayCollection([
|
|
|
|
$source1,
|
|
|
|
$source2,
|
|
|
|
$source3,
|
|
|
|
]);
|
|
|
|
$this->assertNull($this->membersAttribut->setMembers($members));
|
|
|
|
$this->assertEquals($members, $this->membersAttribut->getMembers());
|
2018-10-31 20:27:36 +01:00
|
|
|
$this->assertTrue($this->membersAttribut->getMembers()->contains($source1));
|
|
|
|
}
|
2018-10-31 20:39:41 +01:00
|
|
|
|
|
|
|
public function testFirstLevelMembersInclusiveChildren(): void
|
|
|
|
{
|
2018-10-31 20:27:36 +01:00
|
|
|
$source1 = new GroupSource();
|
|
|
|
$source2 = clone $source1;
|
|
|
|
$source3 = clone $source1;
|
|
|
|
$source4 = clone $source1;
|
|
|
|
$source3->setMembers(new ArrayCollection([$source4]));
|
2018-10-31 20:39:41 +01:00
|
|
|
$members = new ArrayCollection([$source1, $source2, $source3]);
|
2018-10-31 20:27:36 +01:00
|
|
|
$this->assertNull($this->membersAttribut->setMembers($members));
|
2018-10-31 20:39:41 +01:00
|
|
|
$this->assertEquals(3, $this->membersAttribut->getMembersInclusiveChildren(1)->count());
|
2018-10-31 20:27:36 +01:00
|
|
|
}
|
2018-10-31 20:39:41 +01:00
|
|
|
|
|
|
|
public function test3DimensionsMembersInclusiveChildren(): void
|
|
|
|
{
|
|
|
|
$source1 = new GroupSource();
|
2018-10-31 20:27:36 +01:00
|
|
|
$source2 = clone $source1;
|
|
|
|
$source3 = clone $source1;
|
|
|
|
$source4 = clone $source1;
|
|
|
|
$source1->setMembers(new ArrayCollection([$source2]));
|
|
|
|
$source2->setMembers(new ArrayCollection([$source3]));
|
|
|
|
$source3->setMembers(new ArrayCollection([$source4]));
|
|
|
|
$this->membersAttribut->setMembers(new ArrayCollection([$source1]));
|
2018-10-31 20:39:41 +01:00
|
|
|
$this->assertEquals(1, $this->membersAttribut->getMembers()->count());
|
|
|
|
$this->assertEquals(1, $source1->getMembers()->count());
|
|
|
|
$this->assertEquals(1, $source2->getMembers()->count());
|
|
|
|
$this->assertEquals(1, $source3->getMembers()->count());
|
|
|
|
$this->assertEquals(0, $source4->getMembers()->count());
|
|
|
|
$this->assertEquals(3, $this->membersAttribut->getMembersInclusiveChildren(3)->count());
|
2018-10-31 18:10:54 +01:00
|
|
|
}
|
2018-10-31 19:15:07 +01:00
|
|
|
|
2018-10-31 20:39:41 +01:00
|
|
|
public function testMembersIncludingChildrenInfinite(): void
|
2018-10-31 18:10:54 +01:00
|
|
|
{
|
|
|
|
$source1 = new GroupSource();
|
|
|
|
$source2 = clone $source1;
|
|
|
|
$source3 = clone $source1;
|
|
|
|
$source4 = clone $source1;
|
|
|
|
$source5 = clone $source1;
|
2018-10-31 19:15:07 +01:00
|
|
|
$source6 = clone $source1;
|
2018-10-31 18:10:54 +01:00
|
|
|
$source1->setMembers(new ArrayCollection([$source2]));
|
2018-10-31 20:39:41 +01:00
|
|
|
$source2->setMembers(new ArrayCollection([$source1, $source3]));
|
2018-10-31 18:10:54 +01:00
|
|
|
$source3->setMembers(new ArrayCollection([$source4]));
|
|
|
|
$source4->setMembers(new ArrayCollection([$source5]));
|
|
|
|
$source5->setMembers(new ArrayCollection([$source6]));
|
|
|
|
|
2018-10-31 20:39:41 +01:00
|
|
|
$this->membersAttribut->setMembers(new ArrayCollection([$source1]));
|
|
|
|
$this->assertEquals(6, $this->membersAttribut->getMembersInclusiveChildren()->count());
|
|
|
|
}
|
2018-10-31 18:10:54 +01:00
|
|
|
|
2018-10-31 20:39:41 +01:00
|
|
|
public function testMemberWithoutMembers(): void
|
|
|
|
{
|
|
|
|
$source1 = new class() extends AbstractSource {
|
|
|
|
};
|
|
|
|
$this->membersAttribut->setMembers(new ArrayCollection([$source1]));
|
|
|
|
$this->assertEquals(1, $this->membersAttribut->getMembersInclusiveChildren()->count());
|
2018-10-31 18:10:54 +01:00
|
|
|
}
|
|
|
|
}
|