From 08c4bee43f1f31a1c4c3271fc75d1f059567923a Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Sun, 18 Nov 2018 12:16:38 +0100 Subject: [PATCH] Implemented tests for personIdentitySource and solved conflicts --- .../Combination/AbstractCombinationSource.php | 2 +- .../Combination/PersonIdentitySource.php | 9 ++++++-- .../Entity/Source/Combination/UserSource.php | 2 +- .../Unit/Repository/UserRepositoryTest.php | 23 +++++++++++++++---- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/application/src/Entity/Source/Combination/AbstractCombinationSource.php b/application/src/Entity/Source/Combination/AbstractCombinationSource.php index 6e59739..d79a818 100644 --- a/application/src/Entity/Source/Combination/AbstractCombinationSource.php +++ b/application/src/Entity/Source/Combination/AbstractCombinationSource.php @@ -12,7 +12,7 @@ use Doctrine\ORM\Mapping as ORM; * @ORM\Table(name="source_combination") * @ORM\InheritanceType("JOINED") * @ORM\DiscriminatorColumn(name="discr", type="string") - * @ORM\DiscriminatorMap({"user" = "UserSource","fullpersonname" = "FullPersonNameSource"}) + * @ORM\DiscriminatorMap({"user" = "UserSource","fullpersonname" = "FullPersonNameSource","personidentitysource"="PersonIdentitySource"}) */ abstract class AbstractCombinationSource extends AbstractSource implements CombinationSourceInterface { diff --git a/application/src/Entity/Source/Combination/PersonIdentitySource.php b/application/src/Entity/Source/Combination/PersonIdentitySource.php index bbd57d9..d35598e 100644 --- a/application/src/Entity/Source/Combination/PersonIdentitySource.php +++ b/application/src/Entity/Source/Combination/PersonIdentitySource.php @@ -3,9 +3,14 @@ namespace App\Entity\Source\Combination; use App\Entity\Attribut\FullPersonNameSourceAttribut; -use App\Entity\Source\Data\AbstractDataSource; +use Doctrine\ORM\Mapping as ORM; -class PersonIdentitySource extends AbstractDataSource implements PersonIdentitySourceInterface +/** + * @author kevinfrantz + * @ORM\Table(name="source_combination_person_identity") + * @ORM\Entity() + */ +class PersonIdentitySource extends AbstractCombinationSource implements PersonIdentitySourceInterface { use FullPersonNameSourceAttribut; diff --git a/application/src/Entity/Source/Combination/UserSource.php b/application/src/Entity/Source/Combination/UserSource.php index acba653..045c106 100644 --- a/application/src/Entity/Source/Combination/UserSource.php +++ b/application/src/Entity/Source/Combination/UserSource.php @@ -25,7 +25,7 @@ class UserSource extends AbstractCombinationSource implements UserSourceInterfac protected $user; /** - * @todo Implement ORM mapping for database! + * @ORM\OneToOne(targetEntity="PersonIdentitySource",cascade={"persist", "remove"}) * * @var PersonIdentitySourceInterface */ diff --git a/application/tests/Unit/Repository/UserRepositoryTest.php b/application/tests/Unit/Repository/UserRepositoryTest.php index 75c6df6..cbf32e6 100644 --- a/application/tests/Unit/Repository/UserRepositoryTest.php +++ b/application/tests/Unit/Repository/UserRepositoryTest.php @@ -20,6 +20,11 @@ class UserRepositoryTest extends KernelTestCase */ protected $userRepository; + /** + * @var UserInterface + */ + protected $loadedUser; + public function setUp(): void { $kernel = self::bootKernel(); @@ -40,14 +45,22 @@ class UserRepositoryTest extends KernelTestCase $this->entityManager->persist($user); $this->entityManager->flush(); $userId = $user->getId(); - /** + /* * @var UserInterface */ - $loadedUser = $this->userRepository->find($userId); - $this->assertEquals($userId, $loadedUser->getId()); - $this->entityManager->remove($loadedUser); - $this->entityManager->flush(); + $this->loadedUser = $this->userRepository->find($userId); + $this->assertEquals($userId, $this->loadedUser->getId()); + $this->assertGreaterThan(0, $this->loadedUser->getSource()->getId()); + $this->assertGreaterThan(0, $this->loadedUser->getSource()->getPersonIdentitySource()->getId()); + $this->deleteUser(); $this->assertNull($this->userRepository->find($userId)); + $this->loadedUser = null; + } + + private function deleteUser(): void + { + $this->entityManager->remove($this->loadedUser); + $this->entityManager->flush(); } /**