Implemented Collection Attribut

This commit is contained in:
Kevin Frantz 2018-11-02 20:28:42 +01:00
parent 9bcc54cc64
commit cbb8bc702c
3 changed files with 77 additions and 0 deletions

View File

@ -0,0 +1,29 @@
<?php
namespace App\Entity\Attribut;
use Doctrine\Common\Collections\Collection;
trait CollectionAttribut
{
/**
* @var Collection
*/
protected $collection;
/**
* @return Collection
*/
public function getCollection(): Collection
{
return $this->collection;
}
/**
* @param Collection $collection
*/
public function setCollection(Collection $collection): void
{
$this->collection = $collection;
}
}

View File

@ -0,0 +1,12 @@
<?php
namespace App\Entity\Attribut;
use Doctrine\Common\Collections\Collection;
interface CollectionAttributInterface
{
public function getCollection(): Collection;
public function setCollection(Collection $collection): void;
}

View File

@ -0,0 +1,36 @@
<?php
namespace Tests\Unit\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\CollectionAttributInterface;
use App\Entity\Attribut\CollectionAttribut;
use Doctrine\Common\Collections\ArrayCollection;
class CollectionAttributTest extends TestCase
{
/**
* @var CollectionAttributInterface
*/
protected $collection;
public function setUp(): void
{
$this->collection = new class() implements CollectionAttributInterface {
use CollectionAttribut;
};
}
public function testConstructor(): void
{
$this->expectException(\TypeError::class);
$this->collection->getCollection();
}
public function testAccessors(): void
{
$collection = new ArrayCollection();
$this->assertNull($this->collection->setCollection($collection));
$this->assertEquals($collection, $this->collection->getCollection());
}
}