mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 22:17:26 +01:00
Renamed GroupSourcesAttribut to MembershipsAttribut and Implemented\Optimized tests
This commit is contained in:
parent
5f18245b73
commit
61186470da
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Attribut;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use App\Entity\Source\GroupSourceInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
trait GroupSourcesAttribut
|
||||
{
|
||||
/**
|
||||
* @var Collection|GroupSourceInterface[]
|
||||
*/
|
||||
protected $groups;
|
||||
|
||||
/**
|
||||
* @return Collection|GroupSourceInterface[]
|
||||
*/
|
||||
public function getGroupSources(): Collection
|
||||
{
|
||||
return $this->groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection|GroupSourceInterface[] $groups
|
||||
*/
|
||||
public function setGroupSources(Collection $groups): void
|
||||
{
|
||||
$this->groups = $groups;
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Attribut;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use App\Entity\Source\GroupSourceInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface GroupSourcesAttributInterface
|
||||
{
|
||||
/**
|
||||
* @param Collection|GroupSourceInterface[] $groups
|
||||
*/
|
||||
public function setGroupSources(Collection $groups): void;
|
||||
|
||||
/**
|
||||
* @return Collection|GroupSourceInterface[]
|
||||
*/
|
||||
public function getGroupSources(): Collection;
|
||||
}
|
34
application/src/Entity/Attribut/MembershipsAttribut.php
Normal file
34
application/src/Entity/Attribut/MembershipsAttribut.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Attribut;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use App\Entity\Source\GroupSourceInterface;
|
||||
use App\Entity\Source\Collection\MemberCollectionSourceInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
trait MembershipsAttribut
|
||||
{
|
||||
/**
|
||||
* @var Collection|MemberCollectionSourceInterface[]
|
||||
*/
|
||||
protected $memberships;
|
||||
|
||||
/**
|
||||
* @return Collection|MemberCollectionSourceInterface[]
|
||||
*/
|
||||
public function getMemberships(): Collection
|
||||
{
|
||||
return $this->memberships;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection|MemberCollectionSourceInterface[] $memberships
|
||||
*/
|
||||
public function setMemberships(Collection $memberships): void
|
||||
{
|
||||
$this->memberships = $memberships;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Attribut;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use App\Entity\Source\Collection\MemberCollectionSourceInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface MembershipsAttributInterface
|
||||
{
|
||||
/**
|
||||
* @param Collection|MemberCollectionSourceInterface[] $groups
|
||||
*/
|
||||
public function setMemberships(Collection $memberships): void;
|
||||
|
||||
/**
|
||||
* @return Collection|MemberCollectionSourceInterface[]
|
||||
*/
|
||||
public function getMemberships(): Collection;
|
||||
}
|
@ -15,6 +15,7 @@ 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;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@ -28,7 +29,7 @@ use App\Entity\Source\Collection\MemberCollectionSource;
|
||||
*/
|
||||
abstract class AbstractSource extends AbstractEntity implements SourceInterface
|
||||
{
|
||||
use RelationAttribut,GroupSourcesAttribut, LawAttribut;
|
||||
use RelationAttribut,MembershipsAttribut, LawAttribut;
|
||||
|
||||
/**
|
||||
* @var RelationInterface
|
||||
@ -45,7 +46,7 @@ abstract class AbstractSource extends AbstractEntity implements SourceInterface
|
||||
* @var Collection|MemberCollectionSource[]
|
||||
* @ORM\ManyToMany(targetEntity="GroupSource",mappedBy="members")
|
||||
*/
|
||||
protected $groups;
|
||||
protected $memberships;
|
||||
|
||||
/**
|
||||
* @ORM\OneToOne(targetEntity="App\Entity\Meta\Law",cascade={"persist", "remove"})
|
||||
@ -61,6 +62,6 @@ abstract class AbstractSource extends AbstractEntity implements SourceInterface
|
||||
$this->relation = new Relation();
|
||||
$this->relation->setSource($this);
|
||||
$this->law = new Law();
|
||||
$this->groups = new ArrayCollection();
|
||||
$this->memberships = new ArrayCollection();
|
||||
}
|
||||
}
|
||||
|
@ -4,13 +4,13 @@ namespace App\Entity\Source;
|
||||
|
||||
use App\Entity\Attribut\IdAttributInterface;
|
||||
use App\Entity\EntityInterface;
|
||||
use App\Entity\Attribut\GroupSourcesAttributInterface;
|
||||
use App\Entity\Attribut\LawAttributInterface;
|
||||
use App\Entity\Attribut\RelationAttributInterface;
|
||||
use App\Entity\Attribut\MembershipsAttributInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface SourceInterface extends IdAttributInterface, EntityInterface, GroupSourcesAttributInterface, LawAttributInterface, RelationAttributInterface
|
||||
interface SourceInterface extends IdAttributInterface, EntityInterface, MembershipsAttributInterface, LawAttributInterface, RelationAttributInterface
|
||||
{
|
||||
}
|
||||
|
34
application/tests/Unit/Entity/Attribut/IdAttributTest.php
Normal file
34
application/tests/Unit/Entity/Attribut/IdAttributTest.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Entity\Attribut;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use App\Entity\Attribut\IdAttribut;
|
||||
use App\Entity\Attribut\IdAttributInterface;
|
||||
|
||||
class IdAttributTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var IdAttributInterface
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
public function setUp():void{
|
||||
$this->id = new class implements IdAttributInterface{
|
||||
use IdAttribut;
|
||||
};
|
||||
}
|
||||
|
||||
public function testConstruct():void{
|
||||
$this->expectException(\TypeError::class);
|
||||
$this->id->getId();
|
||||
}
|
||||
|
||||
public function testAccessors():void{
|
||||
$id = 1234;
|
||||
$this->assertNull($this->id->setId($id));
|
||||
$this->assertEquals($id, $this->id->getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ use App\Entity\Attribut\MembersAttributInterface;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use App\Entity\Source\AbstractSource;
|
||||
use App\Tests\AbstractTestCase;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
|
||||
class MembersAttributTest extends AbstractTestCase
|
||||
{
|
||||
@ -49,8 +50,7 @@ class MembersAttributTest extends AbstractTestCase
|
||||
|
||||
public function testMembersAccessors()
|
||||
{
|
||||
$source1 = new class() extends AbstractSource {
|
||||
};
|
||||
$source1 = $this->createMock(SourceInterface::class);
|
||||
$source2 = clone $source1;
|
||||
$source3 = clone $source1;
|
||||
$members = new ArrayCollection([
|
||||
@ -115,8 +115,7 @@ class MembersAttributTest extends AbstractTestCase
|
||||
|
||||
public function testMemberWithoutMembers(): void
|
||||
{
|
||||
$source1 = new class() extends AbstractSource {
|
||||
};
|
||||
$source1 = $this->createMock(SourceInterface::class);
|
||||
$this->membersAttribut->setMembers(new ArrayCollection([$source1]));
|
||||
$this->assertEquals(1, $this->membersAttribut->getMembersIncludingChildren()->count());
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
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;
|
||||
|
||||
class MembershipsAttributTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var MembershipsAttributInterface
|
||||
*/
|
||||
protected $memberships;
|
||||
|
||||
public function setUp():void{
|
||||
$this->memberships = new class implements MembershipsAttributInterface{
|
||||
use MembershipsAttribut;
|
||||
};
|
||||
}
|
||||
|
||||
public function testConstructor():void {
|
||||
$this->expectException(\TypeError::class);
|
||||
$this->memberships->getMemberships();
|
||||
}
|
||||
|
||||
public function testAccessors():void {
|
||||
$membership = $this->createMock(MemberCollectionSourceInterface::class);
|
||||
$this->assertNull($this->memberships->setMemberships(new ArrayCollection([$membership])));
|
||||
$this->assertEquals($this->memberships->getMemberships()->get(0), $membership);
|
||||
}
|
||||
}
|
||||
|
@ -7,15 +7,14 @@ use App\Entity\Source\SourceInterface;
|
||||
use App\Entity\Meta\LawInterface;
|
||||
use App\Entity\Meta\RelationInterface;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use App\Entity\Source\AbstractSource;
|
||||
use App\Entity\EntityInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class AbstractSourceTest extends TestCase
|
||||
{
|
||||
const ID = 123;
|
||||
/**
|
||||
* @var SourceInterface
|
||||
*/
|
||||
@ -23,33 +22,15 @@ class AbstractSourceTest extends TestCase
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->source = new class() extends \App\Entity\Source\AbstractSource {
|
||||
$this->source = new class() extends AbstractSource {
|
||||
};
|
||||
$this->source->setId(self::ID);
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$this->assertInstanceOf(EntityInterface::class, $this->source);
|
||||
$this->assertInstanceOf(RelationInterface::class, $this->source->getRelation());
|
||||
}
|
||||
|
||||
public function testId()
|
||||
{
|
||||
$this->assertEquals($this->source->getId(), self::ID);
|
||||
}
|
||||
|
||||
public function testLaw()
|
||||
{
|
||||
$this->assertInstanceOf(Collection::class, $this->source->getMemberships());
|
||||
$this->assertInstanceOf(LawInterface::class, $this->source->getLaw());
|
||||
}
|
||||
|
||||
public function testGroups()
|
||||
{
|
||||
$this->assertInstanceOf(Collection::class, $this->source->getGroupSources());
|
||||
$group = new class() extends AbstractSource {
|
||||
};
|
||||
$groups = new ArrayCollection([$group]);
|
||||
$this->source->setGroupSources($groups);
|
||||
$this->assertEquals($group, $this->source->getGroupSources()->get(0));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user