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), ); } }