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

0
application/symfony/tests/.gitignore vendored Normal file
View File

View File

@@ -0,0 +1,46 @@
<?php
namespace App\Tests;
use PHPUnit\Framework\TestCase;
abstract class AbstractTestCase extends TestCase
{
/**
* Call protected/private method of a class.
*
* @see https://jtreminio.com/blog/unit-testing-tutorial-part-iii-testing-protected-private-methods-coverage-reports-and-crap/
*
* @param object &$object Instantiated object that we will run method on
* @param string $methodName Method name to call
* @param array $parameters array of parameters to pass into method
*
* @return mixed method return
*/
public function invokeMethod(object &$object, string $methodName, array $parameters = [])
{
$reflection = $this->getReflectionClassByObject($object);
$method = $reflection->getMethod($methodName);
$method->setAccessible(true);
return $method->invokeArgs($object, $parameters);
}
/**
* @param object $object
* @param string $property
* @param mixed $value
*/
public function setProperty(object &$object, string $property, $value): void
{
$reflectionClass = $this->getReflectionClassByObject($object);
$reflectionProperty = $reflectionClass->getProperty($property);
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($object, $value);
}
private function getReflectionClassByObject(object &$object): \ReflectionClass
{
return new \ReflectionClass(get_class($object));
}
}

View File

View File

@@ -0,0 +1,41 @@
<?php
namespace Tests\Integration\Controller;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\HttpFoundation\Request;
/**
* @author kevinfrantz
*/
class RoutesGetStatusIntegrationTest extends KernelTestCase
{
const GET_URLS_STATUS = [
'login' => 200,
'imprint' => 200,
'register' => 301,
'logout' => 302,
'profile/edit' => 302,
'spa' => 200,
];
public function setUp(): void
{
self::bootKernel();
}
public function testParameterlesGetUrls(): void
{
foreach (self::GET_URLS_STATUS as $url => $status) {
$this->parameterlesGetRouteTest($url, $status);
}
}
private function parameterlesGetRouteTest(string $url, int $status): void
{
$request = new Request([], [], [], [], [], ['REQUEST_URI' => $url, null]);
$request->setMethod(Request::METHOD_GET);
$response = static::$kernel->handle($request);
$this->assertEquals($status, $response->getStatusCode());
}
}

View File

