mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 13:57:10 +02:00
General optimation of tests and namespaces
This commit is contained in:
42
application/tests/Unit/Entity/AbstractEntityTest.php
Normal file
42
application/tests/Unit/Entity/AbstractEntityTest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace tests\unit\Entity;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use App\Entity\EntityInterface;
|
||||
use App\Entity\AbstractEntity;
|
||||
|
||||
class AbstractEntityTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var EntityInterface
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->entity = new class() extends AbstractEntity {
|
||||
};
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$this->expectException(\TypeError::class);
|
||||
$this->entity->getId();
|
||||
$this->entity->getVersion();
|
||||
}
|
||||
|
||||
public function testVersion(): void
|
||||
{
|
||||
$version = 123;
|
||||
$this->assertNull($this->entity->setVersion($version));
|
||||
$this->assertEquals($version, $this->entity->getVersion());
|
||||
}
|
||||
|
||||
public function testId(): void
|
||||
{
|
||||
$id = 123;
|
||||
$this->assertNull($this->entity->setId($id));
|
||||
$this->assertEquals($id, $this->entity->getId());
|
||||
}
|
||||
}
|
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests\Unit\Entity\Attribut;
|
||||
|
||||
use App\Entity\Attribut\MembersAttribut;
|
||||
use App\Entity\Attribut\MembersAttributInterface;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use App\Entity\Source\AbstractSource;
|
||||
use App\Entity\Source\GroupSource;
|
||||
use App\Tests\AbstractTestCase;
|
||||
|
||||
class MembersAttributTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* @var MembersAttributInterface
|
||||
*/
|
||||
protected $membersAttribut;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->membersAttribut = new class() implements MembersAttributInterface {
|
||||
use MembersAttribut;
|
||||
};
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$this->expectException(\TypeError::class);
|
||||
$this->membersAttribut->getMembers();
|
||||
$this->membersAttribut->getMembersInclusiveChildren();
|
||||
}
|
||||
|
||||
public function testContinueIncludeMemberLoop(){
|
||||
$reflection = new \ReflectionClass($this->membersAttribut);
|
||||
$method = $reflection->getMethod('continueIncludeMembersLoop');
|
||||
$method->setAccessible(true);
|
||||
|
||||
}
|
||||
|
||||
public function testMembersAccessors()
|
||||
{
|
||||
$source1 = new class() extends AbstractSource {
|
||||
};
|
||||
$source2 = clone $source1;
|
||||
$source3 = clone $source1;
|
||||
$members = new ArrayCollection([
|
||||
$source1,
|
||||
$source2,
|
||||
$source3,
|
||||
]);
|
||||
$this->assertNull($this->membersAttribut->setMembers($members));
|
||||
$this->assertEquals($members, $this->membersAttribut->getMembers());
|
||||
}
|
||||
|
||||
public function testMembersIncludingChildren(): void
|
||||
{
|
||||
$source1 = new GroupSource();
|
||||
|
||||
//Level 3
|
||||
$source2 = clone $source1;
|
||||
$source3 = clone $source1;
|
||||
$source4 = clone $source1;
|
||||
$source5 = clone $source1;
|
||||
$source6 = clone $source1;
|
||||
$source1->setMembers(new ArrayCollection([$source2]));
|
||||
$source2->setMembers(new ArrayCollection([$source3]));
|
||||
$source3->setMembers(new ArrayCollection([$source4]));
|
||||
$source4->setMembers(new ArrayCollection([$source5]));
|
||||
$source5->setMembers(new ArrayCollection([$source6]));
|
||||
|
||||
$level3Elements = [$source1, $source2, $source3];
|
||||
|
||||
//Recursion
|
||||
$source7 = clone $source1;
|
||||
$source8 = clone $source1;
|
||||
$source7->setMembers(new ArrayCollection([$source8]));
|
||||
$source8->setMembers(new ArrayCollection([$source7]));
|
||||
|
||||
//Source without members:
|
||||
$source9 = new class() extends AbstractSource {
|
||||
};
|
||||
$allMembers = [$source1, $source2, $source3, $source4, $source5, $source6, $source7, $source8, $source9];
|
||||
//$this->assertArraySubset($source1->getMembersInclusiveChildren(3)->toArray(), $level3Elements);
|
||||
$this->assertArraySubset($source1->getMembersInclusiveChildren()->toArray(), $allMembers);
|
||||
//$this->assertArraySubset($source1->getMembers()->toArray(), $source1->getMembersInclusiveChildren(1)->toArray());
|
||||
//$this->assertArraySubset($source1->getMembersInclusiveChildren(1)->toArray(), $source1->getMembers()->toArray());
|
||||
}
|
||||
}
|
36
application/tests/Unit/Entity/Meta/LawTest.php
Normal file
36
application/tests/Unit/Entity/Meta/LawTest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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->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));
|
||||
}
|
||||
}
|
26
application/tests/Unit/Entity/Meta/RecieverTest.php
Normal file
26
application/tests/Unit/Entity/Meta/RecieverTest.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\tests\unit\Entity\Meta;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use App\Entity\Meta\Reciever;
|
||||
use App\Entity\Meta\RecieverInterface;
|
||||
|
||||
class RecieverTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var RecieverInterface
|
||||
*/
|
||||
public $reciever;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->reciever = new Reciever();
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$this->assertEquals(Collection::class, $this->reciever->getAllRecievers());
|
||||
}
|
||||
}
|
47
application/tests/Unit/Entity/Meta/RightTest.php
Normal file
47
application/tests/Unit/Entity/Meta/RightTest.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace tests\unit\Entity;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use App\DBAL\Types\RightType;
|
||||
use App\Entity\Meta\RightInterface;
|
||||
use App\Entity\Meta\Right;
|
||||
use App\Entity\Meta\Law;
|
||||
|
||||
/**
|
||||
* @todo Implement reciever test
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class RightTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var RightInterface
|
||||
*/
|
||||
protected $right;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->right = new Right();
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$this->expectException(\TypeError::class);
|
||||
$this->assertNull($this->right->getLaw());
|
||||
$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
|
||||
{
|
||||
$this->assertNull($this->right->setType(RightType::READ));
|
||||
$this->assertEquals(RightType::READ, $this->right->getType());
|
||||
}
|
||||
}
|
55
application/tests/Unit/Entity/Source/AbstractSourceTest.php
Normal file
55
application/tests/Unit/Entity/Source/AbstractSourceTest.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use App\Entity\Source\AbstractSource;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class AbstractSourceTest extends TestCase
|
||||
{
|
||||
const ID = 123;
|
||||
/**
|
||||
* @var SourceInterface
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->source = new class() extends \App\Entity\Source\AbstractSource {
|
||||
};
|
||||
$this->source->setId(self::ID);
|
||||
}
|
||||
|
||||
public function testId()
|
||||
{
|
||||
$this->assertEquals($this->source->getId(), self::ID);
|
||||
}
|
||||
|
||||
public function testLaw()
|
||||
{
|
||||
$this->assertInstanceOf(LawInterface::class, $this->source->getLaw());
|
||||
}
|
||||
|
||||
public function testRelation()
|
||||
{
|
||||
$this->assertInstanceOf(RelationInterface::class, $this->source->getRelation());
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
35
application/tests/Unit/Entity/Source/GroupSourceTest.php
Normal file
35
application/tests/Unit/Entity/Source/GroupSourceTest.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace tests\unit\Entity\Source;
|
||||
|
||||
use App\Entity\Source\GroupSourceInterface;
|
||||
use App\Entity\Source\GroupSource;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use App\Entity\Source\AbstractSource;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class GroupSourceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var GroupSourceInterface
|
||||
*/
|
||||
protected $groupSource;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->groupSource = new GroupSource();
|
||||
}
|
||||
|
||||
public function testMembers()
|
||||
{
|
||||
$this->assertInstanceOf(Collection::class, $this->groupSource->getMembers());
|
||||
$member = new class() extends AbstractSource {
|
||||
};
|
||||
$this->groupSource->setMembers(new ArrayCollection([$member]));
|
||||
$this->assertEquals($member, $this->groupSource->getMembers()->get(0));
|
||||
}
|
||||
}
|
31
application/tests/Unit/Entity/Source/NameSourceTest.php
Normal file
31
application/tests/Unit/Entity/Source/NameSourceTest.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace tests\unit\Entity\Source;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use App\Entity\Source\NameSourceInterface;
|
||||
use App\Entity\Source\NameSource;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class NameSourceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var NameSourceInterface
|
||||
*/
|
||||
protected $nameSource;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->nameSource = new NameSource();
|
||||
}
|
||||
|
||||
public function testName(): void
|
||||
{
|
||||
$this->assertEquals('', $this->nameSource->getName());
|
||||
$name = 'Hello World!';
|
||||
$this->nameSource->setName($name);
|
||||
$this->assertEquals($name, $this->nameSource->getName());
|
||||
}
|
||||
}
|
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace tests\unit\Entity\Source\Operand;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use App\Entity\Source\Operation\AbstractOperation;
|
||||
use App\Entity\Source\Operation\OperationInterface;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use App\Logic\Operation\OperandInterface;
|
||||
use App\Logic\Result\ResultInterface;
|
||||
use App\Logic\Result\Result;
|
||||
use App\Exception\NotProcessedException;
|
||||
|
||||
class AbstractOperationTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var OperationInterface
|
||||
*/
|
||||
protected $operation;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->operation = new class() extends AbstractOperation {
|
||||
public function process(): void
|
||||
{
|
||||
$this->result = new Result();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$this->assertInstanceOf(Collection::class, $this->operation->getOperands());
|
||||
}
|
||||
|
||||
public function testOperands(): void
|
||||
{
|
||||
$operand = new class() implements OperandInterface {
|
||||
public function getResult(): ResultInterface
|
||||
{
|
||||
return new Result();
|
||||
}
|
||||
};
|
||||
$operands = new ArrayCollection();
|
||||
$operands->add($operand);
|
||||
$this->assertNull($this->operation->setOperands($operands));
|
||||
$this->assertEquals($operand, $this->operation->getOperands()
|
||||
->get(0));
|
||||
}
|
||||
|
||||
public function testNotProcessedException(): void
|
||||
{
|
||||
$this->expectException(NotProcessedException::class);
|
||||
$this->operation->getResult();
|
||||
}
|
||||
|
||||
public function testResult(): void
|
||||
{
|
||||
$this->setUp();
|
||||
$this->operation->process();
|
||||
$this->assertInstanceOf(ResultInterface::class, $this->operation->getResult());
|
||||
}
|
||||
|
||||
public function testProcess(): void
|
||||
{
|
||||
$this->assertEquals(null, $this->operation->process());
|
||||
}
|
||||
}
|
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace tests\unit\Entity\Source\Operation;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use App\Exception\NotDefinedException;
|
||||
use App\Logic\Result\Result;
|
||||
use App\Logic\Operation\OperandInterface;
|
||||
use App\Logic\Result\ResultInterface;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use App\Entity\Source\Operation\OperationInterface;
|
||||
use App\Entity\Source\Operation\AndOperation;
|
||||
|
||||
class AndOperationTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var OperationInterface
|
||||
*/
|
||||
protected $operation;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->operation = new AndOperation();
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$this->expectException(NotDefinedException::class);
|
||||
$this->operation->process();
|
||||
}
|
||||
|
||||
public function testProcess(): void
|
||||
{
|
||||
//Test True
|
||||
$operand1 = new class() implements OperandInterface {
|
||||
public function getResult(): ResultInterface
|
||||
{
|
||||
$result = new Result();
|
||||
$result->setAll(true);
|
||||
|
||||
return $result;
|
||||
}
|
||||
};
|
||||
|
||||
$operand2 = new class() implements OperandInterface {
|
||||
public function getResult(): ResultInterface
|
||||
{
|
||||
$result = new Result();
|
||||
$result->setAll(true);
|
||||
|
||||
return $result;
|
||||
}
|
||||
};
|
||||
$operands = new ArrayCollection([$operand1, $operand2]);
|
||||
$this->operation->setOperands($operands);
|
||||
$this->operation->process();
|
||||
$this->assertEquals(true, $this->operation->getResult()->getBool());
|
||||
|
||||
//Test False
|
||||
$operand3 = new class() implements OperandInterface {
|
||||
public function getResult(): ResultInterface
|
||||
{
|
||||
$result = new Result();
|
||||
$result->setAll(false);
|
||||
|
||||
return $result;
|
||||
}
|
||||
};
|
||||
$this->operation->getOperands()->add($operand3);
|
||||
$this->operation->process();
|
||||
$this->assertEquals(false, $this->operation->getResult()->getBool());
|
||||
}
|
||||
}
|
51
application/tests/Unit/Entity/UserTest.php
Normal file
51
application/tests/Unit/Entity/UserTest.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace tests\unit\Entity;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use App\Entity\User;
|
||||
use App\Entity\Source\UserSource;
|
||||
use App\Entity\UserInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
use App\Entity\Source\UserSource;
|
||||
*/
|
||||
class UserTest extends TestCase
|
||||
{
|
||||
const PASSWORD = '12345678';
|
||||
|
||||
const USERNAME = 'tester';
|
||||
|
||||
/**
|
||||
* @var UserInterface
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->user = new User();
|
||||
$this->user->setUsername(self::USERNAME);
|
||||
$this->user->setPassword(self::PASSWORD);
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$this->assertInstanceOf(UserInterface::class, new User());
|
||||
}
|
||||
|
||||
public function testUsername(): void
|
||||
{
|
||||
$this->assertEquals(self::USERNAME, $this->user->getUsername());
|
||||
}
|
||||
|
||||
public function testPassword(): void
|
||||
{
|
||||
$this->assertEquals(self::PASSWORD, $this->user->getPassword());
|
||||
}
|
||||
|
||||
public function testSource(): void
|
||||
{
|
||||
$this->assertInstanceOf(UserSource::class, $this->user->getSource());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user