Implemented TreeCollectionSource

This commit is contained in:
Kevin Frantz 2018-11-02 21:38:04 +01:00
parent e0edc8935d
commit a66e2c3b46
11 changed files with 111 additions and 77 deletions

View File

@ -8,6 +8,8 @@ use App\Helper\DimensionHelper;
/**
* @author kevinfrantz
*
* @deprecated use instead CollectionDimensionHelper Method
*
* @todo this attribut should be refactored to mapp fully on collections instead of members
*/
trait MembersAttribut
@ -31,6 +33,8 @@ trait MembersAttribut
* @param int $dimension The dimensions start with 1 for the members of the actuall dimension and NULL for all members
* @param Collection $members A reference to a members list, to which new members should be add
*
* @deprecated Use Instead CollectionDimensionHelperMethod
*
* @return Collection|MembersAttributInterface[] Returns all members till the defined dimension
*/
public function getMembersIncludingChildren(?int $dimension = null, Collection $members = null): Collection

View File

@ -0,0 +1,22 @@
<?php
namespace App\Entity\Method;
use Doctrine\Common\Collections\Collection;
use App\Helper\DimensionHelper;
use App\Entity\Attribut\MembersAttributInterface;
/**
* @todo Create test for trait!
*
* @author kevinfrantz
*/
trait CollectionDimensionHelperMethod
{
public function getDimensions(?int $dimension = null, Collection $elements = null): Collection
{
$dimensionHelper = new DimensionHelper(__FUNCTION__, MembersAttributInterface::class, $this, 'collection');
return $dimensionHelper->getDimensions($dimension, $elements);
}
}

View File

@ -13,8 +13,8 @@ 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;
use App\Entity\Attribut\MembershipsAttribut;
use App\Entity\Source\Collection\TreeCollectionSourceInterface;
/**
* @author kevinfrantz
@ -24,7 +24,7 @@ use App\Entity\Attribut\MembershipsAttribut;
* @ORM\Table(name="source")
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="discr", type="string")
* @ORM\DiscriminatorMap({"user" = "UserSource","name" = "NameSource","group" = "App\Entity\Source\Collection\MemberCollectionSource"})
* @ORM\DiscriminatorMap({"user" = "UserSource","name" = "NameSource","collection" = "App\Entity\Source\Collection\AbstractCollectionSource","operation"="App\Entity\Source\Operation\AbstractOperation"})
*/
abstract class AbstractSource extends AbstractEntity implements SourceInterface
{
@ -42,8 +42,8 @@ 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|MemberCollectionSource[]
* @ORM\ManyToMany(targetEntity="App\Entity\Source\Collection\MemberCollectionSource",mappedBy="collection")
* @var Collection|TreeCollectionSourceInterface[]
* @ORM\ManyToMany(targetEntity="App\Entity\Source\Collection\TreeCollectionSource",mappedBy="collection")
*/
protected $memberships;

View File

@ -14,7 +14,7 @@ use Doctrine\Common\Collections\ArrayCollection;
* @ORM\Table(name="source_collection")
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="discr", type="string")
* @ORM\DiscriminatorMap({"member" = "MemberCollectionSource"})
* @ORM\DiscriminatorMap({"member" = "TreeCollectionSource"})
*
* @author kevinfrantz
*/

View File

@ -1,16 +0,0 @@
<?php
namespace App\Entity\Source\Collection;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Attribut\MembersAttribut;
/**
* @author kevinfrantz
* @ORM\Table(name="source_group")
* @ORM\Entity
*/
final class MemberCollectionSource extends AbstractCollectionSource implements MemberCollectionSourceInterface
{
use MembersAttribut;
}

View File

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

View File

@ -0,0 +1,20 @@
<?php
namespace App\Entity\Source\Collection;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Attribut\MembersAttribut;
use App\Entity\Method\CollectionDimensionHelperMethod;
/**
* @author kevinfrantz
*
* @todo remove deprecated trait membersattribut
* @ORM\Table(name="source_group")
* @ORM\Entity
*/
final class TreeCollectionSource extends AbstractCollectionSource implements TreeCollectionSourceInterface
{
use MembersAttribut;
use CollectionDimensionHelperMethod;
}

View File

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

View File

@ -5,8 +5,8 @@ namespace Tests\Unit\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\MembershipsAttributInterface;
use App\Entity\Attribut\MembershipsAttribut;
use App\Entity\Source\Collection\MemberCollectionSourceInterface;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Source\Collection\TreeCollectionSourceInterface;
class MembershipsAttributTest extends TestCase
{
@ -30,7 +30,7 @@ class MembershipsAttributTest extends TestCase
public function testAccessors(): void
{
$membership = $this->createMock(MemberCollectionSourceInterface::class);
$membership = $this->createMock(TreeCollectionSourceInterface::class);
$this->assertNull($this->memberships->setMemberships(new ArrayCollection([$membership])));
$this->assertEquals($this->memberships->getMemberships()->get(0), $membership);
}

View File

@ -1,42 +0,0 @@
<?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

@ -0,0 +1,45 @@
<?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\TreeCollectionSourceInterface;
use App\Entity\Source\Collection\TreeCollectionSource;
use App\Helper\DimensionHelperInterface;
/**
* @author kevinfrantz
*/
class TreeCollectionSourceTest extends TestCase
{
/**
* @var TreeCollectionSourceInterface
*/
protected $tree;
public function setUp(): void
{
$this->tree = new TreeCollectionSource();
}
public function testConstructor(): void
{
$this->assertInstanceOf(Collection::class, $this->tree->getMembers());
$this->assertInstanceOf(TreeCollectionSourceInterface::class, $this->tree);
$this->assertInstanceOf(DimensionHelperInterface::class, $this->tree);
}
public function testMembers()
{
$member = new class() extends AbstractSource {
};
$this->tree->setMembers(new ArrayCollection([
$member,
]));
$this->assertEquals($member, $this->tree->getMembers()
->get(0));
}
}