mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 13:57:10 +02:00
Optimized for SPA
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace tests\unit\Entity\Source;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
use App\Entity\Meta\LawInterface;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use App\Entity\EntityInterface;
|
||||
use App\Entity\Meta\Relation\Parent\CreatorRelationInterface;
|
||||
use App\Entity\Source\PureSource;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class AbstractSourceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var SourceInterface
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->source = new PureSource();
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$this->assertInstanceOf(EntityInterface::class, $this->source);
|
||||
$this->assertInstanceOf(CreatorRelationInterface::class, $this->source->getCreatorRelation());
|
||||
$this->assertEquals($this->source, $this->source->getCreatorRelation()->getSource());
|
||||
$this->assertInstanceOf(Collection::class, $this->source->getMemberRelation()->getMemberships());
|
||||
$this->assertInstanceOf(LawInterface::class, $this->source->getLaw());
|
||||
$this->assertEquals($this->source, $this->source->getLaw()->getSource());
|
||||
$this->assertInstanceOf(Collection::class, $this->source->getMemberRelation()->getMembers());
|
||||
}
|
||||
|
||||
public function testSlugInit(): void
|
||||
{
|
||||
$this->expectException(\TypeError::class);
|
||||
$this->source->getSlug();
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Entity\Source\Complex\Collection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use App\Entity\Source\Complex\Collection\CollectionSourceInterface;
|
||||
use App\Entity\Source\Complex\Collection\AbstractCollectionSource;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
|
||||
class AbstractCollectionSourceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var CollectionSourceInterface
|
||||
*/
|
||||
public $collectionSource;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->collectionSource = new class() extends AbstractCollectionSource {
|
||||
};
|
||||
}
|
||||
|
||||
public function testConstruct(): void
|
||||
{
|
||||
$this->assertInstanceOf(Collection::class, $this->collectionSource->getCollection());
|
||||
}
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Entity\Source\Complex\Collection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use App\Entity\Source\Complex\Collection\TreeCollectionSourceInterface;
|
||||
use App\Entity\Source\Complex\Collection\TreeCollectionSource;
|
||||
use App\Entity\Source\PureSource;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class TreeCollectionSourceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var TreeCollectionSourceInterface
|
||||
*/
|
||||
protected $tree;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->tree = new TreeCollectionSource();
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$this->assertInstanceOf(Collection::class, $this->tree->getCollection());
|
||||
$this->assertInstanceOf(TreeCollectionSourceInterface::class, $this->tree);
|
||||
}
|
||||
|
||||
public function testAccessors()
|
||||
{
|
||||
$member = new PureSource();
|
||||
$this->tree->setCollection(new ArrayCollection([
|
||||
$member,
|
||||
]));
|
||||
$this->assertEquals($member, $this->tree->getCollection()
|
||||
->get(0));
|
||||
}
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace tests\unit\Entity\Source\Complex;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use App\Entity\Source\Complex\FullPersonNameSourceInterface;
|
||||
use App\Entity\Source\Complex\FullPersonNameSource;
|
||||
use App\Entity\Source\Primitive\Name\SurnameSourceInterface;
|
||||
use App\Entity\Source\Primitive\Name\FirstNameSourceInterface;
|
||||
|
||||
class FullPersonNameSourceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var FullPersonNameSourceInterface
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->name = new FullPersonNameSource();
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$this->assertInstanceOf(SurnameSourceInterface::class, $this->name->getSurnameSource());
|
||||
$this->assertInstanceOf(FirstNameSourceInterface::class, $this->name->getFirstNameSource());
|
||||
}
|
||||
|
||||
public function testFirstNameAccessor(): void
|
||||
{
|
||||
$name = $this->createMock(FirstNameSourceInterface::class);
|
||||
$this->assertNull($this->name->setFirstNameSource($name));
|
||||
$this->assertEquals($name, $this->name->getFirstNameSource());
|
||||
}
|
||||
|
||||
public function testSurnameAccessor(): void
|
||||
{
|
||||
$name = $this->createMock(SurnameSourceInterface::class);
|
||||
$this->assertNull($this->name->setSurnameSource($name));
|
||||
$this->assertEquals($name, $this->name->getSurnameSource());
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace tests\unit\Entity\Source\Complex;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use App\Entity\Source\Complex\PersonIdentitySourceInterface;
|
||||
use App\Entity\Source\Complex\PersonIdentitySource;
|
||||
use App\Entity\Source\Complex\FullPersonNameSourceInterface;
|
||||
|
||||
class PersonIdentitySourceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var PersonIdentitySourceInterface
|
||||
*/
|
||||
protected $identity;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->identity = new PersonIdentitySource();
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$this->assertInstanceOf(FullPersonNameSourceInterface::class, $this->identity->getFullPersonNameSource());
|
||||
}
|
||||
|
||||
public function testFullName(): void
|
||||
{
|
||||
$name = $this->createMock(FullPersonNameSourceInterface::class);
|
||||
$this->assertNull($this->identity->setFullPersonNameSource($name));
|
||||
$this->assertEquals($name, $this->identity->getFullPersonNameSource());
|
||||
}
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace tests\unit\Entity\Source\Complex;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use App\Entity\Source\Complex\UserSourceInterface;
|
||||
use App\Entity\Source\Complex\UserSource;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use App\Entity\Source\Complex\PersonIdentitySourceInterface;
|
||||
|
||||
class UserSourceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var UserSourceInterface
|
||||
*/
|
||||
public $userSource;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->userSource = new UserSource();
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$this->assertInstanceOf(Collection::class, $this->userSource->getMemberRelation()->getMemberships());
|
||||
}
|
||||
|
||||
public function testHasPersonIdentitySource(): void
|
||||
{
|
||||
$this->assertFalse($this->userSource->hasPersonIdentitySource());
|
||||
$this->userSource->setPersonIdentitySource($this->createMock(PersonIdentitySourceInterface::class));
|
||||
$this->assertTrue($this->userSource->hasPersonIdentitySource());
|
||||
$this->assertInstanceOf(PersonIdentitySourceInterface::class, $this->userSource->getPersonIdentitySource());
|
||||
}
|
||||
|
||||
public function testInitPersonIdentitySource(): void
|
||||
{
|
||||
$this->expectException(\TypeError::class);
|
||||
$this->userSource->getPersonIdentitySource();
|
||||
}
|
||||
|
||||
public function testInitUser(): void
|
||||
{
|
||||
$this->expectException(\TypeError::class);
|
||||
$this->userSource->getUser();
|
||||
}
|
||||
}
|
@@ -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());
|
||||
}
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace tests\unit\Entity\Source\Primitive;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use App\Entity\Source\Primitive\Name\NameSourceInterface;
|
||||
use App\Entity\Source\Primitive\Name\AbstractNameSource;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class AbstractNameSourceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var NameSourceInterface
|
||||
*/
|
||||
protected $nameSource;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->nameSource = new class() extends AbstractNameSource {
|
||||
};
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$this->assertInstanceOf(NameSourceInterface::class, $this->nameSource);
|
||||
$this->expectException(\TypeError::class);
|
||||
$this->nameSource->getName();
|
||||
}
|
||||
|
||||
public function testName(): void
|
||||
{
|
||||
$name = 'Hello World!';
|
||||
$this->nameSource->setName($name);
|
||||
$this->assertEquals($name, $this->nameSource->getName());
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Entity\Source\Primitive\Text;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use App\Entity\Source\Primitive\Text\TextSourceInterface;
|
||||
use App\Entity\Source\Primitive\Text\TextSource;
|
||||
|
||||
class TextSourceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var TextSourceInterface
|
||||
*/
|
||||
protected $textSource;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->textSource = new TextSource();
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$this->expectException(\TypeError::class);
|
||||
$this->textSource->getText();
|
||||
}
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Entity\Source;
|
||||
|
||||
use App\Entity\Source\PureSourceInterface;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
use App\Entity\Source\PureSource;
|
||||
use App\Entity\Source\AbstractSource;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class PureSourceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var PureSourceInterface
|
||||
*/
|
||||
private $pureSource;
|
||||
|
||||
/**
|
||||
* @var SourceInterface
|
||||
*/
|
||||
private $abstractSource;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->pureSource = new PureSource();
|
||||
$this->abstractSource = new class() extends AbstractSource {
|
||||
};
|
||||
}
|
||||
|
||||
public function testMethodSet(): void
|
||||
{
|
||||
$pureSourceMethods = get_class_methods($this->pureSource);
|
||||
$abstractSourceMethods = get_class_methods($this->abstractSource);
|
||||
$this->assertArraySubset($pureSourceMethods, $abstractSourceMethods);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user