Optimized for SPA

This commit is contained in:
Kevin Frantz
2019-01-05 23:52:37 +01:00
parent 9e685260e9
commit bccd6efaff
393 changed files with 253 additions and 37 deletions

View File

@@ -0,0 +1,37 @@
<?php
namespace tests\unit\Entity\Meta;
use PHPUnit\Framework\TestCase;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Meta\LawInterface;
use App\Entity\Meta\Law;
use App\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));
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace Tests\Unit\Entity\Meta\Relation\Member;
use PHPUnit\Framework\TestCase;
use App\Entity\Meta\Relation\Member\MemberRelation;
use App\Entity\Meta\Relation\Member\MemberRelationInterface;
use Doctrine\Common\Collections\Collection;
class MemberRelationTest extends TestCase
{
/**
* @var MemberRelationInterface
*/
private $memberRelation;
public function setUp(): void
{
$this->memberRelation = new MemberRelation();
}
public function testConstructor(): void
{
$this->assertInstanceOf(Collection::class, $this->memberRelation->getMembers());
$this->assertInstanceOf(Collection::class, $this->memberRelation->getMemberships());
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace tests\Unit\Entity\Meta;
use PHPUnit\Framework\TestCase;
use Doctrine\Common\Collections\Collection;
use App\Entity\Meta\Relation\Parent\AbstractParentRelation;
use App\Entity\Meta\Relation\Parent\ParentRelationInterface;
class AbstractParentRelationTest extends TestCase
{
/**
* @var ParentRelationInterface
*/
protected $relation;
public function setUp(): void
{
$this->relation = new class() extends AbstractParentRelation {
};
}
public function testConstructor(): void
{
$this->assertInstanceOf(Collection::class, $this->relation->getChilds());
$this->assertInstanceOf(Collection::class, $this->relation->getParents());
$this->assertEquals(0, $this->relation->getVersion());
$this->expectException(\TypeError::class);
$this->relation->getSource();
}
}

View File

@@ -0,0 +1,116 @@
<?php
namespace tests\unit\Entity;
use PHPUnit\Framework\TestCase;
use App\DBAL\Types\Meta\Right\CRUDType;
use App\Entity\Meta\RightInterface;
use App\Entity\Meta\Right;
use App\Entity\Meta\Law;
use App\DBAL\Types\Meta\Right\LayerType;
use App\Exception\NoValidChoiceException;
use App\Entity\Source\AbstractSource;
/**
* @todo Implement reciever test
*
* @author kevinfrantz
*/
class RightTest extends TestCase
{
/**
* @var RightInterface
*/
private $right;
public function setUp(): void
{
$this->right = new Right();
}
public function testConstructorGeneral(): void
{
$this->assertTrue($this->right->getGrant());
$this->assertEquals(0, $this->right->getPriority());
}
public function testConstructorReciever(): void
{
$this->expectException(\TypeError::class);
$this->right->getReciever();
}
public function testConstructorLayer(): void
{
$this->expectException(\TypeError::class);
$this->assertNull($this->right->getLayer());
}
public function testConstructorLaw(): void
{
$this->expectException(\TypeError::class);
$this->assertNull($this->right->getLaw());
}
public function testConstructorCondition(): void
{
$this->expectException(\TypeError::class);
$this->right->getCondition();
}
public function testConstructorType(): void
{
$this->expectException(\TypeError::class);
$this->assertNull($this->right->getType());
}
public function testLaw(): void
{
$law = new Law();
$this->assertNull($this->right->setLaw($law));
$this->assertEquals($law, $this->right->getLaw());
}
public function testRight(): void
{
foreach (CRUDType::getChoices() as $key => $value) {
$this->assertNull($this->right->setType($key));
$this->assertEquals($key, $this->right->getType());
}
$this->expectException(NoValidChoiceException::class);
$this->right->setType('NoneValidType');
}
public function testLayer(): void
{
foreach (LayerType::getChoices() as $key => $value) {
$this->assertNull($this->right->setLayer($key));
$this->assertEquals($key, $this->right->getLayer());
}
$this->expectException(NoValidChoiceException::class);
$this->right->setLayer('NoneValidLayer');
}
/**
* Just to test if the clone function works like assumed.
*/
public function testClone(): void
{
$source = $this->createMock(AbstractSource::class);
$reciever = $this->createMock(AbstractSource::class);
$grant = false;
$type = CRUDType::READ;
$layer = LayerType::SOURCE;
$this->right->setSource($source);
$this->right->setReciever($reciever);
$this->right->setGrant($grant);
$this->right->setType($type);
$this->right->setLayer($layer);
$rightClone = clone $this->right;
$this->assertEquals($source, $rightClone->getSource());
$this->assertEquals($reciever, $rightClone->getReciever());
$this->assertEquals($grant, $rightClone->getGrant());
$this->assertEquals($type, $rightClone->getType());
$this->assertEquals($layer, $rightClone->getLayer());
}
}