@@ -0,0 +1,78 @@
<?php
namespace Tests\Integration\Controller;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use App\DBAL\Types\LanguageType;
use App\DBAL\Types\Meta\Right\LayerType;
use App\DBAL\Types\RESTResponseType;
use Symfony\Component\HttpFoundation\Request;
/**
* @author kevinfrantz
*
* @todo Implement more tests for success etc.
*/
class RoutesReachableIntegrationTest extends KernelTestCase
{
public function setUp(): void
{
self::bootKernel();
}
public function testAllRoutePossibilities()
{
foreach (LayerType::getChoices() as $layer => $layerDescription) {
$this->controller($layer);
}
}
private function controller(string $entity)
{
$this->language($entity, Request::METHOD_GET);
$this->language($entity, Request::METHOD_POST);
$this->language($entity.'s', Request::METHOD_GET);
$this->slugAndId($entity, Request::METHOD_PUT);
$this->slugAndId($entity, Request::METHOD_GET);
$this->slugAndId($entity, Request::METHOD_DELETE);
}
private function slugAndId(string $route, string $method): void
{
$this->language("$route/12345", $method);
$this->language("$route/asdfg", $method);
}
/**
* @todo Implement routing without i18l part!
*
* @param string $entity
* @param string $method
*/
private function language(string $entity, string $method): void
{
//$this->type('api/'.$entity, $method);
foreach (LanguageType::getChoices() as $language) {
$this->type("$language/api/$entity", $method);
$this->type("$language/html/$entity", $method);
}
}
private function type(string $route, string $method): void
{
$this->routeAssert($route, $method);
foreach (RESTResponseType::getChoices() as $restResponseType => $value) {
$this->routeAssert("$route.$restResponseType", $method);
}
}
private function routeAssert(string $url, string $method): void
{
$request = new Request([], [], [], [], [], [
'REQUEST_URI' => $url,
]);
$request->setMethod($method);
$response = static::$kernel->handle($request);
$this->assertNotEquals(404, $response->getStatusCode(), "Route $url with Method $method sends an 404 response!");
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Tests\Integration\DataFixtures;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Doctrine\ORM\EntityManager;
use App\Entity\Source\AbstractSource;
use App\DBAL\Types\SystemSlugType;
use App\Entity\Source\Complex\UserSourceInterface;
class SourceFixturesIntegrationTest extends KernelTestCase
{
/**
* @var EntityManager
*/
protected $entityManager;
public function setUp(): void
{
self::bootKernel();
$this->entityManager = static::$kernel->getContainer()->get('doctrine')->getManager();
}
public function testImpressumSource(): void
{
$sourceRepository = $this->entityManager->getRepository(AbstractSource::class);
$imprint = $sourceRepository->findOneBySlug(SystemSlugType::IMPRINT);
$this->assertInternalType('string', $imprint->getText());
}
public function testGuestUserSource(): void
{
$sourceRepository = $this->entityManager->getRepository(AbstractSource::class);
$userSource = $sourceRepository->findOneBySlug(SystemSlugType::GUEST_USER);
$this->assertInstanceOf(UserSourceInterface::class, $userSource);
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace Tests\Integration\Domain\SourceManagement;
use PHPUnit\Framework\TestCase;
use App\Entity\Source\SourceInterface;
use App\Domain\SourceManagement\SourceMemberManagerInterface;
use App\Domain\SourceManagement\SourceMemberManager;
use App\Domain\SourceManagement\SourceMemberInformation;
use App\Domain\SourceManagement\SourceMembershipInformation;
use App\Entity\Source\PureSource;
class SourceMemberManagerIntegrationTest 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 testSourceMemberInformationIntegration(): void
{
$childSource = new PureSource();
$sourceMemberInformation = new SourceMemberInformation($this->source);
$this->sourceMemberManager->addMember($childSource);
$this->assertEquals($childSource, $sourceMemberInformation->getAllMembers()->get(0));
$this->sourceMemberManager->removeMember($childSource);
$this->assertEquals(0, $sourceMemberInformation->getAllMembers()->count());
}
public function testSourceMembershipInformationIntegration(): void
{
$parentSource = new PureSource();
$sourceMemberInformation = new SourceMembershipInformation($this->source);
$this->sourceMemberManager->addMembership($parentSource);
$this->assertEquals($parentSource, $sourceMemberInformation->getAllMemberships()->get(0));
$this->sourceMemberManager->removeMembership($parentSource);
$this->assertEquals(0, $sourceMemberInformation->getAllMemberships()->count());
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace Integration\Entity\Source;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use App\Repository\Source\SourceRepository;
use App\Entity\Source\PureSourceInterface;
use App\Entity\Source\PureSource;
/**
* @author kevinfrantz
*/
class PureSourceIntegrationTest extends KernelTestCase
{
/**
* @var EntityManagerInterface
*/
private $entityManager;
/**
* @var SourceRepository
*/
private $sourceRepository;
/**
* @var PureSourceInterface
*/
private $pureSource;
public function setUp(): void
{
self::bootKernel();
$this->entityManager = self::$container->get('doctrine.orm.default_entity_manager');
$this->sourceRepository = $this->entityManager->getRepository(PureSource::class);
$this->pureSource = new PureSource();
}
public function testDatabaseProcess(): void
{
$this->entityManager->persist($this->pureSource);
$this->entityManager->flush();
$this->assertGreaterThan(0, $this->pureSource->getId());
$this->entityManager->remove($this->pureSource);
$this->entityManager->flush();
$this->expectException(\TypeError::class);
$this->pureSource->getId();
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace Tests\Integration;
use PHPUnit\Framework\TestCase;
use Doctrine\Common\Collections\ArrayCollection;
/**
* This class tests if all needed Depencies for a source are implemented!
*
* @author kevinfrantz
*/
class SourceIntegrationTest extends TestCase
{
const SOURCE_DIRECTORY = __DIR__.'/../../src/Entity/Source';
/**
* @var ArrayCollection
*/
protected $sources;
private function iterate(string $path)
{
$directoryIterator = new \DirectoryIterator($path);
foreach ($directoryIterator as $fileInfo) {
if (!in_array($fileInfo->getFilename(), [
'.',
'..',
])) {
$pathname = $fileInfo->getPathname();
if ($fileInfo->isDir()) {
$this->iterate($pathname);
} elseif (false === strpos($pathname, 'Interface.php')) {
$this->sources->add(realpath($pathname));
}
}
}
}
public function setUp(): void
{
$this->sources = new ArrayCollection();
$this->iterate(self::SOURCE_DIRECTORY);
}
private function filterSourcePath(string $path): string
{
$path = str_replace('/Abstract', '/', $path);
$path = str_replace('.php', '', $path);
return $path;
}
private function getInterfacePath(string $path): string
{
return $this->filterSourcePath($path).'Interface.php';
}
public function testInterfaces(): void
{
foreach ($this->sources as $source) {
$interfacePath = $this->getInterfacePath($source);
$this->assertTrue(file_exists($this->getInterfacePath($source)), "Interface $interfacePath for $source doesn't exist!");
}
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Tests\Unit\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use App\Controller\DefaultController;
/**
* @author kevinfrantz
*/
class DefaultControllerTest extends WebTestCase
{
/**
* @var DefaultController
*/
protected $defaultController;
public function setUp(): void
{
$this->defaultController = new DefaultController();
}
public function testHomepage(): void
{
$client = static::createClient();
$client->request('GET', '/');
$this->assertEquals(200, $client->getResponse()->getStatusCode());
}
public function testImprint(): void
{
$client = static::createClient();
$client->request('GET', '/imprint');
$this->assertEquals(200, $client->getResponse()->getStatusCode());
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Tests\Unit\Domain;
use PHPUnit\Framework\TestCase;
use App\Domain\FormManagement\FormMetaInterface;
use App\Domain\FormManagement\FormMeta;
use App\Entity\Source\Primitive\Name\SurnameSource;
use App\Domain\SourceManagement\SourceMeta;
use App\Domain\TemplateManagement\TemplateMetaInterface;
class FormMetaTest extends TestCase
{
/**
* @var FormMetaInterface
*/
protected $formMeta;
public function setUp(): void
{
$sourceMeta = new SourceMeta(new SurnameSource());
$this->formMeta = new FormMeta($sourceMeta);
}
public function testGetFormClass(): void
{
$this->assertEquals('App\Form\Source\Primitive\Name\SurnameType', $this->formMeta->getFormClass());
}
public function testTemplateMeta(): void
{
$this->assertInstanceOf(TemplateMetaInterface::class, $this->formMeta->getTemplateMeta());
}
}

View File

@@ -0,0 +1,206 @@
<?php
namespace Unit\Domain\LawManagement;
use PHPUnit\Framework\TestCase;
use App\Domain\LawManagement\LawPermissionCheckerService;
use App\Domain\LawManagement\LawPermissionCheckerServiceInterface;
use App\Entity\Source\SourceInterface;
use App\Entity\Meta\Right;
use App\DBAL\Types\Meta\Right\LayerType;
use App\DBAL\Types\Meta\Right\CRUDType;
use App\Entity\Meta\Law;
use App\Entity\Meta\LawInterface;
use App\Entity\Meta\RightInterface;
use Doctrine\Common\Collections\ArrayCollection;
use App\Domain\SourceManagement\SourceMemberManager;
use App\Entity\Source\PureSource;
/**
* @author kevinfrantz
*/
class LawPermissionCheckerTest extends TestCase
{
/**
* @var LawPermissionCheckerServiceInterface The service which checks the law
*/
private $lawPermissionChecker;
/**
* @var LawInterface The law which applies to the source
*/
private $law;
/**
* @var RightInterface
*/
private $clientRight;
/**
* @var SourceInterface The client which requests a law
*/
private $clientSource;
/**
* @var SourceInterface The source to which the law applies
*/
private $source;
private function checkClientPermission(): bool
{
return $this->lawPermissionChecker->hasPermission($this->clientRight);
}
public function setUp(): void
{
$this->setSourceDummy();
$this->setLawDummy();
$this->setLawPermissionChecker();
$this->setClientSourceDummy();
$this->setClientRightDummy();
}
private function setLawPermissionChecker(): void
{
$this->lawPermissionChecker = new LawPermissionCheckerService($this->law);
}
private function setLawDummy(): void
{
$this->law = new Law();
$this->law->setSource($this->source);
}
private function setSourceDummy(): void
{
$this->source = new PureSource();
$this->source->setSlug('Requested Source');
}
private function setClientSourceDummy(): void
{
$this->clientSource = new PureSource();
$this->clientSource->setSlug('Client Source');
}
private function setClientRightDummy(): void
{
$this->clientRight = new Right();
$this->clientRight->setLayer(LayerType::SOURCE);
$this->clientRight->setType(CRUDType::READ);
$this->clientRight->setReciever($this->clientSource);
$this->clientRight->setSource($this->source);
}
private function getClonedClientRight(): RightInterface
{
return clone $this->clientRight;
}
public function testInitialValues(): void
{
$this->assertFalse($this->checkClientPermission());
$this->assertTrue($this->clientRight->getGrant());
}
public function testGeneralPermission(): void
{
$this->law->getRights()->add($this->getClonedClientRight());
$this->assertTrue($this->checkClientPermission());
$this->clientRight->setType(CRUDType::UPDATE);
$this->assertFalse($this->checkClientPermission());
}
public function testChildMemberPermission(): void
{
$parentSource = new PureSource();
$parentSource->setSlug('Parent Source');
$parentSourceMemberManager = new SourceMemberManager($parentSource);
$parentSourceMemberManager->addMember($this->clientSource);
/*
* The following asserts just check if the SourceMemberManager works like expected
*/
$this->assertEquals($parentSource, $this->clientSource->getMemberRelation()->getMemberships()->get(0)->getSource());
$this->assertEquals($this->clientSource, $parentSource->getMemberRelation()->getMembers()->get(0)->getSource());
$parentSourceRight = $this->getClonedClientRight();
$parentSourceRight->setReciever($parentSource);
$this->law->getRights()->add($parentSourceRight);
/*
* The following asserts just check if the in the tet defined values are like expected
*/
$this->assertEquals($parentSourceRight, $this->law->getRights()->get(0));
$this->assertEquals($parentSource, $parentSourceRight->getReciever());
$this->assertEquals($this->source, $parentSourceRight->getSource());
/*
* The following asserts are the important asserts for the test
*/
$this->assertTrue($this->checkClientPermission());
$this->law->setRights(new ArrayCollection());
$this->assertFalse($this->checkClientPermission());
}
public function testGetRightsByType(): void
{
$right = $this->getClonedClientRight();
$right->setType(CRUDType::UPDATE);
$this->law->getRights()->add($right);
$this->assertFalse($this->checkClientPermission());
$right->setType(CRUDType::READ);
$this->assertTrue($this->checkClientPermission());
}
public function testGetRightsByLayer(): void
{
$right = $this->getClonedClientRight();
$right->setLayer(LayerType::LAW);
$this->law->getRights()->add($right);
$this->assertFalse($this->checkClientPermission());
$right->setLayer(LayerType::SOURCE);
$this->assertTrue($this->checkClientPermission());
}
public function testSortByPriority(): void
{
$right1 = $this->getClonedClientRight();
$right1->setPriority(123);
$right1->setGrant(false);
$right1->setReciever($this->clientSource);
$right2 = $this->getClonedClientRight();
$right2->setPriority(456);
$right2->setGrant(true);
$right2->setReciever($this->clientSource);
$this->law->setRights(new ArrayCollection([
$right1,
$right2,
]));
$this->assertFalse($this->checkClientPermission());
$right2->setPriority(789);
$right1->setPriority(101112);
$this->assertTrue($this->checkClientPermission());
}
public function testMemberFilter(): void
{
$right1 = $this->getClonedClientRight();
$right1->setPriority(123);
$right1->setGrant(false);
$right1->setReciever(new PureSource());
$right1->getReciever()->setSlug('Rigth1 Reciever');
$right2 = $this->getClonedClientRight();
$right2->setPriority(456);
$right2->setGrant(true);
$right2->setReciever($this->clientSource);
$this->law->setRights(new ArrayCollection([
$right1,
$right2,
]));
$this->assertTrue($this->checkClientPermission());
}
public function testGrant(): void
{
$this->assertFalse($this->checkClientPermission());
$this->law->setGrant(true);
$this->assertTrue($this->checkClientPermission());
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace Tests\Unit\Domain\MemberManagement;
use PHPUnit\Framework\TestCase;
use App\Domain\MemberManagement\MemberManagerInterface;
use App\Entity\Meta\Relation\Member\MemberRelationInterface;
use App\Entity\Meta\Relation\Member\MemberRelation;
use App\Domain\MemberManagement\MemberManager;
class MemberManagerTest extends TestCase
{
/**
* @var MemberRelationInterface
*/
private $memberRelation;
/**
* @var MemberManagerInterface
*/
private $MemberManager;
public function setUp(): void
{
$this->memberRelation = new MemberRelation();
$this->MemberManager = new MemberManager($this->memberRelation);
}
public function testAddAndRemoveMember(): void
{
$member = new MemberRelation();
$this->assertNull($this->MemberManager->addMember($member));
$this->assertEquals($member, $this->memberRelation->getMembers()->get(0));
$this->assertEquals($this->memberRelation, $member->getMemberships()->get(0));
$this->assertNull($this->MemberManager->removeMember($member));
$this->assertEquals(0, $this->memberRelation->getMembers()->count());
$this->assertEquals(0, $member->getMemberships()->count());
}
public function testAddAndRemoveMembership(): void
{
$membership = new MemberRelation();
$this->assertNull($this->MemberManager->addMembership($membership));
$this->assertEquals($membership, $this->memberRelation->getMemberships()->get(0));
$this->assertEquals($this->memberRelation, $membership->getMembers()->get(0));
$this->assertNull($this->MemberManager->removeMembership($membership));
$this->assertEquals(0, $this->memberRelation->getMemberships()->count());
$this->assertEquals(0, $membership->getMembers()->count());
}
}

View File

@@ -0,0 +1,75 @@
<?php
namespace Unit\Domain\ResponseManagement;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Meta\RightInterface;
use App\Entity\Meta\Right;
use FOS\RestBundle\View\ViewHandlerInterface;
use App\Entity\Source\PureSource;
use App\DBAL\Types\SystemSlugType;
use App\DBAL\Types\Meta\Right\LayerType;
use App\DBAL\Types\Meta\Right\CRUDType;
use App\Domain\ResponseManagement\SourceRESTResponseManager;
use App\Exception\AllreadyDefinedException;
/**
* @author kevinfrantz
*
* @todo Implement more tests!
*/
class SourceRESTReponseManagerTest extends KernelTestCase
{
/**
* @var EntityManagerInterface
*/
private $entityManager;
/**
* @var RightInterface
*/
private $requestedRight;
/**
* @var ViewHandlerInterface
*/
private $viewHandler;
private function setRequestedRight(): void
{
$this->requestedRight = new Right();
}
private function setEntityManager(): void
{
$this->entityManager = self::$container->get('doctrine.orm.default_entity_manager');
}
private function setViewHandler(): void
{
$this->viewHandler = $this->createMock(ViewHandlerInterface::class);
}
public function setUp(): void
{
self::bootKernel();
$this->setEntityManager();
$this->setRequestedRight();
$this->setViewHandler();
}
public function testAllreadyDefinedException(): void
{
$requestedSource = new PureSource();
$requestedSource->setSlug(SystemSlugType::IMPRINT);
$requestedRight = new Right();
$requestedRight->setSource($requestedSource);
$requestedRight->setReciever(new PureSource());
$requestedRight->setLayer(LayerType::SOURCE);
$requestedRight->setType(CRUDType::READ);
$this->expectException(AllreadyDefinedException::class);
$sourceResponseManager = new SourceRESTResponseManager(null, $this->entityManager, $requestedRight, $this->viewHandler);
$sourceResponseManager->getResponse();
}
}

View File

@@ -0,0 +1,100 @@
<?php
namespace Tests\Unit\Domain\RightManagement;
use PHPUnit\Framework\TestCase;
use App\Entity\Meta\RightInterface;
use App\Entity\Meta\Right;
use App\Entity\Source\SourceInterface;
use App\DBAL\Types\Meta\Right\LayerType;
use App\Domain\RightManagement\RightCheckerInterface;
use App\Domain\RightManagement\RightChecker;
use App\DBAL\Types\Meta\Right\CRUDType;
use App\Entity\Source\PureSource;
class RightCheckerTest extends TestCase
{
/**
* @var string
*/
private $type;
/**
* @var string
*/
private $layer;
/**
* @var SourceInterface
*/
private $source;
/**
* @var RightInterface
*/
private $right;
/**
* @var RightCheckerInterface
*/
private $rightManager;
public function setUp(): void
{
$this->layer = LayerType::MEMBER;
$this->type = CRUDType::READ;
$this->source = new PureSource();
$this->right = new Right();
$this->right->setReciever($this->source);
$this->right->setType($this->type);
$this->right->setLayer($this->layer);
$this->rightManager = new RightChecker($this->right);
}
public function testFirstDimension(): void
{
$granted = $this->rightManager->isGranted($this->layer, $this->type, $this->source);
$this->assertTrue($granted);
$notGranted = $this->rightManager->isGranted(LayerType::SOURCE, $this->type, $this->source);
$this->assertFalse($notGranted);
$notGranted2 = $this->rightManager->isGranted($this->layer, CRUDType::UPDATE, $this->source);
$this->assertFalse($notGranted2);
$this->right->setGrant(false);
$notGranted3 = $this->rightManager->isGranted($this->layer, $this->type, $this->source);
$this->assertFalse($notGranted3);
$notGranted4 = $this->rightManager->isGranted($this->layer, $this->type, new PureSource());
$this->assertFalse($notGranted4);
}
public function testSecondDimension(): void
{
$secondSource = new PureSource();
$this->source->getMemberRelation()->getMembers()->add($secondSource->getMemberRelation());
$granted = $this->rightManager->isGranted($this->layer, $this->type, $secondSource);
$this->assertTrue($granted);
$notGranted = $this->rightManager->isGranted(LayerType::SOURCE, $this->type, $secondSource);
$this->assertFalse($notGranted);
$notGranted2 = $this->rightManager->isGranted($this->layer, CRUDType::UPDATE, $secondSource);
$this->assertFalse($notGranted2);
$this->right->setGrant(false);
$notGranted3 = $this->rightManager->isGranted($this->layer, $this->type, $secondSource);
$this->assertFalse($notGranted3);
}
public function testThirdDimension(): void
{
$thirdSource = new PureSource();
$secondSource = new PureSource();
$secondSource->getMemberRelation()->getMembers()->add($thirdSource->getMemberRelation());
$this->source->getMemberRelation()->getMembers()->add($secondSource->getMemberRelation());
$granted = $this->rightManager->isGranted($this->layer, $this->type, $thirdSource);
$this->assertTrue($granted);
$notGranted = $this->rightManager->isGranted(LayerType::SOURCE, $this->type, $thirdSource);
$this->assertFalse($notGranted);
$notGranted2 = $this->rightManager->isGranted($this->layer, CRUDType::UPDATE, $thirdSource);
$this->assertFalse($notGranted2);
$this->right->setGrant(false);
$notGranted3 = $this->rightManager->isGranted($this->layer, $this->type, $thirdSource);
$this->assertFalse($notGranted3);
}
}

View File

@@ -0,0 +1,74 @@
<?php
namespace Tests\Unit\Domain\SecureLoadManagement;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Doctrine\Common\Persistence\ObjectRepository;
use App\Entity\Source\AbstractSource;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use App\Domain\SecureLoadManagement\SecureSourceLoader;
use App\Entity\Source\Primitive\Text\TextSource;
use App\DBAL\Types\SystemSlugType;
use App\Entity\Meta\Right;
use App\DBAL\Types\Meta\Right\LayerType;
use App\DBAL\Types\Meta\Right\CRUDType;
use App\Entity\Source\Complex\UserSource;
use App\Entity\Source\Primitive\Text\TextSourceInterface;
use Doctrine\ORM\EntityManagerInterface;
/**
* @author kevinfrantz
*
* @todo Implement more tests
*/
class SecureSourceLoaderTest extends KernelTestCase
{
/**
* @var ObjectRepository
*/
private $sourceRepository;
/**
* @var EntityManagerInterface
*/
private $entityManager;
public function setUp(): void
{
self::bootKernel();
$this->entityManager = self::$container->get('doctrine.orm.default_entity_manager');
$this->setSourceRepository();
}
private function setSourceRepository(): void
{
$this->sourceRepository = $this->entityManager->getRepository(AbstractSource::class);
}
public function testAccessDeniedException(): void
{
$requestedSource = new TextSource();
$requestedSource->setSlug(SystemSlugType::IMPRINT);
$requestedRight = new Right();
$requestedRight->setSource($requestedSource);
$requestedRight->setLayer(LayerType::SOURCE);
$requestedRight->setType(CRUDType::READ);
$requestedRight->setReciever(new UserSource());
$secureSourceLoader = new SecureSourceLoader($this->entityManager, $requestedRight);
$this->expectException(AccessDeniedHttpException::class);
$secureSourceLoader->getSource();
}
public function testGranted(): void
{
$requestedSource = new TextSource();
$requestedSource->setSlug(SystemSlugType::IMPRINT);
$requestedRight = new Right();
$requestedRight->setSource($requestedSource);
$requestedRight->setLayer(LayerType::SOURCE);
$requestedRight->setType(CRUDType::READ);
$requestedRight->setReciever($this->sourceRepository->findOneBySlug(SystemSlugType::GUEST_USER));
$secureSourceLoader = new SecureSourceLoader($this->entityManager, $requestedRight);
$this->assertInstanceOf(TextSourceInterface::class, $secureSourceLoader->getSource());
}
}

View File

@@ -0,0 +1,105 @@
<?php
namespace Tests\Unit\Domain\SecureSourceManagement;
use PHPUnit\Framework\TestCase;
use App\Entity\Source\SourceInterface;
use App\Domain\SecureManagement\SecureSourceCheckerInterface;
use App\Entity\Source\AbstractSource;
use App\Domain\SecureManagement\SecureSourceChecker;
use App\Entity\Meta\Right;
use App\DBAL\Types\Meta\Right\LayerType;
use App\DBAL\Types\Meta\Right\CRUDType;
use App\Entity\Attribut\SourceAttribut;
use App\Entity\Attribut\SourceAttributInterface;
use App\Exception\SourceAccessDenied;
/**
* @author kevinfrantz
*/
class SecureSourceCheckerTest extends TestCase
{
/**
* @var SourceInterface|SourceAttributInterface
*/
private $source;
/**
* @var SourceInterface
*/
private $recieverSource;
/**
* @var SecureSourceCheckerInterface
*/
private $securerSourceChecker;
private function createSourceMock(): SourceInterface
{
return new class() extends AbstractSource implements SourceAttributInterface {
use SourceAttribut;
};
}
public function setUp(): void
{
$this->source = $this->createSourceMock();
$this->recieverSource = $this->createSourceMock();
$this->securerSourceChecker = new SecureSourceChecker($this->source);
}
public function testFirstLevel(): void
{
$right = new Right();
$right->setLayer(LayerType::SOURCE);
$right->setType(CRUDType::UPDATE);
$right->setReciever($this->recieverSource);
$right->setSource($this->source);
$this->source->getLaw()->getRights()->add($right);
$requestedRight = clone $right;
$this->assertTrue($this->securerSourceChecker->hasPermission($requestedRight));
$requestedRight->setType(CRUDType::READ);
$this->assertFalse($this->securerSourceChecker->hasPermission($requestedRight));
}
public function testSecondLevel(): void
{
$right = new Right();
$right->setLayer(LayerType::SOURCE);
$right->setType(CRUDType::UPDATE);
$right->setReciever($this->recieverSource);
$right->setSource($this->source);
$this->source->getLaw()->getRights()->add($right);
$attributSource = $this->createSourceMock();
$childRight = clone $right;
$attributSource->getLaw()->getRights()->add($childRight);
$this->source->setSource($attributSource);
$requestedRight = clone $right;
$this->assertTrue($this->securerSourceChecker->hasPermission($requestedRight));
$childRight->setType(CRUDType::READ);
$this->expectException(SourceAccessDenied::class);
$this->securerSourceChecker->hasPermission($requestedRight);
}
public function testThirdLevel(): void
{
$right = new Right();
$right->setLayer(LayerType::SOURCE);
$right->setType(CRUDType::UPDATE);
$right->setReciever($this->recieverSource);
$right->setSource($this->source);
$this->source->getLaw()->getRights()->add($right);
$attribut1Source = $this->createSourceMock();
$attribut1Source->getLaw()->getRights()->add($right);
$this->source->setSource($attribut1Source);
$childRight = clone $right;
$attribut2Source = $this->createSourceMock();
$attribut2Source->getLaw()->getRights()->add($childRight);
$attribut1Source->setSource($attribut2Source);
$requestedRight = clone $right;
$this->assertTrue($this->securerSourceChecker->hasPermission($requestedRight));
$childRight->setType(CRUDType::READ);
$this->expectException(SourceAccessDenied::class);
$this->securerSourceChecker->hasPermission($requestedRight);
}
}

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());
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace Tests\Unit\Domain\TemplateManagement;
use PHPUnit\Framework\TestCase;
use App\Domain\TemplateManagement\TemplateMetaInterface;
use App\Entity\Source\Primitive\Name\FirstNameSource;
use App\Entity\Source\SourceInterface;
use App\Domain\TemplateManagement\TemplateMeta;
use App\Domain\SourceManagement\SourceMeta;
class TemplateMetaTest extends TestCase
{
/**
* @var TemplateMetaInterface
*/
protected $templateMeta;
/**
* @var SourceInterface
*/
protected $source;
private function getExpectedPath(string $type, string $context): string
{
return $context.'/entity/source/primitive/name/firstname.'.$type.'.twig';
}
public function setUp(): void
{
$this->source = new FirstNameSource();
$sourceMeta = new SourceMeta($this->source);
$this->templateMeta = new TemplateMeta($sourceMeta->getBasicPathArray(), $sourceMeta->getBasicName(), 'entity');
}
public function testFrameTemplatePath(): void
{
$this->assertEquals($this->getExpectedPath('html', 'frame'), $this->templateMeta->getFrameTemplatePath());
}
public function testContentTemplatePath(): void
{
$this->assertEquals($this->getExpectedPath('html', 'content'), $this->templateMeta->getContentTemplatePath());
}
public function testSetType(): void
{
$this->templateMeta->setTemplateType('json');
$this->assertEquals($this->getExpectedPath('json', 'content'), $this->templateMeta->getContentTemplatePath());
$this->assertEquals($this->getExpectedPath('json', 'frame'), $this->templateMeta->getFrameTemplatePath());
$this->assertEquals('json', $this->templateMeta->getTemplateType());
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace Tests\Unit\Domain\UserManagement;
use App\Domain\UserManagement\UserIdentityManager;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use App\DBAL\Types\SystemSlugType;
use App\Entity\User;
class UserIdentityManagerTest extends KernelTestCase
{
/**
* @var EntityManagerInterface
*/
private $entityManager;
public function setUp(): void
{
self::bootKernel();
$this->entityManager = self::$container->get('doctrine.orm.default_entity_manager');
}
public function testGuestUser(): void
{
$origineUser = null;
$userIdentityManager = new UserIdentityManager($this->entityManager, $origineUser);
$expectedUser = $userIdentityManager->getUser();
$this->assertEquals(SystemSlugType::GUEST_USER, $expectedUser->getSource()->getSlug());
}
public function testUser(): void
{
$origineUser = new User();
$userIdentityManager = new UserIdentityManager($this->entityManager, $origineUser);
$expectedUser = $userIdentityManager->getUser();
$this->assertEquals($origineUser, $expectedUser);
}
}

View File

@@ -0,0 +1,47 @@
<?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->assertEquals(0, $this->entity->getVersion());
$this->expectException(\TypeError::class);
$this->entity->getId();
}
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());
}
public function testToString(): void
{
$this->assertEquals(true, is_string($this->entity->__toString()));
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\ChildsAttributeInterface;
use App\Entity\Attribut\ChildsAttribut;
use Doctrine\Common\Collections\ArrayCollection;
class ChildsAttributTest extends TestCase
{
/**
* @var ChildsAttributeInterface
*/
protected $childs;
public function setUp(): void
{
$this->childs = new class() implements ChildsAttributeInterface {
use ChildsAttribut;
};
}
public function testConstructor(): void
{
$this->expectException(\TypeError::class);
$this->childs->getChilds();
}
public function testAccessors(): void
{
$childs = new ArrayCollection();
$this->assertNull($this->childs->setChilds($childs));
$this->assertEquals($childs, $this->childs->getChilds());
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace Tests\Unit\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\CollectionAttributInterface;
use App\Entity\Attribut\CollectionAttribut;
use Doctrine\Common\Collections\ArrayCollection;
class CollectionAttributTest extends TestCase
{
/**
* @var CollectionAttributInterface
*/
protected $collection;
public function setUp(): void
{
$this->collection = new class() implements CollectionAttributInterface {
use CollectionAttribut;
};
}
public function testConstructor(): void
{
$this->expectException(\TypeError::class);
$this->collection->getCollection();
}
public function testAccessors(): void
{
$collection = new ArrayCollection();
$this->assertNull($this->collection->setCollection($collection));
$this->assertEquals($collection, $this->collection->getCollection());
}
public function testAdd(): void
{
$mock = new class() {
};
$this->collection->setCollection(new ArrayCollection());
$this->assertTrue($this->collection->getCollection()->add($mock));
$this->assertEquals($mock, $this->collection->getCollection()->get(0));
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\ConditionAttributInterface;
use App\Entity\Attribut\ConditionAttribut;
use App\Logic\Operation\OperationInterface;
class ConditionAttributTest extends TestCase
{
/**
* @var ConditionAttributInterface
*/
protected $condition;
public function setUp(): void
{
$this->condition = new class() implements ConditionAttributInterface {
use ConditionAttribut;
};
}
public function testConstructor(): void
{
$this->expectException(\TypeError::class);
$this->condition->getCondition();
}
public function testAccessors(): void
{
$this->assertEquals(false, $this->condition->hasCondition());
$condition = $this->createMock(OperationInterface::class);
$this->assertNull($this->condition->setCondition($condition));
$this->assertEquals(true, $this->condition->hasCondition());
$this->assertEquals($condition, $this->condition->getCondition());
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Tests\Unit\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\CreatorRelationAttributInterface;
use App\Entity\Attribut\CreatorRelationAttribut;
use App\Entity\Meta\Relation\Parent\CreatorRelationInterface;
class CreatorRelationAttributTest extends TestCase
{
/***
* @var CreatorRelationAttributInterface
*/
protected $creatorRelationAttribut;
public function setUp(): void
{
$this->creatorRelationAttribut = new class() implements CreatorRelationAttributInterface {
use CreatorRelationAttribut;
};
}
public function testAccessors(): void
{
$relation = $this->createMock(CreatorRelationInterface::class);
$this->assertNull($this->creatorRelationAttribut->setCreatorRelation($relation));
$this->assertEquals($relation, $this->creatorRelationAttribut->getCreatorRelation());
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace Tests\Unit\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\FirstNameSourceAttribut;
use App\Entity\Attribut\FirstNameSourceAttributInterface;
use App\Entity\Source\Primitive\Name\FirstNameSourceInterface;
/**
* @author kevinfrantz
*/
class FirstNameSourceAttributTest extends TestCase
{
/**
* @var FirstNameSourceAttributInterface
*/
protected $name;
public function setUp(): void
{
$this->name = new class() implements FirstNameSourceAttributInterface {
use FirstNameSourceAttribut;
};
}
public function testConstructor(): void
{
$this->expectException(\TypeError::class);
$this->name->getFirstNameSource();
}
public function testAccessors(): void
{
$name = $this->createMock(FirstNameSourceInterface::class);
$this->assertNull($this->name->setFirstNameSource($name));
$this->assertEquals($name, $this->name->getFirstNameSource());
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace Tests\Unit\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Source\Complex\FullPersonNameSourceInterface;
use App\Entity\Attribut\FullPersonNameSourceAttributInterface;
use App\Entity\Attribut\FullPersonNameSourceAttribut;
/**
* @author kevinfrantz
*/
class FullPersonNameSourceAttributTest extends TestCase
{
/**
* @var FullPersonNameSourceAttributInterface
*/
protected $fullname;
public function setUp(): void
{
$this->fullname = new class() implements FullPersonNameSourceAttributInterface {
use FullPersonNameSourceAttribut;
};
}
public function testConstructor(): void
{
$this->expectException(\TypeError::class);
$this->fullname->getFullPersonNameSource();
}
public function testAccessors(): void
{
$fullname = $this->createMock(FullPersonNameSourceInterface::class);
$this->assertNull($this->fullname->setFullPersonNameSource($fullname));
$this->assertEquals($fullname, $this->fullname->getFullPersonNameSource());
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace Tests\Unit\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\GrantAttribut;
use App\Entity\Attribut\GrantAttributInterface;
class GrantAttributTest extends TestCase
{
/**
* @var GrantAttributInterface
*/
protected $grant;
public function setUp(): void
{
$this->grant = new class() implements GrantAttributInterface {
use GrantAttribut;
};
}
public function testConstruct(): void
{
$this->expectException(\TypeError::class);
$this->grant->getGrant();
}
public function testAccessors(): void
{
$grant = true;
$this->assertNull($this->grant->setGrant($grant));
$this->assertEquals($grant, $this->grant->getGrant());
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace Tests\Unit\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\IdAttribut;
use App\Entity\Attribut\IdAttributInterface;
class IdAttributTest extends TestCase
{
/**
* @var IdAttributInterface
*/
protected $id;
public function setUp(): void
{
$this->id = new class() implements IdAttributInterface {
use IdAttribut;
};
}
public function testConstruct(): void
{
$this->expectException(\TypeError::class);
$this->id->getId();
}
public function testAccessors(): void
{
$id = 1234;
$this->assertNull($this->id->setId($id));
$this->assertEquals($id, $this->id->getId());
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Tests\Unit\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\LayerAttributInterface;
use App\Entity\Attribut\LayerAttribut;
use App\DBAL\Types\Meta\Right\LayerType;
class LayerAttributTest extends TestCase
{
/**
* @var LayerAttributInterface
*/
protected $layer;
public function setUp(): void
{
$this->layer = new class() implements LayerAttributInterface {
use LayerAttribut;
};
}
public function testConstruct(): void
{
$this->expectException(\TypeError::class);
$this->layer->getLayer();
}
public function testAccessors(): void
{
foreach (LayerType::getChoices() as $value) {
$this->assertNull($this->layer->setLayer($value));
$this->assertEquals($value, $this->layer->getLayer());
}
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace Tests\Unit\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\MemberRelationAttributInterface;
use App\Entity\Attribut\MemberRelationAttribut;
use App\Entity\Meta\Relation\Member\MemberRelationInterface;
class MemberRelationAttributTest extends TestCase
{
/**
* @var MemberRelationAttributInterface
*/
protected $memberRelation;
public function setUp(): void
{
$this->memberRelation = new class() implements MemberRelationAttributInterface {
use MemberRelationAttribut;
};
}
public function testConstructor(): void
{
$this->expectException(\TypeError::class);
$this->memberRelation->getMemberRelation();
}
public function testAccessors(): void
{
$membership = $this->createMock(MemberRelationInterface::class);
$this->assertNull($this->memberRelation->setMemberRelation($membership));
$this->assertEquals($this->memberRelation->getMemberRelation(), $membership);
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Tests\Unit\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Attribut\MembersAttributInterface;
use App\Entity\Source\SourceInterface;
use App\Entity\Attribut\MembersAttribut;
class MembersAttributTest extends TestCase
{
/**
* @var MembersAttributInterface
*/
protected $members;
public function setUp(): void
{
$this->members = new class() implements MembersAttributInterface {
use MembersAttribut;
};
}
public function testConstructor(): void
{
$this->expectException(\TypeError::class);
$this->members->getMembers();
}
public function testAccessors(): void
{
$membership = $this->createMock(SourceInterface::class);
$this->assertNull($this->members->setMembers(new ArrayCollection([$membership])));
$this->assertEquals($this->members->getMembers()->get(0), $membership);
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Tests\Unit\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\MembershipsAttributInterface;
use App\Entity\Attribut\MembershipsAttribut;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Source\Complex\Collection\TreeCollectionSourceInterface;
class MembershipsAttributTest extends TestCase
{
/**
* @var MembershipsAttributInterface
*/
protected $memberships;
public function setUp(): void
{
$this->memberships = new class() implements MembershipsAttributInterface {
use MembershipsAttribut;
};
}
public function testConstructor(): void
{
$this->expectException(\TypeError::class);
$this->memberships->getMemberships();
}
public function testAccessors(): void
{
$membership = $this->createMock(TreeCollectionSourceInterface::class);
$this->assertNull($this->memberships->setMemberships(new ArrayCollection([$membership])));
$this->assertEquals($this->memberships->getMemberships()->get(0), $membership);
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace App\Entity\Attribut;
use PHPUnit\Framework\TestCase;
class NameAttributTest extends TestCase
{
/**
* @var NameAttributInterface
*/
public $name;
public function setUp(): void
{
$this->name = new class() implements NameAttributInterface {
use NameAttribut;
};
}
public function testConstructor(): void
{
$this->expectException(\TypeError::class);
$this->name->getName();
}
public function testAccessors(): void
{
$name = 'hello world!';
$this->assertNull($this->name->setName($name));
$this->assertEquals($name, $this->name->getName());
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace tests\unit\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\NameSourceAttributInterface;
use App\Entity\Attribut\NameSourceAttribut;
use App\Entity\Source\Primitive\Name\NameSourceInterface;
class NameSourceAttributTest extends TestCase
{
/**
* @var NameSourceAttributInterface
*/
protected $name;
public function setUp(): void
{
$this->name = new class() implements NameSourceAttributInterface {
use NameSourceAttribut;
};
}
public function testConstructor(): void
{
$this->expectException(\TypeError::class);
$this->name->getNameSource();
}
public function testAccessors(): void
{
$nameSource = $this->createMock(NameSourceInterface::class);
$this->assertNull($this->name->setNameSource($nameSource));
$this->assertEquals($nameSource, $this->name->getNameSource());
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Tests\Unit\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\ParentRelationAttributInterface;
use App\Entity\Attribut\ParentRelationAttribut;
use App\Entity\Meta\Relation\Parent\ParentRelationInterface;
class ParentRelationAttributTest extends TestCase
{
/***
* @var ParentRelationAttributInterface
*/
protected $parentRelationAttribut;
public function setUp(): void
{
$this->parentRelationAttribut = new class() implements ParentRelationAttributInterface {
use ParentRelationAttribut;
};
}
public function testAccessors(): void
{
$relation = $this->createMock(ParentRelationInterface::class);
$this->assertNull($this->parentRelationAttribut->setParentRelation($relation));
$this->assertEquals($relation, $this->parentRelationAttribut->getParentRelation());
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\ParentsAttributInterface;
use App\Entity\Attribut\ParentsAttribut;
use Doctrine\Common\Collections\ArrayCollection;
class ParentsAttributTest extends TestCase
{
/**
* @var ParentsAttributInterface
*/
protected $parents;
public function setUp(): void
{
$this->parents = new class() implements ParentsAttributInterface {
use ParentsAttribut;
};
}
public function testConstructor(): void
{
$this->expectException(\TypeError::class);
$this->parents->getParents();
}
public function testAccessors(): void
{
$parents = new ArrayCollection();
$this->assertNull($this->parents->setParents($parents));
$this->assertEquals($parents, $this->parents->getParents());
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Tests\Unit\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\PersonIdentitySourceAttributInterface;
use App\Entity\Attribut\PersonIdentitySourceAttribut;
use App\Entity\Source\Complex\PersonIdentitySourceInterface;
/**
* @todo Implement abstract test class for entity attributs
*
* @author kevinfrantz
*/
class PersonIdentitySourceAttributTest extends TestCase
{
/**
* @var PersonIdentitySourceAttributInterface
*/
protected $identity;
public function setUp(): void
{
$this->identity = new class() implements PersonIdentitySourceAttributInterface {
use PersonIdentitySourceAttribut;
};
}
public function testConstructor(): void
{
$this->expectException(\TypeError::class);
$this->identity->getPersonIdentitySource();
}
public function testAccessors(): void
{
$identity = $this->createMock(PersonIdentitySourceInterface::class);
$this->assertNull($this->identity->setPersonIdentitySource($identity));
$this->assertEquals($identity, $this->identity->getPersonIdentitySource());
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Tests\Unit\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\PriorityAttributInterface;
use App\Entity\Attribut\PriorityAttribut;
/**
* @author kevinfrantz
*/
class PriorityAttributTest extends TestCase
{
/**
* @var PriorityAttributInterface
*/
protected $priorityAttribut;
public function setUp(): void
{
$this->priorityAttribut = new class() implements PriorityAttributInterface {
use PriorityAttribut;
};
}
public function testConstructor(): void
{
$this->expectException(\TypeError::class);
$this->priorityAttribut->getPriority();
}
public function testAccessors(): void
{
$priority = 123;
$this->assertNull($this->priorityAttribut->setPriority($priority));
$this->assertEquals($priority, $this->priorityAttribut->getPriority());
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace Tests\Unit\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\RecieverAttributInterface;
use App\Entity\Attribut\RecieverAttribut;
use App\Entity\Source\AbstractSource;
class RecieverAttributTest extends TestCase
{
/**
* @var RecieverAttributInterface
*/
protected $reciever;
public function setUp(): void
{
$this->reciever = new class() implements RecieverAttributInterface {
use RecieverAttribut;
};
}
public function testConstructor(): void
{
$this->expectException(\TypeError::class);
$this->reciever->getReciever();
}
public function testAccessors(): void
{
$reciever = $this->createMock(AbstractSource::class);
$this->assertNull($this->reciever->setReciever($reciever));
$this->assertEquals($reciever, $this->reciever->getReciever());
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Tests\Unit\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Meta\Relation\RelationInterface;
use App\Entity\Attribut\RelationAttributInterface;
use App\Entity\Attribut\RelationAttribut;
class RelationAttributTest extends TestCase
{
/***
* @var RelationAttributInterface
*/
protected $relationAttribut;
public function setUp(): void
{
$this->relationAttribut = new class() implements RelationAttributInterface {
use RelationAttribut;
};
}
public function testAccessors(): void
{
$relation = $this->createMock(RelationInterface::class);
$this->assertNull($this->relationAttribut->setRelation($relation));
$this->assertEquals($relation, $this->relationAttribut->getRelation());
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Tests\Unit\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\RightAttributInterface;
use App\Entity\Attribut\RightAttribut;
use App\Entity\Meta\RightInterface;
class RightAttributTest extends TestCase
{
/***
* @var RightAttributInterface
*/
private $rightAttribut;
public function setUp(): void
{
$this->rightAttribut = new class() implements RightAttributInterface {
use RightAttribut;
};
}
public function testAccessors(): void
{
$right = $this->createMock(RightInterface::class);
$this->assertNull($this->rightAttribut->setRight($right));
$this->assertEquals($right, $this->rightAttribut->getRight());
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Tests\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\SlugAttributInterface;
use App\Entity\Attribut\SlugAttribut;
/**
* @author kevinfrantz
*/
class SlugAttributTest extends TestCase
{
/**
* @var SlugAttributInterface
*/
protected $slugAttribut;
public function setUp(): void
{
$this->slugAttribut = new class() implements SlugAttributInterface {
use SlugAttribut;
};
}
public function testConstructor(): void
{
$this->expectException(\TypeError::class);
$this->slugAttribut->getSlug();
}
public function testAccessors(): void
{
$slug = 'goodslug';
$this->assertNull($this->slugAttribut->setSlug($slug));
$this->assertEquals($slug, $this->slugAttribut->getSlug());
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Tests\Unit\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\TextAttributInterface;
use App\Entity\Attribut\TextAttribut;
/**
* @author kevinfrantz
*/
class TextAttributTest extends TestCase
{
/**
* @var TextAttributInterface
*/
protected $textAttribut;
public function setUp(): void
{
$this->textAttribut = new class() implements TextAttributInterface {
use TextAttribut;
};
}
public function testConstructor(): void
{
$this->expectException(\TypeError::class);
$this->textAttribut->getText();
}
public function testAccessors(): void
{
$text = 'Hello World!';
$this->assertNull($this->textAttribut->setText($text));
$this->assertEquals($text, $this->textAttribut->getText());
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Tests\Unit\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\TypeAttributInterface;
use App\Entity\Attribut\TypeAttribut;
/**
* @author kevinfrantz
*/
class TypeAttributTest extends TestCase
{
/**
* @var TypeAttributInterface
*/
protected $typeAttribut;
public function setUp(): void
{
$this->typeAttribut = new class() implements TypeAttributInterface {
use TypeAttribut;
};
}
public function testConstructor(): void
{
$this->expectException(\TypeError::class);
$this->typeAttribut->getType();
}
public function testAccessors(): void
{
$type = 'Hello World!';
$this->assertNull($this->typeAttribut->setType($type));
$this->assertEquals($type, $this->typeAttribut->getType());
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace Tests\Unit\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\UserAttributInterface;
use App\Entity\Attribut\UserAttribut;
use App\Entity\UserInterface;
class UserAttributTest extends TestCase
{
/**
* @var UserAttributInterface
*/
public $user;
public function setUp(): void
{
$this->user = new class() implements UserAttributInterface {
use UserAttribut;
};
}
public function testConstructor(): void
{
$this->expectException(\TypeError::class);
$this->user->getUser();
}
public function testAccessors(): void
{
$user = $this->createMock(UserInterface::class);
$this->assertNull($this->user->setUser($user));
$this->assertEquals($user, $this->user->getUser());
}
}

View File

@@ -0,0 +1,37 @@
<?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->assertFalse($this->law->getGrant());
$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));
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace Tests\Unit\Entity\Meta\Relation\Member;
use PHPUnit\Framework\TestCase;
use App\Entity\Meta\Relation\Member\MemberRelation;
use App\Entity\Meta\Relation\Member\MemberRelationInterface;
use Doctrine\Common\Collections\Collection;
class MemberRelationTest extends TestCase
{
/**
* @var MemberRelationInterface
*/
private $memberRelation;
public function setUp(): void
{
$this->memberRelation = new MemberRelation();
}
public function testConstructor(): void
{
$this->assertInstanceOf(Collection::class, $this->memberRelation->getMembers());
$this->assertInstanceOf(Collection::class, $this->memberRelation->getMemberships());
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace tests\Unit\Entity\Meta;
use PHPUnit\Framework\TestCase;
use Doctrine\Common\Collections\Collection;
use App\Entity\Meta\Relation\Parent\AbstractParentRelation;
use App\Entity\Meta\Relation\Parent\ParentRelationInterface;
class AbstractParentRelationTest extends TestCase
{
/**
* @var ParentRelationInterface
*/
protected $relation;
public function setUp(): void
{
$this->relation = new class() extends AbstractParentRelation {
};
}
public function testConstructor(): void
{
$this->assertInstanceOf(Collection::class, $this->relation->getChilds());
$this->assertInstanceOf(Collection::class, $this->relation->getParents());
$this->assertEquals(0, $this->relation->getVersion());
$this->expectException(\TypeError::class);
$this->relation->getSource();
}
}

View File

@@ -0,0 +1,116 @@
<?php
namespace tests\unit\Entity;
use PHPUnit\Framework\TestCase;
use App\DBAL\Types\Meta\Right\CRUDType;
use App\Entity\Meta\RightInterface;
use App\Entity\Meta\Right;
use App\Entity\Meta\Law;
use App\DBAL\Types\Meta\Right\LayerType;
use App\Exception\NoValidChoiceException;
use App\Entity\Source\AbstractSource;
/**
* @todo Implement reciever test
*
* @author kevinfrantz
*/
class RightTest extends TestCase
{
/**
* @var RightInterface
*/
private $right;
public function setUp(): void
{
$this->right = new Right();
}
public function testConstructorGeneral(): void
{
$this->assertTrue($this->right->getGrant());
$this->assertEquals(0, $this->right->getPriority());
}
public function testConstructorReciever(): void
{
$this->expectException(\TypeError::class);
$this->right->getReciever();
}
public function testConstructorLayer(): void
{
$this->expectException(\TypeError::class);
$this->assertNull($this->right->getLayer());
}
public function testConstructorLaw(): void
{
$this->expectException(\TypeError::class);
$this->assertNull($this->right->getLaw());
}
public function testConstructorCondition(): void
{
$this->expectException(\TypeError::class);
$this->right->getCondition();
}
public function testConstructorType(): void
{
$this->expectException(\TypeError::class);
$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
{
foreach (CRUDType::getChoices() as $key => $value) {
$this->assertNull($this->right->setType($key));
$this->assertEquals($key, $this->right->getType());
}
$this->expectException(NoValidChoiceException::class);
$this->right->setType('NoneValidType');
}
public function testLayer(): void
{
foreach (LayerType::getChoices() as $key => $value) {
$this->assertNull($this->right->setLayer($key));
$this->assertEquals($key, $this->right->getLayer());
}
$this->expectException(NoValidChoiceException::class);
$this->right->setLayer('NoneValidLayer');
}
/**
* Just to test if the clone function works like assumed.
*/
public function testClone(): void
{
$source = $this->createMock(AbstractSource::class);
$reciever = $this->createMock(AbstractSource::class);
$grant = false;
$type = CRUDType::READ;
$layer = LayerType::SOURCE;
$this->right->setSource($source);
$this->right->setReciever($reciever);
$this->right->setGrant($grant);
$this->right->setType($type);
$this->right->setLayer($layer);
$rightClone = clone $this->right;
$this->assertEquals($source, $rightClone->getSource());
$this->assertEquals($reciever, $rightClone->getReciever());
$this->assertEquals($grant, $rightClone->getGrant());
$this->assertEquals($type, $rightClone->getType());
$this->assertEquals($layer, $rightClone->getLayer());
}
}

View File

@@ -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();
}
}

View File

@@ -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());
}
}

View File

@@ -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));
}
}

View File

@@ -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());
}
}

View File

@@ -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());
}
}

View File

@@ -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();
}
}

View File

@@ -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());
}
}

View File

@@ -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());
}
}

View File

@@ -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());
}
}

View File

@@ -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();
}
}

View File

@@ -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);
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace tests\unit\Entity;
use PHPUnit\Framework\TestCase;
use App\Entity\User;
use App\Entity\Source\Complex\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());
$this->assertEquals(0, $this->user->getVersion());
}
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());
$this->assertEquals($this->user, $this->user->getSource()->getUser());
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Event;
use PHPUnit\Framework\TestCase;
use App\Event\Menu\MenuEvent;
use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
use Symfony\Component\HttpFoundation\RequestStack;
class MenuEventTest extends TestCase
{
/**
* @var MenuEvent
*/
protected $menuEvent;
public function setUp(): void
{
$factory = $this->createMock(FactoryInterface::class);
$item = $this->createMock(ItemInterface::class);
$request = $this->createMock(RequestStack::class);
$this->menuEvent = new MenuEvent($factory, $item, $request);
}
public function testConstructor(): void
{
$this->assertInstanceOf(FactoryInterface::class, $this->menuEvent->getFactory());
$this->assertInstanceOf(ItemInterface::class, $this->menuEvent->getItem());
$this->assertInstanceOf(RequestStack::class, $this->menuEvent->getRequest());
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Tests\Unit\Form;
use PHPUnit\Framework\TestCase;
use App\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* This class just exists to keep the code coverage high.
*
* @todo Implement better tests!
*
* @author kevinfrantz
*/
class AbstractTypeTest extends TestCase
{
/**
* @var AbstractType
*/
protected $type;
public function setUp(): void
{
$this->type = new class() extends AbstractType {
};
}
public function testBuildForm(): void
{
$builder = $this->createMock(FormBuilderInterface::class);
$this->assertNull($this->type->buildForm($builder, []));
}
public function testConfigureOptions(): void
{
$resolver = $this->createMock(OptionsResolver::class);
$this->assertNull($this->type->configureOptions($resolver));
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Tests\Unit\Form;
use PHPUnit\Framework\TestCase;
use App\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use App\Form\NameSourceType;
/**
* This class just exists to keep the code coverage high.
*
* @todo Implement better tests!
*
* @author kevinfrantz
*/
class NameSourceTypeTest extends TestCase
{
/**
* @var AbstractType
*/
protected $type;
public function setUp(): void
{
$this->type = new NameSourceType();
}
public function testBuildForm(): void
{
$builder = $this->createMock(FormBuilderInterface::class);
$this->assertNull($this->type->buildForm($builder, []));
}
public function testConfigureOptions(): void
{
$resolver = $this->createMock(OptionsResolver::class);
$this->assertNull($this->type->configureOptions($resolver));
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Tests\Unit\Form;
use PHPUnit\Framework\TestCase;
use App\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use App\Form\UserSourceType;
/**
* This class just exists to keep the code coverage high.
*
* @todo Implement better tests!
*
* @author kevinfrantz
*/
class UserSourceTypeTest extends TestCase
{
/**
* @var AbstractType
*/
protected $type;
public function setUp(): void
{
$this->type = new UserSourceType();
}
public function testBuildForm(): void
{
$builder = $this->createMock(FormBuilderInterface::class);
$this->assertNull($this->type->buildForm($builder, []));
}
public function testConfigureOptions(): void
{
$resolver = $this->createMock(OptionsResolver::class);
$this->assertNull($this->type->configureOptions($resolver));
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace Tests\Unit\Form;
use PHPUnit\Framework\TestCase;
use App\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use App\Form\UserType;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\FormFactoryInterface;
/**
* This class just exists to keep the code coverage high.
*
* @todo Implement better tests!
*
* @author kevinfrantz
*/
class UserTypeTest extends TestCase
{
/**
* @var AbstractType
*/
protected $type;
public function setUp(): void
{
$this->type = new UserType();
}
public function testBuildForm(): void
{
$builder = new FormBuilder(null, null, $this->createMock(EventDispatcherInterface::class), $this->createMock(FormFactoryInterface::class));
$this->assertNull($this->type->buildForm($builder, []));
}
public function testConfigureOptions(): void
{
$resolver = $this->createMock(OptionsResolver::class);
$this->assertNull($this->type->configureOptions($resolver));
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Tests\Unit;
use App\Kernel;
use App\Tests\AbstractTestCase;
/**
* This tests just exist to keep the code covering high.
* They're also helpfull to see if the symfony core changed.
*
* @author kevinfrantz
*/
class KernelTest extends AbstractTestCase
{
/**
* @var Kernel
*/
protected $kernel;
public function setUp(): void
{
$this->kernel = new Kernel('test', false);
}
public function testLogDir(): void
{
$this->assertEquals(true, is_string($this->kernel->getLogDir()));
}
public function testConfigureContainer(): void
{
$this->expectException(\TypeError::class);
$this->assertNull($this->invokeMethod($this->kernel, 'configureContainer', [null, null]));
}
public function testConfigureRoutes(): void
{
$this->expectException(\TypeError::class);
$this->assertNull($this->invokeMethod($this->kernel, 'configureRoutes', [null, null]));
}
}

View File

@@ -0,0 +1,88 @@
<?php
namespace Tests\Unit\Logic;
use PHPUnit\Framework\TestCase;
use App\Logic\Result\ResultInterface;
use App\Logic\Result\Result;
class ResultTest extends TestCase
{
/**
* @var ResultInterface
*/
protected $result;
public function setUp(): void
{
$this->result = new Result();
}
public function testConstructor(): void
{
$this->expectException(\TypeError::class);
$this->result->getValue();
$this->expectException(\TypeError::class);
$this->result->getBool();
}
public function testSetBool(): void
{
$bool = true;
$this->assertNull($this->result->setBool($bool));
$this->assertEquals($bool, $this->result->getBool());
$bool = false;
$this->assertNull($this->result->setBool($bool));
$this->assertEquals($bool, $this->result->getBool());
$this->expectException(\TypeError::class);
$bool = null;
$this->assertNull($this->result->setBool($bool));
$this->assertEquals($bool, $this->result->getBool());
}
public function testSetValue(): void
{
$value = 'test';
$this->assertNull($this->result->setValue($value));
$this->assertEquals($value, $this->result->getValue());
$value = null;
$this->assertNull($this->result->setValue($value));
$this->assertEquals($value, $this->result->getValue());
$value = 123;
$this->assertNull($this->result->setValue($value));
$this->assertEquals($value, $this->result->getValue());
$value = new class() {
};
$this->assertNull($this->result->setValue($value));
$this->assertEquals($value, $this->result->getValue());
}
public function testSetAll(): void
{
$value = 123;
$this->assertNull($this->result->setAll($value));
$this->assertEquals($value, $this->result->getValue());
$this->assertEquals(true, $this->result->getBool());
$value = null;
$this->assertNull($this->result->setAll($value));
$this->assertEquals($value, $this->result->getValue());
$this->assertEquals(false, $this->result->getBool());
$value = '';
$this->assertNull($this->result->setAll($value));
$this->assertEquals($value, $this->result->getValue());
$this->assertEquals(false, $this->result->getBool());
$value = true;
$this->assertNull($this->result->setAll($value));
$this->assertEquals($value, $this->result->getValue());
$this->assertEquals($value, $this->result->getBool());
$value = false;
$this->assertNull($this->result->setAll($value));
$this->assertEquals($value, $this->result->getValue());
$this->assertEquals($value, $this->result->getBool());
$value = new class() {
};
$this->assertNull($this->result->setAll($value));
$this->assertEquals($value, $this->result->getValue());
$this->assertEquals(true, $this->result->getBool());
}
}

View File

@@ -0,0 +1,97 @@
<?php
namespace tests\Unit\Repository;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Doctrine\ORM\EntityRepository;
use App\Entity\Meta\RightInterface;
use App\Entity\Meta\Right;
use App\DBAL\Types\Meta\Right\LayerType;
use App\DBAL\Types\Meta\Right\CRUDType;
use App\Entity\Meta\Law;
use App\Entity\Meta\LawInterface;
use Doctrine\ORM\EntityManagerInterface;
/**
* @todo specify tests for all attributes
*
* @author kevinfrantz
*/
class RightRepositoryTest extends KernelTestCase
{
const PRIORITY = 123;
/**
* @var EntityManagerInterface
*/
private $entityManager;
/**
* @var EntityRepository
*/
private $rightRepository;
/**
* @var RightInterface
*/
private $loadedRight;
/**
* @var RightInterface
*/
private $right;
/**
* @var LawInterface
*/
private $law;
public function setUp(): void
{
$kernel = self::bootKernel();
$this->entityManager = $kernel->getContainer()
->get('doctrine')
->getManager();
$this->rightRepository = $this->entityManager->getRepository(Right::class);
$this->right = new Right();
$this->right->setPriority(self::PRIORITY);
$this->right->setLayer(LayerType::SOURCE);
$this->right->setType(CRUDType::READ);
$this->law = new Law();
$this->entityManager->persist($this->law);
$this->right->setLaw($this->law);
}
public function testCreation(): void
{
$this->entityManager->persist($this->right);
$this->entityManager->flush();
$rightId = $this->right->getId();
$this->loadedRight = $this->rightRepository->find($rightId);
$this->assertEquals($rightId, $this->loadedRight->getId());
$this->assertEquals(self::PRIORITY, $this->loadedRight->getPriority());
$this->deleteRight();
$this->assertNull($this->rightRepository->find($rightId));
$this->loadedRight = null;
}
private function deleteRight(): void
{
$this->entityManager->remove($this->loadedRight);
$this->entityManager->flush();
$this->entityManager->remove($this->law);
$this->entityManager->flush();
}
/**
* {@inheritdoc}
*
* @see \Symfony\Bundle\FrameworkBundle\Test\KernelTestCase::tearDown()
*/
protected function tearDown(): void
{
parent::tearDown();
$this->entityManager->close();
$this->entityManager = null;
}
}

View File

@@ -0,0 +1,103 @@
<?php
namespace tests\Unit\Repository;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Doctrine\ORM\EntityManager;
use App\Repository\UserRepository;
use App\Entity\User;
use App\Entity\UserInterface;
use App\Entity\Source\Complex\PersonIdentitySourceInterface;
use App\Entity\Source\Complex\PersonIdentitySource;
class UserRepositoryTest extends KernelTestCase
{
/**
* @var EntityManager
*/
protected $entityManager;
/**
* @var UserRepository
*/
protected $userRepository;
/**
* @var UserInterface
*/
protected $loadedUser;
/**
* @var UserInterface
*/
protected $user;
public function setUp(): void
{
$kernel = self::bootKernel();
$this->entityManager = $kernel->getContainer()->get('doctrine')->getManager();
$this->userRepository = $this->entityManager->getRepository(User::class);
$this->user = new User();
$this->user->setUsername('Karl Marx');
$this->user->setEmail('mew21@test.de');
$this->user->setPassword('Die Philosophen haben die Welt nur verschieden interpretiert; es kommt aber darauf an, sie zu verändern.');
}
/**
* @todo Test double username
* @todo Test double email
*/
public function testCreation(): void
{
$this->entityManager->persist($this->user);
$this->entityManager->flush();
$userId = $this->user->getId();
/*
* @var UserInterface
*/
$this->loadedUser = $this->userRepository->find($userId);
$this->assertEquals($userId, $this->loadedUser->getId());
$this->assertGreaterThan(0, $this->loadedUser->getSource()->getId());
$this->deleteUser();
$this->assertNull($this->userRepository->find($userId));
$this->loadedUser = null;
}
public function testUserWithPersonIdentitySource(): void
{
/**
* @var PersonIdentitySourceInterface
*/
$personIdentity = new PersonIdentitySource();
$personIdentity->getFullPersonNameSource()->getFirstNameSource()->setName('Karl');
$personIdentity->getFullPersonNameSource()->getSurnameSource()->setName('Marx');
$this->user->getSource()->setPersonIdentitySource($personIdentity);
$this->entityManager->persist($this->user);
$this->entityManager->flush();
$userId = $this->user->getId();
$this->loadedUser = $this->userRepository->find($userId);
$this->assertGreaterThan(0, $this->loadedUser->getSource()->getPersonIdentitySource()->getId());
$this->assertGreaterThan(0, $this->loadedUser->getSource()->getPersonIdentitySource()->getFullPersonNameSource()->getId());
$this->assertGreaterThan(0, $this->loadedUser->getSource()->getPersonIdentitySource()->getFullPersonNameSource()->getFirstNameSource()->getId());
$this->assertGreaterThan(0, $this->loadedUser->getSource()->getPersonIdentitySource()->getFullPersonNameSource()->getSurnameSource()->getId());
$this->deleteUser();
}
private function deleteUser(): void
{
$this->entityManager->remove($this->loadedUser);
$this->entityManager->flush();
}
/**
* {@inheritdoc}
*
* @see \Symfony\Bundle\FrameworkBundle\Test\KernelTestCase::tearDown()
*/
protected function tearDown(): void
{
parent::tearDown();
$this->entityManager->close();
$this->entityManager = null;
}
}

View File

@@ -0,0 +1,85 @@
<?php
namespace tests\Unit\Repository;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Doctrine\ORM\EntityManager;
use App\Entity\Source\Complex\UserSource;
use App\Domain\SourceManagement\SourceMemberManager;
/**
* @todo refactor this to an integration test!
*
* @author kevinfrantz
*/
class UserSourceRepositoryTest extends KernelTestCase
{
/**
* @var EntityManager
*/
protected $entityManager;
public function setUp(): void
{
$kernel = self::bootKernel();
$this->entityManager = $kernel->getContainer()
->get('doctrine')
->getManager();
}
public function testAddAndRemoveMember(): void
{
$insertSource = new UserSource();
$origineSource = new UserSource();
$origineSourceMemberManager = new SourceMemberManager($origineSource);
$origineSourceMemberManager->addMember($insertSource);
$this->entityManager->persist($insertSource);
$this->entityManager->persist($origineSource);
$this->entityManager->flush();
$this->assertGreaterThan(0, $insertSource->getId());
$this->assertGreaterThan(0, $origineSource->getId());
$this->assertEquals($insertSource, $origineSource->getMemberRelation()->getMembers()
->get(0)->getSource());
$this->assertEquals($origineSource, $insertSource->getMemberRelation()->getMemberships()
->get(0)->getSource());
$this->assertNull($origineSourceMemberManager->removeMember($insertSource));
$this->assertEquals(0, $origineSource->getMemberRelation()->getMembers()
->count());
$this->assertEquals(0, $insertSource->getMemberRelation()->getMemberships()
->count());
$this->entityManager->remove($origineSource);
$this->entityManager->flush();
$this->assertGreaterThan(0, $insertSource->getId());
$this->entityManager->remove($insertSource);
$this->entityManager->flush();
$this->expectException(\TypeError::class);
$insertSource->getId();
}
public function testCreation(): void
{
$userSource = new UserSource();
$this->entityManager->persist($userSource);
$this->entityManager->flush();
$userSourceId = $userSource->getId();
$loadedUserSource = $this->entityManager->getRepository(UserSource::class)->find($userSourceId);
$this->assertEquals($userSourceId, $loadedUserSource->getId());
$this->assertGreaterThan(0, $userSource->getCreatorRelation()->getId());
$this->assertGreaterThan(0, $userSource->getLaw()->getId());
$this->assertFalse($userSource->hasPersonIdentitySource());
$this->entityManager->remove($loadedUserSource);
$this->entityManager->flush();
}
/**
* {@inheritdoc}
*
* @see \Symfony\Bundle\FrameworkBundle\Test\KernelTestCase::tearDown()
*/
protected function tearDown(): void
{
parent::tearDown();
$this->entityManager->close();
$this->entityManager = null;
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Tests\Unit\Entity\Subscriber;
use App\Subscriber\SourceMenuSubscriber;
use Symfony\Component\Translation\Translator;
use App\Event\Menu\MenuEvent;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Request;
use Knp\Menu\MenuItem;
use Knp\Menu\MenuFactory;
class SourceMenuSubscriberTest extends TestCase
{
/**
* @var SourceMenuSubscriber
*/
public $subscriber;
public function setUp(): void
{
$translator = new Translator('en');
$this->subscriber = new SourceMenuSubscriber($translator);
}
public function testOnSourceMenuConfig(): void
{
$factory = new MenuFactory();
$item = new MenuItem('test', $factory);
$request = new Request();
$request->attributes->set('id', 123);
$requests = new RequestStack();
$requests->push($request);
$event = new MenuEvent($factory, $item, $requests);
$this->assertNull($this->subscriber->onSourceMenuConfigure($event));
}
}