diff --git a/tests/Doctrine/RepositoryClassMappingTest.php b/tests/Doctrine/RepositoryClassMappingTest.php new file mode 100644 index 00000000..ae6f2d7b --- /dev/null +++ b/tests/Doctrine/RepositoryClassMappingTest.php @@ -0,0 +1,44 @@ +Repository class + * (App\\Entity\X -> App\\Repository\XRepository), assert + * getRepository() actually returns that custom class. + */ +class RepositoryClassMappingTest extends KernelTestCase +{ + public function testEntitiesWithCustomRepoDeclareIt(): void + { + self::bootKernel(); + $em = static::getContainer()->get(EntityManagerInterface::class); + + $offenders = []; + foreach ($em->getMetadataFactory()->getAllMetadata() as $meta) { + $entity = $meta->getName(); + $repoFqcn = str_replace('\\Entity\\', '\\Repository\\', $entity) . 'Repository'; + if (!class_exists($repoFqcn)) { + continue; + } + $actual = $em->getRepository($entity); + if (!$actual instanceof $repoFqcn) { + $offenders[] = sprintf('%s -> got %s, expected %s', $entity, $actual::class, $repoFqcn); + } + } + + $this->assertSame( + [], + $offenders, + "Entities missing #[ORM\\Entity(repositoryClass: ...)]:\n" . implode("\n", $offenders), + ); + } +}