From 372bea484944b32a0730771de3b4fd536a7c55df Mon Sep 17 00:00:00 2001 From: hamed <15238-genius.ha@users.noreply.drupalcode.org> Date: Sun, 28 Jun 2026 16:53:40 +0330 Subject: [PATCH] =?UTF-8?q?test(orm):=20regression=20=E2=80=94=20every=20e?= =?UTF-8?q?ntity=20with=20a=20custom=20repo=20declares=20repositoryClass?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Auto-discovers each mapped entity that has a sibling Repository class and asserts getRepository() returns it (not Doctrine's default). Catches the prod-only opcache.preload bug class that broke /oauth/userinfo. --- tests/Doctrine/RepositoryClassMappingTest.php | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/Doctrine/RepositoryClassMappingTest.php 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), + ); + } +}