Continued integration of CreatorParent

This commit is contained in:
Kevin Frantz 2018-11-25 23:12:42 +01:00
parent ba3a246c0c
commit 884c4cfaea
9 changed files with 149 additions and 13 deletions

View File

@ -0,0 +1,21 @@
<?php
namespace App\Entity\Attribut;
use App\Entity\Meta\Relation\CreatorRelationInterface;
trait CreatorRelationAttribut
{
/**
* @var CreatorRelationInterface
*/
protected $creatorRelation;
public function setCreatorRelation(CreatorRelationInterface $creatorRelation){
$this->creatorRelation = $creatorRelation;
}
public function getCreatorRelation():CreatorRelationInterface{
return $this->creatorRelation;
}
}

View File

@ -0,0 +1,11 @@
<?php
namespace App\Entity\Attribut;
use App\Entity\Meta\Relation\CreatorRelationInterface;
interface CreatorRelationAttributInterface
{
public function setCreatorRelation(CreatorRelationInterface $creatorRelation);
public function getCreatorRelation():CreatorRelationInterface;
}

View File

@ -0,0 +1,21 @@
<?php
namespace App\Entity\Attribut;
use App\Entity\Meta\Relation\Parent\ParentRelationInterface;
trait ParentRelationAttribut
{
/**
*
* @var ParentRelationInterface
*/
protected $parentRelation;
public function setParentRelation(ParentRelationInterface $parentRelation):void{
$this->parentRelation = $parentRelation;
}
public function getParentRelation():ParentRelationInterface{
return $this->parentRelation;
}
}

View File

@ -0,0 +1,12 @@
<?php
namespace App\Entity\Attribut;
use App\Entity\Meta\Relation\Parent\ParentRelationInterface;
interface ParentRelationAttributInterface
{
public function setParentRelation(ParentRelationInterface $parentRelation):void;
public function getParentRelation():ParentRelationInterface;
}

View File

@ -6,9 +6,6 @@ use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\Exclude;
use App\Entity\AbstractEntity;
use Doctrine\Common\Collections\Collection;
use App\Entity\Meta\RelationInterface;
use App\Entity\Attribut\RelationAttribut;
use App\Entity\Meta\Relation;
use App\Entity\Attribut\LawAttribut;
use App\Entity\Meta\LawInterface;
use App\Entity\Meta\Law;
@ -18,6 +15,9 @@ use App\Entity\Attribut\SlugAttribut;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
use App\Entity\Attribut\MembersAttribut;
use App\Entity\Attribut\CreatorRelationAttribut;
use App\Entity\Meta\Relation\CreatorRelationInterface;
use App\Entity\Meta\Relation\Parent\CreatorRelation;
/**
* @author kevinfrantz
@ -47,7 +47,7 @@ use App\Entity\Attribut\MembersAttribut;
*/
abstract class AbstractSource extends AbstractEntity implements SourceInterface
{
use RelationAttribut,MembershipsAttribut, LawAttribut,SlugAttribut,MembersAttribut;
use MembershipsAttribut, LawAttribut,SlugAttribut,MembersAttribut,CreatorRelationAttribut;
/**
* System slugs should be writen in UPPER CASES
@ -61,12 +61,12 @@ abstract class AbstractSource extends AbstractEntity implements SourceInterface
protected $slug;
/**
* @var RelationInterface
* @ORM\OneToOne(targetEntity="App\Entity\Meta\Relation",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="relation_id", referencedColumnName="id", onDelete="CASCADE")
* @var CreatorRelationInterface
* @ORM\OneToOne(targetEntity="App\Entity\Meta\Relation\Parent\CreatorRelation",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="creator_relation_id", referencedColumnName="id", onDelete="CASCADE")
* @Exclude
*/
protected $relation;
protected $creatorRelation;
/**
* Many Sources have many Source Members.
@ -97,9 +97,14 @@ abstract class AbstractSource extends AbstractEntity implements SourceInterface
public function __construct()
{
parent::__construct();
$this->relation = new Relation();
$this->relation->setSource($this);
$this->creatorRelation = new CreatorRelation();
$this->creatorRelation->setSource($this);
$this->law = new Law();
$this->law->setSource($this);
/**
*
* @todo Refactor the following attibutes
*/
$this->memberships = new ArrayCollection();
$this->members = new ArrayCollection();
}

