2018-10-28 20:28:29 +01:00
|
|
|
<?php
|
2018-10-29 19:01:00 +01:00
|
|
|
|
2018-10-28 20:28:29 +01:00
|
|
|
namespace tests\unit\Entity\Source;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use App\Entity\Source\SourceInterface;
|
|
|
|
use App\Entity\Meta\LawInterface;
|
|
|
|
use App\Entity\Meta\RelationInterface;
|
|
|
|
use Doctrine\Common\Collections\Collection;
|
2018-10-28 22:43:35 +01:00
|
|
|
use App\Entity\Source\AbstractSource;
|
2018-11-01 20:42:18 +01:00
|
|
|
use App\Entity\EntityInterface;
|
2018-10-28 20:28:29 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author kevinfrantz
|
|
|
|
*/
|
|
|
|
class AbstractSourceTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var SourceInterface
|
|
|
|
*/
|
|
|
|
protected $source;
|
2018-10-29 19:01:00 +01:00
|
|
|
|
2018-11-24 21:21:59 +01:00
|
|
|
private function getSourceDummy(): SourceInterface
|
2018-10-29 19:01:00 +01:00
|
|
|
{
|
2018-11-24 21:21:59 +01:00
|
|
|
return new class() extends AbstractSource {
|
2018-10-29 19:01:00 +01:00
|
|
|
};
|
2018-10-28 20:28:29 +01:00
|
|
|
}
|
2018-10-29 19:01:00 +01:00
|
|
|
|
2018-11-24 21:21:59 +01:00
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
$this->source = $this->getSourceDummy();
|
|
|
|
}
|
|
|
|
|
2018-10-31 23:11:34 +01:00
|
|
|
public function testConstructor(): void
|
|
|
|
{
|
2018-11-01 20:42:18 +01:00
|
|
|
$this->assertInstanceOf(EntityInterface::class, $this->source);
|
2018-10-31 23:11:34 +01:00
|
|
|
$this->assertInstanceOf(RelationInterface::class, $this->source->getRelation());
|
2018-11-01 20:42:18 +01:00
|
|
|
$this->assertInstanceOf(Collection::class, $this->source->getMemberships());
|
2018-10-29 19:01:00 +01:00
|
|
|
$this->assertInstanceOf(LawInterface::class, $this->source->getLaw());
|
2018-11-24 18:13:04 +01:00
|
|
|
$this->assertInstanceOf(Collection::class, $this->source->getMembers());
|
2018-10-28 20:28:29 +01:00
|
|
|
}
|
2018-11-23 18:17:00 +01:00
|
|
|
|
2018-11-24 21:21:59 +01:00
|
|
|
public function testAddAndRemoveMember(): void
|
|
|
|
{
|
|
|
|
$member = $this->getSourceDummy();
|
|
|
|
$this->assertNull($this->source->addMember($member));
|
|
|
|
$this->assertEquals($member, $this->source->getMembers()->get(0));
|
|
|
|
$this->assertEquals($this->source, $member->getMemberships()->get(0));
|
|
|
|
$this->assertNull($this->source->removeMember($member));
|
|
|
|
$this->assertEquals(0, $this->source->getMembers()->count());
|
|
|
|
$this->assertEquals(0, $member->getMemberships()->count());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddAndRemoveMembership(): void
|
|
|
|
{
|
|
|
|
$membership = $this->getSourceDummy();
|
|
|
|
$this->assertNull($this->source->addMembership($membership));
|
|
|
|
$this->assertEquals($membership, $this->source->getMemberships()->get(0));
|
|
|
|
$this->assertEquals($this->source, $membership->getMembers()->get(0));
|
|
|
|
$this->assertNull($this->source->removeMembership($membership));
|
|
|
|
$this->assertEquals(0, $this->source->getMemberships()->count());
|
|
|
|
$this->assertEquals(0, $membership->getMembers()->count());
|
|
|
|
}
|
|
|
|
|
2018-11-23 18:17:00 +01:00
|
|
|
public function testSlugInit(): void
|
|
|
|
{
|
|
|
|
$this->expectException(\TypeError::class);
|
|
|
|
$this->source->getSlug();
|
|
|
|
}
|
2018-11-01 22:34:26 +01:00
|
|
|
}
|