Refactored Collection Sources

This commit is contained in:
Kevin Frantz 2018-11-01 19:59:36 +01:00
parent 7cb6238f92
commit 5f18245b73
15 changed files with 148 additions and 63 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
namespace App\Entity\Source\Attribut; namespace App\Entity\Attribut;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use App\Entity\Source\GroupSourceInterface; use App\Entity\Source\GroupSourceInterface;

View File

@ -1,6 +1,6 @@
<?php <?php
namespace App\Entity\Source\Attribut; namespace App\Entity\Attribut;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use App\Entity\Source\GroupSourceInterface; use App\Entity\Source\GroupSourceInterface;

View File

@ -0,0 +1,23 @@
<?php
namespace App\Entity\Attribut;
use Doctrine\Common\Collections\Collection;
use App\Entity\Source\SourceInterface;
trait SourceCollectionAttribut
{
/**
* @param Collection|SourceInterface[] $collection
*/
public function setCollection(Collection $collection):void{
}
/**
* @return Collection|SourceInterface[]
*/
public function getCollection():Collection{
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace App\Entity\Attribut;
use Doctrine\Common\Collections\Collection;
use App\Entity\Source\SourceInterface;
interface SourceCollectionAttributInterface
{
/**
* @param Collection|SourceInterface[] $collection
*/
public function setCollection(Collection $collection):void;
/**
* @return Collection|SourceInterface[]
*/
public function getCollection():Collection;
}

View File

@ -6,7 +6,7 @@ use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\Exclude; use JMS\Serializer\Annotation\Exclude;
use App\Entity\AbstractEntity; use App\Entity\AbstractEntity;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use App\Entity\Source\Attribut\GroupSourcesAttribut; use App\Entity\Attribut\GroupSourcesAttribut;
use App\Entity\Meta\RelationInterface; use App\Entity\Meta\RelationInterface;
use App\Entity\Attribut\RelationAttribut; use App\Entity\Attribut\RelationAttribut;
use App\Entity\Meta\Relation; use App\Entity\Meta\Relation;
@ -14,6 +14,7 @@ use App\Entity\Attribut\LawAttribut;
use App\Entity\Meta\LawInterface; use App\Entity\Meta\LawInterface;
use App\Entity\Meta\Law; use App\Entity\Meta\Law;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Source\Collection\MemberCollectionSource;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -41,7 +42,7 @@ abstract class AbstractSource extends AbstractEntity implements SourceInterface
* @todo Implement that just one table on database level is needed! * @todo Implement that just one table on database level is needed!
* @todo Rename table to use the right schema * @todo Rename table to use the right schema
* *
* @var Collection|GroupSource[] * @var Collection|MemberCollectionSource[]
* @ORM\ManyToMany(targetEntity="GroupSource",mappedBy="members") * @ORM\ManyToMany(targetEntity="GroupSource",mappedBy="members")
*/ */
protected $groups; protected $groups;

View File

@ -0,0 +1,9 @@
<?php
namespace App\Entity\Source\Collection;
use App\Entity\Source\AbstractSource;
class AbstractCollectionSource extends AbstractSource implements CollectionSourceInterface
{
}

View File

@ -0,0 +1,8 @@
<?php
namespace App\Entity\Source\Collection;
use App\Entity\Source\SourceInterface;
interface CollectionSourceInterface extends SourceInterface
{}

View File

@ -1,19 +1,17 @@
<?php <?php
namespace App\Entity\Source; namespace App\Entity\Source\Collection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use App\Entity\Attribut\MembersAttributInterface;
use App\Entity\Attribut\MembersAttribut; use App\Entity\Attribut\MembersAttribut;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
/** /**
* @author kevinfrantz * @author kevinfrantz
* @ORM\Table(name="source_group") * @ORM\Table(name="source_group")
* @ORM\Entity * @ORM\Entity
*/ */
final class GroupSource extends AbstractSource implements MembersAttributInterface final class MemberCollectionSource extends AbstractCollectionSource implements MemberCollectionSourceInterface
{ {
use MembersAttribut; use MembersAttribut;

View File

@ -0,0 +1,12 @@
<?php
namespace App\Entity\Source\Collection;
use App\Entity\Attribut\MembersAttributInterface;
/**
* @author kevinfrantz
*/
interface MemberCollectionSourceInterface extends MembersAttributInterface,CollectionSourceInterface
{
}

View File

@ -0,0 +1,17 @@
<?php
namespace App\Entity\Source\Collection\Queue;
use App\Entity\Attribut\MembersAttributInterface;
use App\Entity\Source\Collection\CollectionSourceInterface;
use App\Entity\Source\SourceInterface;
/**
* @todo Implement integration test for two user accessing queue! Check if log works!
* @author kevinfrantz
*/
interface QueueSourceInterface extends CollectionSourceInterface, MembersAttributInterface
{
public function getPointerPosition():int;
public function getNextElement():SourceInterface;
}

View File

@ -1,14 +0,0 @@
<?php
namespace App\Entity\Source;
use App\Entity\Attribut\MembersAttributInterface;
/**
* @author kevinfrantz
*
* @todo Map the not jet mapped functions!
*/
interface GroupSourceInterface extends MembersAttributInterface
{
}

View File

@ -4,7 +4,7 @@ namespace App\Entity\Source;
use App\Entity\Attribut\IdAttributInterface; use App\Entity\Attribut\IdAttributInterface;
use App\Entity\EntityInterface; use App\Entity\EntityInterface;
use App\Entity\Source\Attribut\GroupSourcesAttributInterface; use App\Entity\Attribut\GroupSourcesAttributInterface;
use App\Entity\Attribut\LawAttributInterface; use App\Entity\Attribut\LawAttributInterface;
use App\Entity\Attribut\RelationAttributInterface; use App\Entity\Attribut\RelationAttributInterface;

View File

@ -6,7 +6,6 @@ use App\Entity\Attribut\MembersAttribut;
use App\Entity\Attribut\MembersAttributInterface; use App\Entity\Attribut\MembersAttributInterface;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Source\AbstractSource; use App\Entity\Source\AbstractSource;
use App\Entity\Source\GroupSource;
use App\Tests\AbstractTestCase; use App\Tests\AbstractTestCase;
class MembersAttributTest extends AbstractTestCase class MembersAttributTest extends AbstractTestCase
@ -18,7 +17,11 @@ class MembersAttributTest extends AbstractTestCase
public function setUp(): void public function setUp(): void
{ {
$this->membersAttribut = new class() implements MembersAttributInterface { $this->membersAttribut = $this->getMembersAttributClassMock();
}
private function getMembersAttributClassMock():MembersAttributInterface{
return new class implements MembersAttributInterface{
use MembersAttribut; use MembersAttribut;
}; };
} }
@ -62,7 +65,7 @@ class MembersAttributTest extends AbstractTestCase
public function testFirstLevelMembersInclusiveChildren(): void public function testFirstLevelMembersInclusiveChildren(): void
{ {
$source1 = new GroupSource(); $source1 = $this->getMembersAttributClassMock();
$source2 = clone $source1; $source2 = clone $source1;
$source3 = clone $source1; $source3 = clone $source1;
$source4 = clone $source1; $source4 = clone $source1;
@ -74,13 +77,14 @@ class MembersAttributTest extends AbstractTestCase
public function test3DimensionsMembersInclusiveChildren(): void public function test3DimensionsMembersInclusiveChildren(): void
{ {
$source1 = new GroupSource(); $source1 = $this->getMembersAttributClassMock();
$source2 = clone $source1; $source2 = clone $source1;
$source3 = clone $source1; $source3 = clone $source1;
$source4 = clone $source1; $source4 = clone $source1;
$source1->setMembers(new ArrayCollection([$source2])); $source1->setMembers(new ArrayCollection([$source2]));
$source2->setMembers(new ArrayCollection([$source3])); $source2->setMembers(new ArrayCollection([$source3]));
$source3->setMembers(new ArrayCollection([$source4])); $source3->setMembers(new ArrayCollection([$source4]));
$source4->setMembers(new ArrayCollection());
$this->membersAttribut->setMembers(new ArrayCollection([$source1])); $this->membersAttribut->setMembers(new ArrayCollection([$source1]));
$this->assertEquals(1, $this->membersAttribut->getMembers()->count()); $this->assertEquals(1, $this->membersAttribut->getMembers()->count());
$this->assertEquals(1, $source1->getMembers()->count()); $this->assertEquals(1, $source1->getMembers()->count());
@ -92,7 +96,8 @@ class MembersAttributTest extends AbstractTestCase
public function testMembersIncludingChildrenInfinite(): void public function testMembersIncludingChildrenInfinite(): void
{ {
$source1 = new GroupSource(); $source1 = $this->getMembersAttributClassMock();
$source1->setMembers(new ArrayCollection());
$source2 = clone $source1; $source2 = clone $source1;
$source3 = clone $source1; $source3 = clone $source1;
$source4 = clone $source1; $source4 = clone $source1;

View File

@ -0,0 +1,43 @@
<?php
namespace Tests\Unit\Entity\Source\Collection;
use PHPUnit\Framework\TestCase;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Source\AbstractSource;
use App\Entity\Source\Collection\MemberCollectionSourceInterface;
use App\Entity\Source\Collection\MemberCollectionSource;
/**
*
* @author kevinfrantz
*/
class MemberCollectionSourceTest extends TestCase
{
/**
*
* @var MemberCollectionSourceInterface
*/
protected $groupSource;
public function setUp(): void
{
$this->groupSource = new MemberCollectionSource();
}
public function testConstructor(): void
{
$this->assertInstanceOf(Collection::class, $this->groupSource->getMembers());
}
public function testMembers()
{
$member = new class() extends AbstractSource {};
$this->groupSource->setMembers(new ArrayCollection([
$member
]));
$this->assertEquals($member, $this->groupSource->getMembers()
->get(0));
}
}

View File

@ -1,35 +0,0 @@
<?php
namespace tests\unit\Entity\Source;
use App\Entity\Source\GroupSourceInterface;
use App\Entity\Source\GroupSource;
use PHPUnit\Framework\TestCase;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Source\AbstractSource;
/**
* @author kevinfrantz
*/
class GroupSourceTest extends TestCase
{
/**
* @var GroupSourceInterface
*/
protected $groupSource;
public function setUp(): void
{
$this->groupSource = new GroupSource();
}
public function testMembers()
{
$this->assertInstanceOf(Collection::class, $this->groupSource->getMembers());
$member = new class() extends AbstractSource {
};
$this->groupSource->setMembers(new ArrayCollection([$member]));
$this->assertEquals($member, $this->groupSource->getMembers()->get(0));
}
}