mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 22:17:26 +01:00
Refactored Collection Sources
This commit is contained in:
parent
7cb6238f92
commit
5f18245b73
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Source\Attribut;
|
||||
namespace App\Entity\Attribut;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use App\Entity\Source\GroupSourceInterface;
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Source\Attribut;
|
||||
namespace App\Entity\Attribut;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use App\Entity\Source\GroupSourceInterface;
|
23
application/src/Entity/Attribut/SourceCollectionAttribut.php
Normal file
23
application/src/Entity/Attribut/SourceCollectionAttribut.php
Normal 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{
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
@ -6,7 +6,7 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
use JMS\Serializer\Annotation\Exclude;
|
||||
use App\Entity\AbstractEntity;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use App\Entity\Source\Attribut\GroupSourcesAttribut;
|
||||
use App\Entity\Attribut\GroupSourcesAttribut;
|
||||
use App\Entity\Meta\RelationInterface;
|
||||
use App\Entity\Attribut\RelationAttribut;
|
||||
use App\Entity\Meta\Relation;
|
||||
@ -14,6 +14,7 @@ use App\Entity\Attribut\LawAttribut;
|
||||
use App\Entity\Meta\LawInterface;
|
||||
use App\Entity\Meta\Law;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use App\Entity\Source\Collection\MemberCollectionSource;
|
||||
|
||||
/**
|
||||
* @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 Rename table to use the right schema
|
||||
*
|
||||
* @var Collection|GroupSource[]
|
||||
* @var Collection|MemberCollectionSource[]
|
||||
* @ORM\ManyToMany(targetEntity="GroupSource",mappedBy="members")
|
||||
*/
|
||||
protected $groups;
|
||||
|
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace App\Entity\Source\Collection;
|
||||
|
||||
use App\Entity\Source\AbstractSource;
|
||||
|
||||
class AbstractCollectionSource extends AbstractSource implements CollectionSourceInterface
|
||||
{
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace App\Entity\Source\Collection;
|
||||
|
||||
use App\Entity\Source\SourceInterface;
|
||||
|
||||
interface CollectionSourceInterface extends SourceInterface
|
||||
{}
|
||||
|
@ -1,19 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Source;
|
||||
namespace App\Entity\Source\Collection;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use App\Entity\Attribut\MembersAttributInterface;
|
||||
use App\Entity\Attribut\MembersAttribut;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
* @ORM\Table(name="source_group")
|
||||
* @ORM\Entity
|
||||
*/
|
||||
final class GroupSource extends AbstractSource implements MembersAttributInterface
|
||||
final class MemberCollectionSource extends AbstractCollectionSource implements MemberCollectionSourceInterface
|
||||
{
|
||||
use MembersAttribut;
|
||||
|
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Source\Collection;
|
||||
|
||||
use App\Entity\Attribut\MembersAttributInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface MemberCollectionSourceInterface extends MembersAttributInterface,CollectionSourceInterface
|
||||
{
|
||||
}
|
@ -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;
|
||||
}
|
@ -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
|
||||
{
|
||||
}
|
@ -4,7 +4,7 @@ namespace App\Entity\Source;
|
||||
|
||||
use App\Entity\Attribut\IdAttributInterface;
|
||||
use App\Entity\EntityInterface;
|
||||
use App\Entity\Source\Attribut\GroupSourcesAttributInterface;
|
||||
use App\Entity\Attribut\GroupSourcesAttributInterface;
|
||||
use App\Entity\Attribut\LawAttributInterface;
|
||||
use App\Entity\Attribut\RelationAttributInterface;
|
||||
|
||||
|
@ -6,7 +6,6 @@ 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;
|
||||
use App\Tests\AbstractTestCase;
|
||||
|
||||
class MembersAttributTest extends AbstractTestCase
|
||||
@ -18,7 +17,11 @@ class MembersAttributTest extends AbstractTestCase
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
@ -62,7 +65,7 @@ class MembersAttributTest extends AbstractTestCase
|
||||
|
||||
public function testFirstLevelMembersInclusiveChildren(): void
|
||||
{
|
||||
$source1 = new GroupSource();
|
||||
$source1 = $this->getMembersAttributClassMock();
|
||||
$source2 = clone $source1;
|
||||
$source3 = clone $source1;
|
||||
$source4 = clone $source1;
|
||||
@ -74,13 +77,14 @@ class MembersAttributTest extends AbstractTestCase
|
||||
|
||||
public function test3DimensionsMembersInclusiveChildren(): void
|
||||
{
|
||||
$source1 = new GroupSource();
|
||||
$source1 = $this->getMembersAttributClassMock();
|
||||
$source2 = clone $source1;
|
||||
$source3 = clone $source1;
|
||||
$source4 = clone $source1;
|
||||
$source1->setMembers(new ArrayCollection([$source2]));
|
||||
$source2->setMembers(new ArrayCollection([$source3]));
|
||||
$source3->setMembers(new ArrayCollection([$source4]));
|
||||
$source4->setMembers(new ArrayCollection());
|
||||
$this->membersAttribut->setMembers(new ArrayCollection([$source1]));
|
||||
$this->assertEquals(1, $this->membersAttribut->getMembers()->count());
|
||||
$this->assertEquals(1, $source1->getMembers()->count());
|
||||
@ -92,7 +96,8 @@ class MembersAttributTest extends AbstractTestCase
|
||||
|
||||
public function testMembersIncludingChildrenInfinite(): void
|
||||
{
|
||||
$source1 = new GroupSource();
|
||||
$source1 = $this->getMembersAttributClassMock();
|
||||
$source1->setMembers(new ArrayCollection());
|
||||
$source2 = clone $source1;
|
||||
$source3 = clone $source1;
|
||||
$source4 = clone $source1;
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
@ -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));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user