mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 13:57:10 +02:00
Renamed domain SourceManagement to Source
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace tests\Unit\Domain\Source;
|
||||
|
||||
use Infinito\Domain\Source\SourceClassInformationServiceInterface;
|
||||
use Infinito\Domain\Source\SourceClassInformationService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Infinito\Entity\Source\PureSource;
|
||||
use Infinito\Entity\Source\Complex\AbstractComplexSource;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class SourceClassInformationServiceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var SourceClassInformationServiceInterface
|
||||
*/
|
||||
private $sourceClassInformationService;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->sourceClassInformationService = new SourceClassInformationService();
|
||||
}
|
||||
|
||||
public function testPureSource(): void
|
||||
{
|
||||
$allClasses = $this->sourceClassInformationService->getAllSourceClasses();
|
||||
$this->assertTrue(in_array(PureSource::class, $allClasses));
|
||||
}
|
||||
|
||||
public function testNotSource(): void
|
||||
{
|
||||
$allClasses = $this->sourceClassInformationService->getAllSourceClasses();
|
||||
$this->assertFalse(in_array('ALLALALABBBB', $allClasses));
|
||||
}
|
||||
|
||||
public function testSubSource(): void
|
||||
{
|
||||
$allClasses = $this->sourceClassInformationService->getAllSubSourceClasses('Infinito\\Entity\\Source\\Complex');
|
||||
$this->assertFalse(in_array(PureSource::class, $allClasses));
|
||||
$this->assertTrue(in_array(AbstractComplexSource::class, $allClasses));
|
||||
}
|
||||
}
|
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Domain\Source;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Infinito\Entity\Source\SourceInterface;
|
||||
use Infinito\Entity\Source\Complex\UserSource;
|
||||
use Infinito\Entity\Source\Primitive\Text\TextSource;
|
||||
use Infinito\Entity\Source\Primitive\Name\FirstNameSource;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Infinito\Entity\Source\Complex\FullPersonNameSource;
|
||||
use Infinito\Domain\Source\SourceMemberInformation;
|
||||
use Infinito\Domain\Source\SourceMemberInformationInterface;
|
||||
use Infinito\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();
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Domain\Source;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Infinito\Entity\Source\SourceInterface;
|
||||
use Infinito\Domain\Source\SourceMemberManagerInterface;
|
||||
use Infinito\Domain\Source\SourceMemberManager;
|
||||
use Infinito\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());
|
||||
}
|
||||
}
|
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Domain\Source;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Infinito\Domain\Source\SourceMembershipInformationInterface;
|
||||
use Infinito\Domain\Source\SourceMembershipInformation;
|
||||
use Infinito\Entity\Source\SourceInterface;
|
||||
use Infinito\Entity\Source\Complex\UserSource;
|
||||
use Infinito\Entity\Source\Primitive\Text\TextSource;
|
||||
use Infinito\Entity\Source\Primitive\Name\FirstNameSource;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Infinito\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();
|
||||
}
|
||||
}
|
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Unit\Domain\Source;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Infinito\Entity\Source\SourceInterface;
|
||||
use Infinito\Domain\Source\SourceRightManagerInterface;
|
||||
use Infinito\Domain\Source\SourceRightManager;
|
||||
use Infinito\Entity\Meta\RightInterface;
|
||||
use Infinito\Entity\Meta\Right;
|
||||
use Infinito\Entity\Meta\Law;
|
||||
use Infinito\Entity\Source\PureSource;
|
||||
use Infinito\Exception\Collection\ContainsElementException;
|
||||
use Infinito\Exception\Attribut\AllreadyDefinedAttributException;
|
||||
use Infinito\Exception\Collection\NotSetElementException;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
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(AllreadyDefinedAttributException::class);
|
||||
$this->sourceRightManager->addRight($this->right);
|
||||
}
|
||||
|
||||
public function testSourceException(): void
|
||||
{
|
||||
$this->right->setSource(new PureSource());
|
||||
$this->expectException(AllreadyDefinedAttributException::class);
|
||||
$this->sourceRightManager->addRight($this->right);
|
||||
}
|
||||
|
||||
public function testNotSetElementException(): void
|
||||
{
|
||||
$this->expectException(NotSetElementException::class);
|
||||
$this->sourceRightManager->removeRight($this->right);
|
||||
}
|
||||
|
||||
public function testAllreadSetException(): void
|
||||
{
|
||||
$this->sourceRightManager->addRight($this->right);
|
||||
$this->expectException(ContainsElementException::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());
|
||||
}
|
||||
}
|
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Domain\Source;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Infinito\Entity\Source\Complex\Collection\TreeCollectionSource;
|
||||
use Infinito\Entity\Source\SourceInterface;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Infinito\Domain\Source\TreeSourceInformationInterface;
|
||||
use Infinito\Domain\Source\TreeSourceInformation;
|
||||
|
||||
class TreeSourceInformationTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var TreeSourceInformationInterface
|
||||
*/
|
||||
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 TreeSourceInformation($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());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user