diff --git a/Repository/ServiceEntityRepository.php b/Repository/ServiceEntityRepository.php index 0b36f233d..5d4597fa2 100644 --- a/Repository/ServiceEntityRepository.php +++ b/Repository/ServiceEntityRepository.php @@ -4,6 +4,7 @@ use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\ORM\EntityRepository; +use LogicException; /** * Optional EntityRepository base class with a simplified constructor (for autowiring). @@ -28,6 +29,13 @@ public function __construct(ManagerRegistry $registry, $entityClass) { $manager = $registry->getManagerForClass($entityClass); + if (null === $manager) { + throw new LogicException(sprintf( + 'Could not find the entity manager for class "%s". Check your Doctrine configuration to make sure it is configured to load this entity’s metadata.', + $entityClass + )); + } + parent::__construct($manager, $manager->getClassMetadata($entityClass)); } } diff --git a/Tests/Repository/ServiceEntityRepositoryTest.php b/Tests/Repository/ServiceEntityRepositoryTest.php new file mode 100644 index 000000000..499c99b44 --- /dev/null +++ b/Tests/Repository/ServiceEntityRepositoryTest.php @@ -0,0 +1,20 @@ +getMockBuilder(ManagerRegistry::class)->getMock(); + new ServiceEntityRepository($registry, TestEntity::class); + } +}