|
10 | 10 | use Doctrine\Bundle\MongoDBBundle\Attribute\MapDocument; |
11 | 11 | use Doctrine\Bundle\MongoDBBundle\Command\Encryption\DiagnosticCommand; |
12 | 12 | use Doctrine\Bundle\MongoDBBundle\Command\Encryption\DumpFieldsMapCommand; |
| 13 | +use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\CreateProxyDirectoryPass; |
13 | 14 | use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\ServiceRepositoryCompilerPass; |
14 | 15 | use Doctrine\Bundle\MongoDBBundle\DependencyInjection\DoctrineMongoDBExtension; |
| 16 | +use Doctrine\Bundle\MongoDBBundle\ManagerRegistry; |
| 17 | +use Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\AttributesBundle\Document\TestDocument; |
15 | 18 | use Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\DocumentListenerBundle\EventListener\TestAttributeListener; |
16 | 19 | use Doctrine\ODM\MongoDB\Configuration; |
| 20 | +use Doctrine\ODM\MongoDB\DocumentManager; |
17 | 21 | use Doctrine\ODM\MongoDB\Mapping\Annotations; |
18 | 22 | use InvalidArgumentException; |
19 | 23 | use MongoDB\Client; |
|
22 | 26 | use stdClass; |
23 | 27 | use Symfony\Component\DependencyInjection\Alias; |
24 | 28 | use Symfony\Component\DependencyInjection\ChildDefinition; |
| 29 | +use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass; |
25 | 30 | use Symfony\Component\DependencyInjection\Container; |
26 | 31 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
27 | 32 | use Symfony\Component\DependencyInjection\Definition; |
@@ -716,6 +721,55 @@ public function testAutoEncryptionMinimumODMVersion(): void |
716 | 721 | $loader->load([$config], $container); |
717 | 722 | } |
718 | 723 |
|
| 724 | + #[DataProvider('provideLazyObjectConfigurations')] |
| 725 | + public function testRegistryGetManagerForClass(array $config): void |
| 726 | + { |
| 727 | + $container = $this->getContainer('AttributesBundle'); |
| 728 | + $loader = new DoctrineMongoDBExtension(); |
| 729 | + $loader->load(self::buildConfiguration($config + [ |
| 730 | + 'connections' => [ |
| 731 | + 'default' => [], |
| 732 | + ], |
| 733 | + 'document_managers' => [ |
| 734 | + 'default' => [ |
| 735 | + 'mappings' => [ |
| 736 | + 'AttributesBundle' => ['type' => 'attribute'], |
| 737 | + ], |
| 738 | + ], |
| 739 | + ], |
| 740 | + ]), $container); |
| 741 | + (new ResolveParameterPlaceHoldersPass())->process($container); |
| 742 | + (new ServiceRepositoryCompilerPass())->process($container); |
| 743 | + (new CreateProxyDirectoryPass())->process($container); |
| 744 | + |
| 745 | + $container->compile(); |
| 746 | + $registry = $container->get('doctrine_mongodb'); |
| 747 | + $dm = $container->get('doctrine_mongodb.odm.document_manager'); |
| 748 | + |
| 749 | + self::assertInstanceOf(ManagerRegistry::class, $registry); |
| 750 | + self::assertInstanceOf(DocumentManager::class, $dm); |
| 751 | + |
| 752 | + // Create a lazy object |
| 753 | + $ref = $dm->getReference(TestDocument::class, 'some'); |
| 754 | + self::assertInstanceOf(TestDocument::class, $ref); |
| 755 | + self::assertSame($dm, $registry->getManagerForClass($ref::class)); |
| 756 | + } |
| 757 | + |
| 758 | + public static function provideLazyObjectConfigurations(): iterable |
| 759 | + { |
| 760 | + yield 'Proxy Manager' => [ |
| 761 | + ['enable_lazy_ghost_objects' => false, 'enable_native_lazy_objects' => false], |
| 762 | + ]; |
| 763 | + |
| 764 | + yield 'Symfony Lazy Objects' => [ |
| 765 | + ['enable_lazy_ghost_objects' => true, 'enable_native_lazy_objects' => false], |
| 766 | + ]; |
| 767 | + |
| 768 | + yield 'Native Lazy Objects' => [ |
| 769 | + ['enable_lazy_ghost_objects' => false, 'enable_native_lazy_objects' => true], |
| 770 | + ]; |
| 771 | + } |
| 772 | + |
719 | 773 | private static function requireAutoEncryptionSupportInODM(): void |
720 | 774 | { |
721 | 775 | if (! InstalledVersions::satisfies(new VersionParser(), 'doctrine/mongodb-odm', '>=2.12@dev')) { |
|
0 commit comments