Refactored code through substituting by PureSource

This commit is contained in:
Kevin Frantz 2019-01-04 22:09:05 +01:00
parent 74c404a9ce
commit f931f824fb
11 changed files with 34 additions and 74 deletions

View File

@ -12,6 +12,7 @@ use App\DBAL\Types\LayerType;
use App\DBAL\Types\RightType; use App\DBAL\Types\RightType;
use App\Domain\UserManagement\UserIdentityManager; use App\Domain\UserManagement\UserIdentityManager;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Source\PureSource;
/** /**
* This controller offers the standart routes for the template. * This controller offers the standart routes for the template.
@ -28,8 +29,7 @@ final class DefaultController extends AbstractEntityController
{ {
$userIdentityManager = new UserIdentityManager($entityManager, $this->getUser()); $userIdentityManager = new UserIdentityManager($entityManager, $this->getUser());
$user = $userIdentityManager->getUser(); $user = $userIdentityManager->getUser();
$requestedSource = new class() extends AbstractSource { $requestedSource = new PureSource();
};
$requestedSource->setSlug(SystemSlugType::IMPRINT); $requestedSource->setSlug(SystemSlugType::IMPRINT);
$requestedRight = new Right(); $requestedRight = new Right();
$requestedRight->setSource($requestedSource); $requestedRight->setSource($requestedSource);

View File

@ -5,10 +5,10 @@ namespace Tests\Integration\Domain\SourceManagement;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use App\Entity\Source\SourceInterface; use App\Entity\Source\SourceInterface;
use App\Domain\SourceManagement\SourceMemberManagerInterface; use App\Domain\SourceManagement\SourceMemberManagerInterface;
use App\Entity\Source\AbstractSource;
use App\Domain\SourceManagement\SourceMemberManager; use App\Domain\SourceManagement\SourceMemberManager;
use App\Domain\SourceManagement\SourceMemberInformation; use App\Domain\SourceManagement\SourceMemberInformation;
use App\Domain\SourceManagement\SourceMembershipInformation; use App\Domain\SourceManagement\SourceMembershipInformation;
use App\Entity\Source\PureSource;
class SourceMemberManagerIntegrationTest extends TestCase class SourceMemberManagerIntegrationTest extends TestCase
{ {
@ -22,21 +22,15 @@ class SourceMemberManagerIntegrationTest extends TestCase
*/ */
private $sourceMemberManager; private $sourceMemberManager;
private function createSource(): SourceInterface
{
return new class() extends AbstractSource {
};
}
public function setUp(): void public function setUp(): void
{ {
$this->source = $this->createSource(); $this->source = new PureSource();
$this->sourceMemberManager = new SourceMemberManager($this->source); $this->sourceMemberManager = new SourceMemberManager($this->source);
} }
public function testSourceMemberInformationIntegration(): void public function testSourceMemberInformationIntegration(): void
{ {
$childSource = $this->createSource(); $childSource = new PureSource();
$sourceMemberInformation = new SourceMemberInformation($this->source); $sourceMemberInformation = new SourceMemberInformation($this->source);
$this->sourceMemberManager->addMember($childSource); $this->sourceMemberManager->addMember($childSource);
$this->assertEquals($childSource, $sourceMemberInformation->getAllMembers()->get(0)); $this->assertEquals($childSource, $sourceMemberInformation->getAllMembers()->get(0));
@ -46,7 +40,7 @@ class SourceMemberManagerIntegrationTest extends TestCase
public function testSourceMembershipInformationIntegration(): void public function testSourceMembershipInformationIntegration(): void
{ {
$parentSource = $this->createSource(); $parentSource = new PureSource();
$sourceMemberInformation = new SourceMembershipInformation($this->source); $sourceMemberInformation = new SourceMembershipInformation($this->source);
$this->sourceMemberManager->addMembership($parentSource); $this->sourceMemberManager->addMembership($parentSource);
$this->assertEquals($parentSource, $sourceMemberInformation->getAllMemberships()->get(0)); $this->assertEquals($parentSource, $sourceMemberInformation->getAllMemberships()->get(0));

View File

@ -6,7 +6,6 @@ use PHPUnit\Framework\TestCase;
use App\Domain\LawManagement\LawPermissionCheckerService; use App\Domain\LawManagement\LawPermissionCheckerService;
use App\Domain\LawManagement\LawPermissionCheckerServiceInterface; use App\Domain\LawManagement\LawPermissionCheckerServiceInterface;
use App\Entity\Source\SourceInterface; use App\Entity\Source\SourceInterface;
use App\Entity\Source\AbstractSource;
use App\Entity\Meta\Right; use App\Entity\Meta\Right;
use App\DBAL\Types\LayerType; use App\DBAL\Types\LayerType;
use App\DBAL\Types\RightType; use App\DBAL\Types\RightType;
@ -15,6 +14,7 @@ use App\Entity\Meta\LawInterface;
use App\Entity\Meta\RightInterface; use App\Entity\Meta\RightInterface;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use App\Domain\SourceManagement\SourceMemberManager; use App\Domain\SourceManagement\SourceMemberManager;
use App\Entity\Source\PureSource;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -46,12 +46,6 @@ class LawPermissionCheckerTest extends TestCase
*/ */
private $source; private $source;
private function getSourceMock(): SourceInterface
{
return new class() extends AbstractSource {
};
}
private function checkClientPermission(): bool private function checkClientPermission(): bool
{ {
return $this->lawPermissionChecker->hasPermission($this->clientRight); return $this->lawPermissionChecker->hasPermission($this->clientRight);
@ -79,13 +73,13 @@ class LawPermissionCheckerTest extends TestCase
private function setSourceDummy(): void private function setSourceDummy(): void
{ {
$this->source = $this->getSourceMock(); $this->source = new PureSource();
$this->source->setSlug('Requested Source'); $this->source->setSlug('Requested Source');
} }
private function setClientSourceDummy(): void private function setClientSourceDummy(): void
{ {
$this->clientSource = $this->getSourceMock(); $this->clientSource = new PureSource();
$this->clientSource->setSlug('Client Source'); $this->clientSource->setSlug('Client Source');
} }
@ -119,7 +113,7 @@ class LawPermissionCheckerTest extends TestCase
public function testChildMemberPermission(): void public function testChildMemberPermission(): void
{ {
$parentSource = $this->getSourceMock(); $parentSource = new PureSource();
$parentSource->setSlug('Parent Source'); $parentSource->setSlug('Parent Source');
$parentSourceMemberManager = new SourceMemberManager($parentSource); $parentSourceMemberManager = new SourceMemberManager($parentSource);
$parentSourceMemberManager->addMember($this->clientSource); $parentSourceMemberManager->addMember($this->clientSource);
@ -190,7 +184,7 @@ class LawPermissionCheckerTest extends TestCase
$right1 = $this->getClonedClientRight(); $right1 = $this->getClonedClientRight();
$right1->setPriority(123); $right1->setPriority(123);
$right1->setGrant(false); $right1->setGrant(false);
$right1->setReciever($this->getSourceMock()); $right1->setReciever(new PureSource());
$right1->getReciever()->setSlug('Rigth1 Reciever'); $right1->getReciever()->setSlug('Rigth1 Reciever');
$right2 = $this->getClonedClientRight(); $right2 = $this->getClonedClientRight();
$right2->setPriority(456); $right2->setPriority(456);

View File

@ -6,11 +6,11 @@ use PHPUnit\Framework\TestCase;
use App\Entity\Meta\RightInterface; use App\Entity\Meta\RightInterface;
use App\Entity\Meta\Right; use App\Entity\Meta\Right;
use App\Entity\Source\SourceInterface; use App\Entity\Source\SourceInterface;
use App\Entity\Source\AbstractSource;
use App\DBAL\Types\LayerType; use App\DBAL\Types\LayerType;
use App\Domain\RightManagement\RightCheckerInterface; use App\Domain\RightManagement\RightCheckerInterface;
use App\Domain\RightManagement\RightChecker; use App\Domain\RightManagement\RightChecker;
use App\DBAL\Types\RightType; use App\DBAL\Types\RightType;
use App\Entity\Source\PureSource;
class RightCheckerTest extends TestCase class RightCheckerTest extends TestCase
{ {
@ -39,17 +39,11 @@ class RightCheckerTest extends TestCase
*/ */
private $rightManager; private $rightManager;
private function getSourceMock(): SourceInterface
{
return new class() extends AbstractSource {
};
}
public function setUp(): void public function setUp(): void
{ {
$this->layer = LayerType::RELATION; $this->layer = LayerType::RELATION;
$this->type = RightType::READ; $this->type = RightType::READ;
$this->source = $this->getSourceMock(); $this->source = new PureSource();
$this->right = new Right(); $this->right = new Right();
$this->right->setReciever($this->source); $this->right->setReciever($this->source);
$this->right->setType($this->type); $this->right->setType($this->type);
@ -68,13 +62,13 @@ class RightCheckerTest extends TestCase
$this->right->setGrant(false); $this->right->setGrant(false);
$notGranted3 = $this->rightManager->isGranted($this->layer, $this->type, $this->source); $notGranted3 = $this->rightManager->isGranted($this->layer, $this->type, $this->source);
$this->assertFalse($notGranted3); $this->assertFalse($notGranted3);
$notGranted4 = $this->rightManager->isGranted($this->layer, $this->type, $this->getSourceMock()); $notGranted4 = $this->rightManager->isGranted($this->layer, $this->type, new PureSource());
$this->assertFalse($notGranted4); $this->assertFalse($notGranted4);
} }
public function testSecondDimension(): void public function testSecondDimension(): void
{ {
$secondSource = $this->getSourceMock(); $secondSource = new PureSource();
$this->source->getMemberRelation()->getMembers()->add($secondSource->getMemberRelation()); $this->source->getMemberRelation()->getMembers()->add($secondSource->getMemberRelation());
$granted = $this->rightManager->isGranted($this->layer, $this->type, $secondSource); $granted = $this->rightManager->isGranted($this->layer, $this->type, $secondSource);
$this->assertTrue($granted); $this->assertTrue($granted);
@ -89,8 +83,8 @@ class RightCheckerTest extends TestCase
public function testThirdDimension(): void public function testThirdDimension(): void
{ {
$thirdSource = $this->getSourceMock(); $thirdSource = new PureSource();
$secondSource = $this->getSourceMock(); $secondSource = new PureSource();
$secondSource->getMemberRelation()->getMembers()->add($thirdSource->getMemberRelation()); $secondSource->getMemberRelation()->getMembers()->add($thirdSource->getMemberRelation());
$this->source->getMemberRelation()->getMembers()->add($secondSource->getMemberRelation()); $this->source->getMemberRelation()->getMembers()->add($secondSource->getMemberRelation());
$granted = $this->rightManager->isGranted($this->layer, $this->type, $thirdSource); $granted = $this->rightManager->isGranted($this->layer, $this->type, $thirdSource);

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Tests\Unit\Domain; namespace Tests\Unit\Domain\SecureSourceManagement;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use App\Entity\Source\SourceInterface; use App\Entity\Source\SourceInterface;

View File

@ -11,7 +11,7 @@ use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Source\Complex\FullPersonNameSource; use App\Entity\Source\Complex\FullPersonNameSource;
use App\Domain\SourceManagement\SourceMemberInformation; use App\Domain\SourceManagement\SourceMemberInformation;
use App\Domain\SourceManagement\SourceMemberInformationInterface; use App\Domain\SourceManagement\SourceMemberInformationInterface;
use App\Entity\Source\AbstractSource; use App\Entity\Source\PureSource;
class SourceMemberInformationTest extends TestCase class SourceMemberInformationTest extends TestCase
{ {
@ -25,12 +25,6 @@ class SourceMemberInformationTest extends TestCase
*/ */
private $sourceMemberInformation; private $sourceMemberInformation;
private function createSourceMock(): SourceInterface
{
return new class() extends AbstractSource {
};
}
public function setUp(): void public function setUp(): void
{ {
$this->source = new UserSource(); $this->source = new UserSource();
@ -75,7 +69,7 @@ class SourceMemberInformationTest extends TestCase
public function testError(): void public function testError(): void
{ {
$this->expectException(\Error::class); $this->expectException(\Error::class);
$this->source->getMemberRelation()->getMembers()->add($this->createSourceMock()); $this->source->getMemberRelation()->getMembers()->add(new PureSource());
$this->sourceMemberInformation->getAllMembers(); $this->sourceMemberInformation->getAllMembers();
} }
} }

View File

@ -5,8 +5,8 @@ namespace Tests\Unit\Domain\SourceManagement;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use App\Entity\Source\SourceInterface; use App\Entity\Source\SourceInterface;
use App\Domain\SourceManagement\SourceMemberManagerInterface; use App\Domain\SourceManagement\SourceMemberManagerInterface;
use App\Entity\Source\AbstractSource;
use App\Domain\SourceManagement\SourceMemberManager; use App\Domain\SourceManagement\SourceMemberManager;
use App\Entity\Source\PureSource;
class SourceMemberManagerTest extends TestCase class SourceMemberManagerTest extends TestCase
{ {
@ -20,21 +20,15 @@ class SourceMemberManagerTest extends TestCase
*/ */
private $sourceMemberManager; private $sourceMemberManager;
private function createSource(): SourceInterface
{
return new class() extends AbstractSource {
};
}
public function setUp(): void public function setUp(): void
{ {
$this->source = $this->createSource(); $this->source = new PureSource();
$this->sourceMemberManager = new SourceMemberManager($this->source); $this->sourceMemberManager = new SourceMemberManager($this->source);
} }
public function testAddAndRemoveMember(): void public function testAddAndRemoveMember(): void
{ {
$member = $this->createSource(); $member = new PureSource();
$this->assertNull($this->sourceMemberManager->addMember($member)); $this->assertNull($this->sourceMemberManager->addMember($member));
$this->assertEquals($member, $this->source->getMemberRelation()->getMembers()->get(0)->getSource()); $this->assertEquals($member, $this->source->getMemberRelation()->getMembers()->get(0)->getSource());
$this->assertEquals($this->source, $member->getMemberRelation()->getMemberships()->get(0)->getSource()); $this->assertEquals($this->source, $member->getMemberRelation()->getMemberships()->get(0)->getSource());
@ -45,7 +39,7 @@ class SourceMemberManagerTest extends TestCase
public function testAddAndRemoveMembership(): void public function testAddAndRemoveMembership(): void
{ {
$membership = $this->createSource(); $membership = new PureSource();
$this->assertNull($this->sourceMemberManager->addMembership($membership)); $this->assertNull($this->sourceMemberManager->addMembership($membership));
$this->assertEquals($membership, $this->source->getMemberRelation()->getMemberships()->get(0)->getSource()); $this->assertEquals($membership, $this->source->getMemberRelation()->getMemberships()->get(0)->getSource());
$this->assertEquals($this->source, $membership->getMemberRelation()->getMembers()->get(0)->getSource()); $this->assertEquals($this->source, $membership->getMemberRelation()->getMembers()->get(0)->getSource());

View File

@ -5,7 +5,6 @@ namespace Unit\Domain\SourceManagement;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use App\Entity\Source\SourceInterface; use App\Entity\Source\SourceInterface;
use App\Domain\SourceManagement\SourceRightManagerInterface; use App\Domain\SourceManagement\SourceRightManagerInterface;
use App\Entity\Source\AbstractSource;
use App\Domain\SourceManagement\SourceRightManager; use App\Domain\SourceManagement\SourceRightManager;
use App\Entity\Meta\RightInterface; use App\Entity\Meta\RightInterface;
use App\Entity\Meta\Right; use App\Entity\Meta\Right;
@ -13,6 +12,7 @@ use App\Entity\Meta\Law;
use App\Exception\AllreadySetException; use App\Exception\AllreadySetException;
use App\Exception\NotSetException; use App\Exception\NotSetException;
use App\Exception\AllreadyDefinedException; use App\Exception\AllreadyDefinedException;
use App\Entity\Source\PureSource;
class SourceRightManagerTest extends TestCase class SourceRightManagerTest extends TestCase
{ {
@ -31,15 +31,9 @@ class SourceRightManagerTest extends TestCase
*/ */
private $right; private $right;
private function createSourceMock()
{
return new class() extends AbstractSource {
};
}
public function setUp(): void public function setUp(): void
{ {
$this->source = $this->createSourceMock(); $this->source = new PureSource();
$this->sourceRightManager = new SourceRightManager($this->source); $this->sourceRightManager = new SourceRightManager($this->source);
$this->right = new Right(); $this->right = new Right();
} }
@ -53,7 +47,7 @@ class SourceRightManagerTest extends TestCase
public function testSourceException(): void public function testSourceException(): void
{ {
$this->right->setSource($this->createSourceMock()); $this->right->setSource(new PureSource());
$this->expectException(AllreadyDefinedException::class); $this->expectException(AllreadyDefinedException::class);
$this->sourceRightManager->addRight($this->right); $this->sourceRightManager->addRight($this->right);
} }

View File

@ -6,9 +6,9 @@ use PHPUnit\Framework\TestCase;
use App\Entity\Source\SourceInterface; use App\Entity\Source\SourceInterface;
use App\Entity\Meta\LawInterface; use App\Entity\Meta\LawInterface;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use App\Entity\Source\AbstractSource;
use App\Entity\EntityInterface; use App\Entity\EntityInterface;
use App\Entity\Meta\Relation\Parent\CreatorRelationInterface; use App\Entity\Meta\Relation\Parent\CreatorRelationInterface;
use App\Entity\Source\PureSource;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -20,15 +20,9 @@ class AbstractSourceTest extends TestCase
*/ */
protected $source; protected $source;
private function getSourceDummy(): SourceInterface
{
return new class() extends AbstractSource {
};
}
public function setUp() public function setUp()
{ {
$this->source = $this->getSourceDummy(); $this->source = new PureSource();
} }
public function testConstructor(): void public function testConstructor(): void

View File

@ -5,9 +5,9 @@ namespace Tests\Unit\Entity\Source\Complex\Collection;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Source\AbstractSource;
use App\Entity\Source\Complex\Collection\TreeCollectionSourceInterface; use App\Entity\Source\Complex\Collection\TreeCollectionSourceInterface;
use App\Entity\Source\Complex\Collection\TreeCollectionSource; use App\Entity\Source\Complex\Collection\TreeCollectionSource;
use App\Entity\Source\PureSource;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -32,8 +32,7 @@ class TreeCollectionSourceTest extends TestCase
public function testAccessors() public function testAccessors()
{ {
$member = new class() extends AbstractSource { $member = new PureSource();
};
$this->tree->setCollection(new ArrayCollection([ $this->tree->setCollection(new ArrayCollection([
$member, $member,
])); ]));

View File

@ -8,6 +8,9 @@ use App\Entity\Source\PureSource;
use App\Entity\Source\AbstractSource; use App\Entity\Source\AbstractSource;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
/**
* @author kevinfrantz
*/
class PureSourceTest extends TestCase class PureSourceTest extends TestCase
{ {
/** /**