View File

@ -5,14 +5,14 @@ namespace App\Entity\Source;
use App\Entity\Attribut\IdAttributInterface;
use App\Entity\EntityInterface;
use App\Entity\Attribut\LawAttributInterface;
use App\Entity\Attribut\RelationAttributInterface;
use App\Entity\Attribut\MembershipsAttributInterface;
use App\Entity\Attribut\SlugAttributInterface;
use App\Entity\Attribut\MembersAttributInterface;
use App\Entity\Attribut\CreatorRelationAttributInterface;
/**
* @author kevinfrantz
*/
interface SourceInterface extends IdAttributInterface, EntityInterface, MembershipsAttributInterface, LawAttributInterface, RelationAttributInterface, SlugAttributInterface, MembersAttributInterface
interface SourceInterface extends IdAttributInterface, EntityInterface, MembershipsAttributInterface, LawAttributInterface, SlugAttributInterface, MembersAttributInterface,CreatorRelationAttributInterface
{
}

View File

@ -0,0 +1,33 @@
<?php
namespace App\Tests\Unit\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\ParentRelationAttributInterface;
use App\Entity\Attribut\ParentRelationAttribut;
use App\Entity\Meta\Relation\Parent\ParentRelationInterface;
use App\Entity\Attribut\CreatorRelationAttributInterface;
use App\Entity\Attribut\CreatorRelationAttribut;
use App\Entity\Meta\Relation\CreatorRelationInterface;
class CreatorRelationAttributTest extends TestCase
{
/***
* @var CreatorRelationAttributInterface
*/
protected $creatorRelationAttribut;
public function setUp(): void
{
$this->creatorRelationAttribut = new class() implements CreatorRelationAttributInterface {
use CreatorRelationAttribut;
};
}
public function testAccessors(): void
{
$relation = $this->createMock(CreatorRelationInterface::class);
$this->assertNull($this->creatorRelationAttribut->setCreatorRelation($relation));
$this->assertEquals($relation, $this->creatorRelationAttribut->getCreatorRelation());
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace App\Tests\Unit\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\ParentRelationAttributInterface;
use App\Entity\Attribut\ParentRelationAttribut;
use App\Entity\Meta\Relation\Parent\ParentRelationInterface;
class ParentRelationAttributTest extends TestCase
{
/***
* @var ParentRelationAttributInterface
*/
protected $parentRelationAttribut;
public function setUp(): void
{
$this->parentRelationAttribut = new class() implements ParentRelationAttributInterface {
use ParentRelationAttribut;
};
}
public function testAccessors(): void
{
$relation = $this->createMock(ParentRelationInterface::class);
$this->assertNull($this->parentRelationAttribut->setParentRelation($relation));
$this->assertEquals($relation, $this->parentRelationAttribut->getParentRelation());
}
}

View File

@ -9,6 +9,7 @@ use App\Entity\Meta\RelationInterface;
use Doctrine\Common\Collections\Collection;
use App\Entity\Source\AbstractSource;
use App\Entity\EntityInterface;
use App\Entity\Meta\Relation\CreatorRelationInterface;
/**
* @author kevinfrantz
@ -34,9 +35,11 @@ class AbstractSourceTest extends TestCase
public function testConstructor(): void
{
$this->assertInstanceOf(EntityInterface::class, $this->source);
$this->assertInstanceOf(RelationInterface::class, $this->source->getRelation());
$this->assertInstanceOf(CreatorRelationInterface::class, $this->source->getCreatorRelation());
$this->assertEquals($this->source, $this->source->getCreatorRelation()->getSource());
$this->assertInstanceOf(Collection::class, $this->source->getMemberships());
$this->assertInstanceOf(LawInterface::class, $this->source->getLaw());
$this->assertEquals($this->source, $this->source->getLaw()->getSource());
$this->assertInstanceOf(Collection::class, $this->source->getMembers());
}