infinito/application/symfony/tests/Unit/Entity/Meta/LawTest.php
2019-03-29 18:44:22 +01:00

49 lines
1.4 KiB
PHP

<?php
namespace tests\unit\Entity\Meta;
use PHPUnit\Framework\TestCase;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use Infinito\Entity\Meta\LawInterface;
use Infinito\Entity\Meta\Law;
use Infinito\Entity\Meta\Right;
class LawTest extends TestCase
{
/**
* @var LawInterface
*/
protected $law;
public function setUp(): void
{
$this->law = new Law();
}
public function testConstruct(): void
{
$this->assertFalse($this->law->getGrant());
$this->assertInstanceOf(Collection::class, $this->law->getRights());
}
public function testRights(): void
{
$right = new Right();
$rights = new ArrayCollection([$right, new Right(), new Right()]);
$this->assertNull($this->law->setRights($rights));
$this->assertEquals($right, $this->law->getRights()->get(0));
}
/**
* Implemented to debug where ReflectionException "Property Infinito\\Entity\\Meta\\Law::$relation does not exist" is coming from.
*/
public function testRelationNotSet(): void
{
$reflectionClass = new \ReflectionClass($this->law);
$this->assertFalse($reflectionClass->hasMethod('getRelation'));
$this->assertFalse($reflectionClass->hasMethod('setRelation'));
$this->assertFalse($reflectionClass->hasProperty('relation'));
}
}