Implemented use of EntityManager service

This commit is contained in:
Kevin Frantz 2019-01-03 22:14:01 +01:00
parent aea23725f6
commit 16e56de458
2 changed files with 17 additions and 11 deletions

View File

@ -7,6 +7,8 @@ use App\Entity\Meta\RightInterface;
use Doctrine\Common\Persistence\ObjectRepository; use Doctrine\Common\Persistence\ObjectRepository;
use App\Domain\SecureManagement\SecureSourceChecker; use App\Domain\SecureManagement\SecureSourceChecker;
use App\Exception\SourceAccessDenied; use App\Exception\SourceAccessDenied;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Source\AbstractSource;
/** /**
* @author kevinfrantz * @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; $this->requestedRight = $requestedRight;
} }

View File

@ -5,7 +5,6 @@ namespace Tests\Unit\Domain\SecureLoadManagement;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Doctrine\Common\Persistence\ObjectRepository; use Doctrine\Common\Persistence\ObjectRepository;
use App\Entity\Source\AbstractSource; use App\Entity\Source\AbstractSource;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use App\Domain\SecureLoadManagement\SecureSourceLoader; use App\Domain\SecureLoadManagement\SecureSourceLoader;
use App\Entity\Source\Primitive\Text\TextSource; use App\Entity\Source\Primitive\Text\TextSource;
@ -15,6 +14,7 @@ use App\DBAL\Types\LayerType;
use App\DBAL\Types\RightType; use App\DBAL\Types\RightType;
use App\Entity\Source\Complex\UserSource; use App\Entity\Source\Complex\UserSource;
use App\Entity\Source\Primitive\Text\TextSourceInterface; use App\Entity\Source\Primitive\Text\TextSourceInterface;
use Doctrine\ORM\EntityManagerInterface;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -28,17 +28,21 @@ class SecureSourceLoaderTest extends KernelTestCase
*/ */
private $sourceRepository; private $sourceRepository;
/**
* @var EntityManagerInterface
*/
private $entityManager;
public function setUp(): void public function setUp(): void
{ {
$kernel = self::bootKernel(); self::bootKernel();
$this->setSourceRepository($kernel); $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() $this->sourceRepository = $this->entityManager->getRepository(AbstractSource::class);
->get('doctrine')
->getManager()->getRepository(AbstractSource::class);
} }
public function testAccessDeniedException(): void public function testAccessDeniedException(): void
@ -50,7 +54,7 @@ class SecureSourceLoaderTest extends KernelTestCase
$requestedRight->setLayer(LayerType::SOURCE); $requestedRight->setLayer(LayerType::SOURCE);
$requestedRight->setType(RightType::READ); $requestedRight->setType(RightType::READ);
$requestedRight->setReciever(new UserSource()); $requestedRight->setReciever(new UserSource());
$secureSourceLoader = new SecureSourceLoader($this->sourceRepository, $requestedRight); $secureSourceLoader = new SecureSourceLoader($this->entityManager, $requestedRight);
$this->expectException(AccessDeniedHttpException::class); $this->expectException(AccessDeniedHttpException::class);
$secureSourceLoader->getSource(); $secureSourceLoader->getSource();
} }
@ -64,7 +68,7 @@ class SecureSourceLoaderTest extends KernelTestCase
$requestedRight->setLayer(LayerType::SOURCE); $requestedRight->setLayer(LayerType::SOURCE);
$requestedRight->setType(RightType::READ); $requestedRight->setType(RightType::READ);
$requestedRight->setReciever($this->sourceRepository->findOneBy(['slug' => SystemSlugType::GUEST_USER])); $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()); $this->assertInstanceOf(TextSourceInterface::class, $secureSourceLoader->getSource());
} }
} }