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,75 @@
<?php
namespace Tests\Unit\Domain\SourceManagement;
use PHPUnit\Framework\TestCase;
use App\Entity\Source\SourceInterface;
use App\Entity\Source\Complex\UserSource;
use App\Entity\Source\Primitive\Text\TextSource;
use App\Entity\Source\Primitive\Name\FirstNameSource;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Source\Complex\FullPersonNameSource;
use App\Domain\SourceManagement\SourceMemberInformation;
use App\Domain\SourceManagement\SourceMemberInformationInterface;
use App\Entity\Source\PureSource;
class SourceMemberInformationTest extends TestCase
{
/**
* @var SourceInterface
*/
private $source;
/**
* @var SourceMemberInformationInterface
*/
private $sourceMemberInformation;
public function setUp(): void
{
$this->source = new UserSource();
$this->sourceMemberInformation = new SourceMemberInformation($this->source);
}
public function testOneDimension(): void
{
$this->source->getMemberRelation()->getMembers()->add((new TextSource())->getMemberRelation());
$allSourceMembers = $this->sourceMemberInformation->getAllMembers();
$this->assertEquals(1, $allSourceMembers->count());
$this->assertInstanceOf(SourceInterface::class, $allSourceMembers[0]);
}
public function testThreeDimension(): void
{
$source1 = new TextSource();
$source2 = new FirstNameSource();
$source2->getMemberRelation()->setMembers(new ArrayCollection([$source1->getMemberRelation()]));
$source3 = new FullPersonNameSource();
$source3->getMemberRelation()->getMembers()->add($source2->getMemberRelation());
$this->source->getMemberRelation()->getMembers()->add($source3->getMemberRelation());
$allSourceMembers = $this->sourceMemberInformation->getAllMembers();
$this->assertEquals(3, $allSourceMembers->count());
foreach ($allSourceMembers as $sourceMember) {
$this->assertInstanceOf(SourceInterface::class, $sourceMember);
}
}
public function testRecursion(): void
{
$recursiveSource = new UserSource();
$recursiveSource->getMemberRelation()->getMembers()->add($this->source->getMemberRelation());
$this->source->getMemberRelation()->getMembers()->add($recursiveSource->getMemberRelation());
$allSourceMembers = $this->sourceMemberInformation->getAllMembers();
$this->assertEquals(2, $allSourceMembers->count());
foreach ($allSourceMembers as $sourceMember) {
$this->assertInstanceOf(SourceInterface::class, $sourceMember);
}
}
public function testError(): void
{
$this->expectException(\Error::class);
$this->source->getMemberRelation()->getMembers()->add(new PureSource());
$this->sourceMemberInformation->getAllMembers();
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace Tests\Unit\Domain\SourceManagement;
use PHPUnit\Framework\TestCase;
use App\Entity\Source\SourceInterface;
use App\Domain\SourceManagement\SourceMemberManagerInterface;
use App\Domain\SourceManagement\SourceMemberManager;
use App\Entity\Source\PureSource;
class SourceMemberManagerTest extends TestCase
{
/**
* @var SourceInterface
*/
private $source;
/**
* @var SourceMemberManagerInterface
*/
private $sourceMemberManager;
public function setUp(): void
{
$this->source = new PureSource();
$this->sourceMemberManager = new SourceMemberManager($this->source);
}
public function testAddAndRemoveMember(): void
{
$member = new PureSource();
$this->assertNull($this->sourceMemberManager->addMember($member));
$this->assertEquals($member, $this->source->getMemberRelation()->getMembers()->get(0)->getSource());
$this->assertEquals($this->source, $member->getMemberRelation()->getMemberships()->get(0)->getSource());
$this->assertNull($this->sourceMemberManager->removeMember($member));
$this->assertEquals(0, $this->source->getMemberRelation()->getMembers()->count());
$this->assertEquals(0, $member->getMemberRelation()->getMemberships()->count());
}
public function testAddAndRemoveMembership(): void
{
$membership = new PureSource();
$this->assertNull($this->sourceMemberManager->addMembership($membership));
$this->assertEquals($membership, $this->source->getMemberRelation()->getMemberships()->get(0)->getSource());
$this->assertEquals($this->source, $membership->getMemberRelation()->getMembers()->get(0)->getSource());
$this->assertNull($this->sourceMemberManager->removeMembership($membership));
$this->assertEquals(0, $this->source->getMemberRelation()->getMemberships()->count());
$this->assertEquals(0, $membership->getMemberRelation()->getMembers()->count());
}
}

View File

@@ -0,0 +1,64 @@
<?php
namespace Tests\Unit\Domain\SourceManagement;
use PHPUnit\Framework\TestCase;
use App\Domain\SourceManagement\SourceMembershipInformationInterface;
use App\Domain\SourceManagement\SourceMembershipInformation;
use App\Entity\Source\SourceInterface;
use App\Entity\Source\Complex\UserSource;
use App\Entity\Source\Primitive\Text\TextSource;
use App\Entity\Source\Primitive\Name\FirstNameSource;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Source\Complex\FullPersonNameSource;
class SourceMembershipInformationTest extends TestCase
{
/**
* @var SourceInterface
*/
protected $source;
/**
* @var SourceMembershipInformationInterface
*/
protected $sourceMembershipInformation;
public function setUp(): void
{
$this->source = new UserSource();
$this->sourceMembershipInformation = new SourceMembershipInformation($this->source);
}
public function testOneDimension(): void
{
$this->source->getMemberRelation()->getMemberships()->add((new TextSource())->getMemberRelation());
$this->assertEquals(1, $this->sourceMembershipInformation->getAllMemberships()->count());
}
public function testThreeDimension(): void
{
$source1 = new TextSource();
$source2 = new FirstNameSource();
$source2->getMemberRelation()->setMemberships(new ArrayCollection([$source1->getMemberRelation()]));
$source3 = new FullPersonNameSource();
$source3->getMemberRelation()->getMemberships()->add($source2->getMemberRelation());
$this->source->getMemberRelation()->getMemberships()->add($source3->getMemberRelation());
$this->assertEquals(3, $this->sourceMembershipInformation->getAllMemberships()->count());
}
public function testRecursion(): void
{
$recursiveSource = new UserSource();
$recursiveSource->getMemberRelation()->getMemberships()->add($this->source->getMemberRelation());
$this->source->getMemberRelation()->getMemberships()->add($recursiveSource->getMemberRelation());
$this->assertEquals(2, $this->sourceMembershipInformation->getAllMemberships()->count());
}
public function testError(): void
{
$this->expectException(\Error::class);
$this->source->getMemberRelation()->getMemberships()->add($this->createSourceMock());
$this->sourceMembershipInformation->getAllMemberships();
}
}

View File

@@ -0,0 +1,82 @@
<?php
namespace Tests\Unit\Domain\SourceManagement;
use PHPUnit\Framework\TestCase;
use App\Domain\SourceManagement\SourceMetaInterface;
use App\Entity\Source\Complex\UserSource;
use App\Domain\SourceManagement\SourceMeta;
use App\Entity\Source\Complex\UserSourceInterface;
use App\Domain\TemplateManagement\TemplateMetaInterface;
use App\Entity\Source\SourceInterface;
use App\Domain\FormManagement\FormMetaInterface;
class SourceMetaTest extends TestCase
{
/**
* @var SourceMetaInterface
*/
protected $sourceMeta;
/**
* @var SourceInterface
*/
protected $source;
public function setUp(): void
{
$this->source = new UserSource();
$this->sourceMeta = new SourceMeta($this->source);
}
public function testBasicName(): void
{
$this->assertEquals('user', $this->sourceMeta->getBasicName());
$this->assertNotEquals('user2', $this->sourceMeta->getBasicName());
}
public function testBasicPath(): void
{
$subset = ['source', 'complex'];
$amount = count($subset);
$basicPathArray = $this->sourceMeta->getBasicPathArray();
for ($index = 0; $index < $amount; ++$index) {
$this->assertEquals($subset[$index], $basicPathArray[$index]);
}
$this->assertArraySubset($subset, $basicPathArray);
$this->assertEquals($amount, count($basicPathArray));
}
public function testInterfaceReflection(): void
{
/**
* @var \ReflectionClass
*/
$interfaceReflection = $this->sourceMeta->getInterfaceReflection();
$this->assertEquals(UserSourceInterface::class, $interfaceReflection->getName());
}
public function testSourceReflection(): void
{
/**
* @var \ReflectionClass
*/
$sourceReflection = $this->sourceMeta->getSourceReflection();
$this->assertEquals(UserSource::class, $sourceReflection->getName());
}
public function testTemplateMeta(): void
{
$this->assertInstanceOf(TemplateMetaInterface::class, $this->sourceMeta->getTemplateMeta());
}
public function testSource(): void
{
$this->assertEquals($this->source, $this->sourceMeta->getSource());
}
public function testFormMeta(): void
{
$this->assertInstanceOf(FormMetaInterface::class, $this->sourceMeta->getFormMeta());
}
}

View File

@@ -0,0 +1,79 @@
<?php
namespace Unit\Domain\SourceManagement;
use PHPUnit\Framework\TestCase;
use App\Entity\Source\SourceInterface;
use App\Domain\SourceManagement\SourceRightManagerInterface;
use App\Domain\SourceManagement\SourceRightManager;
use App\Entity\Meta\RightInterface;
use App\Entity\Meta\Right;
use App\Entity\Meta\Law;
use App\Exception\AllreadySetException;
use App\Exception\NotSetException;
use App\Exception\AllreadyDefinedException;
use App\Entity\Source\PureSource;
class SourceRightManagerTest extends TestCase
{
/**
* @var SourceInterface
*/
private $source;
/**
* @var SourceRightManagerInterface
*/
private $sourceRightManager;
/**
* @var RightInterface
*/
private $right;
public function setUp(): void
{
$this->source = new PureSource();
$this->sourceRightManager = new SourceRightManager($this->source);
$this->right = new Right();
}
public function testLawException(): void
{
$this->right->setLaw(new Law());
$this->expectException(AllreadyDefinedException::class);
$this->sourceRightManager->addRight($this->right);
}
public function testSourceException(): void
{
$this->right->setSource(new PureSource());
$this->expectException(AllreadyDefinedException::class);
$this->sourceRightManager->addRight($this->right);
}
public function testNotSetException(): void
{
$this->expectException(NotSetException::class);
$this->sourceRightManager->removeRight($this->right);
}
public function testAllreadSetException(): void
{
$this->sourceRightManager->addRight($this->right);
$this->expectException(AllreadySetException::class);
$this->sourceRightManager->addRight($this->right);
}
public function testRightAdd(): void
{
$this->assertNull($this->sourceRightManager->addRight($this->right));
$this->assertEquals($this->source, $this->right->getSource());
$this->assertEquals($this->right, $this->source->getLaw()->getRights()->get(0));
$this->assertEquals($this->right->getLaw(), $this->source->getLaw());
$this->assertNull($this->sourceRightManager->removeRight($this->right));
$this->assertNotEquals($this->source, $this->right->getSource());
$this->assertNotEquals($this->right->getLaw(), $this->source->getLaw());
$this->assertEquals(0, $this->source->getLaw()->getRights()->count());
}
}

View File

@@ -0,0 +1,56 @@
<?php
namespace Tests\Unit\Domain\SourceManagement;
use PHPUnit\Framework\TestCase;
use App\Entity\Source\Complex\Collection\TreeCollectionSource;
use App\Entity\Source\SourceInterface;
use Doctrine\Common\Collections\ArrayCollection;
use App\Domain\SourceManagement\TreeSourceServiceInterface;
use App\Domain\SourceManagement\TreeSourceService;
class TreeSourceServiceTest extends TestCase
{
/**
* @var TreeSourceServiceInterface
*/
protected $treeService;
public function setUp(): void
{
$tree1 = new TreeCollectionSource();
$tree2 = new TreeCollectionSource();
$tree3 = new TreeCollectionSource();
$tree4 = new TreeCollectionSource();
$tree5 = new TreeCollectionSource(new ArrayCollection([$tree2]));
$leave1 = $this->createMock(SourceInterface::class);
$leave2 = $this->createMock(SourceInterface::class);
$leave3 = $this->createMock(SourceInterface::class);
$leave4 = $this->createMock(SourceInterface::class);
$leave5 = $this->createMock(SourceInterface::class);
$tree2->setCollection(new ArrayCollection([$leave3, $leave4, $tree5, $leave5]));
$collection = new ArrayCollection([$tree2, $tree3, $leave1, $leave2, $tree4, $tree1]);
$tree1->setCollection($collection);
$this->treeService = new TreeSourceService($tree1);
}
public function testGetLeaves(): void
{
$this->assertEquals(2, $this->treeService->getLeaves()->count());
}
public function testGetBranches(): void
{
$this->assertEquals(4, $this->treeService->getBranches()->count());
}
public function testGetAllBranches(): void
{
$this->assertEquals(5, $this->treeService->getAllBranches()->count());
}
public function testGetAllLeaves(): void
{
$this->assertEquals(5, $this->treeService->getAllLeaves()->count());
}
}