Optimized for SPA

This commit is contained in:
Kevin Frantz
2019-01-05 23:52:37 +01:00
parent 9e685260e9
commit bccd6efaff
393 changed files with 253 additions and 37 deletions

View File

@@ -0,0 +1,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;
}
}