From 16e56de458452a99ed7b1c7d10c2c4c370678cfc Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Thu, 3 Jan 2019 22:14:01 +0100 Subject: [PATCH] Implemented use of EntityManager service --- .../SecureSourceLoader.php | 6 +++-- .../SecureSourceLoaderTest.php | 22 +++++++++++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/application/src/Domain/SecureLoadManagement/SecureSourceLoader.php b/application/src/Domain/SecureLoadManagement/SecureSourceLoader.php index 89aa6c2..0bd2bc5 100644 --- a/application/src/Domain/SecureLoadManagement/SecureSourceLoader.php +++ b/application/src/Domain/SecureLoadManagement/SecureSourceLoader.php @@ -7,6 +7,8 @@ use App\Entity\Meta\RightInterface; use Doctrine\Common\Persistence\ObjectRepository; use App\Domain\SecureManagement\SecureSourceChecker; use App\Exception\SourceAccessDenied; +use Doctrine\ORM\EntityManagerInterface; +use App\Entity\Source\AbstractSource; /** * @author kevinfrantz @@ -52,9 +54,9 @@ final class SecureSourceLoader implements SecureSourceLoaderInterface } } - public function __construct(ObjectRepository $sourceRepository, RightInterface $requestedRight) + public function __construct(EntityManagerInterface $entityManager, RightInterface $requestedRight) { - $this->sourceRepository = $sourceRepository; + $this->sourceRepository = $entityManager->getRepository(AbstractSource::class); $this->requestedRight = $requestedRight; } diff --git a/application/tests/Unit/Domain/SecureLoadManagement/SecureSourceLoaderTest.php b/application/tests/Unit/Domain/SecureLoadManagement/SecureSourceLoaderTest.php index bf9fb4a..00442af 100644 --- a/application/tests/Unit/Domain/SecureLoadManagement/SecureSourceLoaderTest.php +++ b/application/tests/Unit/Domain/SecureLoadManagement/SecureSourceLoaderTest.php @@ -5,7 +5,6 @@ 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\KernelInterface; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use App\Domain\SecureLoadManagement\SecureSourceLoader; use App\Entity\Source\Primitive\Text\TextSource; @@ -15,6 +14,7 @@ use App\DBAL\Types\LayerType; use App\DBAL\Types\RightType; use App\Entity\Source\Complex\UserSource; use App\Entity\Source\Primitive\Text\TextSourceInterface; +use Doctrine\ORM\EntityManagerInterface; /** * @author kevinfrantz @@ -28,17 +28,21 @@ class SecureSourceLoaderTest extends KernelTestCase */ private $sourceRepository; + /** + * @var EntityManagerInterface + */ + private $entityManager; + public function setUp(): void { - $kernel = self::bootKernel(); - $this->setSourceRepository($kernel); + self::bootKernel(); + $this->entityManager = self::$container->get('doctrine.orm.default_entity_manager'); + $this->setSourceRepository(); } - private function setSourceRepository(KernelInterface $kernel): void + private function setSourceRepository(): void { - $this->sourceRepository = $kernel->getContainer() - ->get('doctrine') - ->getManager()->getRepository(AbstractSource::class); + $this->sourceRepository = $this->entityManager->getRepository(AbstractSource::class); } public function testAccessDeniedException(): void @@ -50,7 +54,7 @@ class SecureSourceLoaderTest extends KernelTestCase $requestedRight->setLayer(LayerType::SOURCE); $requestedRight->setType(RightType::READ); $requestedRight->setReciever(new UserSource()); - $secureSourceLoader = new SecureSourceLoader($this->sourceRepository, $requestedRight); + $secureSourceLoader = new SecureSourceLoader($this->entityManager, $requestedRight); $this->expectException(AccessDeniedHttpException::class); $secureSourceLoader->getSource(); } @@ -64,7 +68,7 @@ class SecureSourceLoaderTest extends KernelTestCase $requestedRight->setLayer(LayerType::SOURCE); $requestedRight->setType(RightType::READ); $requestedRight->setReciever($this->sourceRepository->findOneBy(['slug' => SystemSlugType::GUEST_USER])); - $secureSourceLoader = new SecureSourceLoader($this->sourceRepository, $requestedRight); + $secureSourceLoader = new SecureSourceLoader($this->entityManager, $requestedRight); $this->assertInstanceOf(TextSourceInterface::class, $secureSourceLoader->getSource()); } }