From 21d6ef80659268ffb9b2e0fc5257dcdabe279704 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 14 Dec 2023 09:57:58 +0100 Subject: [PATCH] Expose use_transactional_flush setting --- DependencyInjection/Configuration.php | 1 + .../DoctrineMongoDBExtension.php | 1 + .../DependencyInjection/ConfigurationTest.php | 13 +++--- .../DoctrineMongoDBExtensionTest.php | 40 +++++++++++++++++++ 4 files changed, 50 insertions(+), 5 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 3fd9c98b..f57dbd0a 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -208,6 +208,7 @@ private function addDocumentManagersSection(ArrayNodeDefinition $rootNode): void ->scalarNode('namespace')->end() ->end() ->end() + ->booleanNode('use_transactional_flush')->defaultFalse()->end() ->end() ->fixXmlConfig('mapping') ->children() diff --git a/DependencyInjection/DoctrineMongoDBExtension.php b/DependencyInjection/DoctrineMongoDBExtension.php index df23fe9d..1d945bea 100644 --- a/DependencyInjection/DoctrineMongoDBExtension.php +++ b/DependencyInjection/DoctrineMongoDBExtension.php @@ -251,6 +251,7 @@ protected function loadDocumentManager(array $documentManager, $defaultDM, $defa 'setPersistentCollectionDir' => '%doctrine_mongodb.odm.persistent_collection_dir%', 'setPersistentCollectionNamespace' => '%doctrine_mongodb.odm.persistent_collection_namespace%', 'setAutoGeneratePersistentCollectionClasses' => '%doctrine_mongodb.odm.auto_generate_persistent_collection_classes%', + 'setUseTransactionalFlush' => $documentManager['use_transactional_flush'], ]; if ($documentManager['repository_factory']) { diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index a647d431..d0fbd671 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -177,6 +177,7 @@ public function testFullConfiguration(array $config): void 'enabled' => true, 'pretty' => false, ], + 'use_transactional_flush' => false, ], 'dm2' => [ 'connection' => 'dm2_connection', @@ -203,6 +204,7 @@ public function testFullConfiguration(array $config): void 'enabled' => '%kernel.debug%', 'pretty' => '%kernel.debug%', ], + 'use_transactional_flush' => false, ], ], 'resolve_target_documents' => ['Foo\BarInterface' => 'Bar\FooClass'], @@ -293,7 +295,7 @@ public static function provideMergeOptions(): array ['document_managers' => ['default' => ['mappings' => ['foomap' => ['type' => 'val1'], 'barmap' => ['dir' => 'val2']]]]], ['document_managers' => ['default' => ['mappings' => ['barmap' => ['prefix' => 'val3']]]]], ], - ['document_managers' => ['default' => ['metadata_cache_driver' => ['type' => 'array'], 'logging' => '%kernel.debug%', 'profiler' => ['enabled' => '%kernel.debug%', 'pretty' => '%kernel.debug%'], 'auto_mapping' => false, 'default_document_repository_class' => DocumentRepository::class, 'default_gridfs_repository_class' => DefaultGridFSRepository::class, 'repository_factory' => 'doctrine_mongodb.odm.container_repository_factory', 'persistent_collection_factory' => null, 'filters' => [], 'mappings' => ['foomap' => ['type' => 'val1', 'mapping' => true], 'barmap' => ['prefix' => 'val3', 'mapping' => true]]]]], + ['document_managers' => ['default' => ['metadata_cache_driver' => ['type' => 'array'], 'logging' => '%kernel.debug%', 'profiler' => ['enabled' => '%kernel.debug%', 'pretty' => '%kernel.debug%'], 'auto_mapping' => false, 'default_document_repository_class' => DocumentRepository::class, 'default_gridfs_repository_class' => DefaultGridFSRepository::class, 'repository_factory' => 'doctrine_mongodb.odm.container_repository_factory', 'persistent_collection_factory' => null, 'filters' => [], 'mappings' => ['foomap' => ['type' => 'val1', 'mapping' => true], 'barmap' => ['prefix' => 'val3', 'mapping' => true]], 'use_transactional_flush' => false]]], ]; // connections are merged non-recursively. @@ -344,8 +346,8 @@ public static function provideMergeOptions(): array ], [ 'document_managers' => [ - 'foodm' => ['database' => 'val1', 'metadata_cache_driver' => ['type' => 'array'], 'logging' => '%kernel.debug%', 'profiler' => ['enabled' => '%kernel.debug%', 'pretty' => '%kernel.debug%'], 'auto_mapping' => false, 'default_document_repository_class' => DocumentRepository::class, 'default_gridfs_repository_class' => DefaultGridFSRepository::class, 'repository_factory' => 'doctrine_mongodb.odm.container_repository_factory', 'persistent_collection_factory' => null, 'filters' => [], 'mappings' => []], - 'bardm' => ['database' => 'val3', 'metadata_cache_driver' => ['type' => 'array'], 'logging' => '%kernel.debug%', 'profiler' => ['enabled' => '%kernel.debug%', 'pretty' => '%kernel.debug%'], 'auto_mapping' => false, 'default_document_repository_class' => DocumentRepository::class, 'default_gridfs_repository_class' => DefaultGridFSRepository::class, 'repository_factory' => 'doctrine_mongodb.odm.container_repository_factory', 'persistent_collection_factory' => null, 'filters' => [], 'mappings' => []], + 'foodm' => ['database' => 'val1', 'metadata_cache_driver' => ['type' => 'array'], 'logging' => '%kernel.debug%', 'profiler' => ['enabled' => '%kernel.debug%', 'pretty' => '%kernel.debug%'], 'auto_mapping' => false, 'default_document_repository_class' => DocumentRepository::class, 'default_gridfs_repository_class' => DefaultGridFSRepository::class, 'repository_factory' => 'doctrine_mongodb.odm.container_repository_factory', 'persistent_collection_factory' => null, 'filters' => [], 'mappings' => [], 'use_transactional_flush' => false], + 'bardm' => ['database' => 'val3', 'metadata_cache_driver' => ['type' => 'array'], 'logging' => '%kernel.debug%', 'profiler' => ['enabled' => '%kernel.debug%', 'pretty' => '%kernel.debug%'], 'auto_mapping' => false, 'default_document_repository_class' => DocumentRepository::class, 'default_gridfs_repository_class' => DefaultGridFSRepository::class, 'repository_factory' => 'doctrine_mongodb.odm.container_repository_factory', 'persistent_collection_factory' => null, 'filters' => [], 'mappings' => [], 'use_transactional_flush' => false], ], ], ]; @@ -401,8 +403,8 @@ public static function provideNormalizeOptions(): array ], [ 'document_managers' => [ - 'foo' => ['connection' => 'conn1', 'metadata_cache_driver' => ['type' => 'array'], 'logging' => '%kernel.debug%', 'profiler' => ['enabled' => '%kernel.debug%', 'pretty' => '%kernel.debug%'], 'auto_mapping' => false, 'default_document_repository_class' => DocumentRepository::class, 'default_gridfs_repository_class' => DefaultGridFSRepository::class, 'repository_factory' => 'doctrine_mongodb.odm.container_repository_factory', 'persistent_collection_factory' => null, 'filters' => [], 'mappings' => []], - 'bar' => ['connection' => 'conn2', 'metadata_cache_driver' => ['type' => 'array'], 'logging' => '%kernel.debug%', 'profiler' => ['enabled' => '%kernel.debug%', 'pretty' => '%kernel.debug%'], 'auto_mapping' => false, 'default_document_repository_class' => DocumentRepository::class, 'default_gridfs_repository_class' => DefaultGridFSRepository::class, 'repository_factory' => 'doctrine_mongodb.odm.container_repository_factory', 'persistent_collection_factory' => null,'filters' => [], 'mappings' => []], + 'foo' => ['connection' => 'conn1', 'metadata_cache_driver' => ['type' => 'array'], 'logging' => '%kernel.debug%', 'profiler' => ['enabled' => '%kernel.debug%', 'pretty' => '%kernel.debug%'], 'auto_mapping' => false, 'default_document_repository_class' => DocumentRepository::class, 'default_gridfs_repository_class' => DefaultGridFSRepository::class, 'repository_factory' => 'doctrine_mongodb.odm.container_repository_factory', 'persistent_collection_factory' => null, 'filters' => [], 'mappings' => [], 'use_transactional_flush' => false], + 'bar' => ['connection' => 'conn2', 'metadata_cache_driver' => ['type' => 'array'], 'logging' => '%kernel.debug%', 'profiler' => ['enabled' => '%kernel.debug%', 'pretty' => '%kernel.debug%'], 'auto_mapping' => false, 'default_document_repository_class' => DocumentRepository::class, 'default_gridfs_repository_class' => DefaultGridFSRepository::class, 'repository_factory' => 'doctrine_mongodb.odm.container_repository_factory', 'persistent_collection_factory' => null,'filters' => [], 'mappings' => [], 'use_transactional_flush' => false], ], ], ]; @@ -435,6 +437,7 @@ public static function provideNormalizeOptions(): array 'profiler' => ['enabled' => '%kernel.debug%', 'pretty' => '%kernel.debug%'], 'auto_mapping' => false, 'filters' => [], + 'use_transactional_flush' => false, ], ], ], diff --git a/Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php b/Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php index fbe69742..67aebabc 100644 --- a/Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php +++ b/Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php @@ -370,4 +370,44 @@ public function testControllerResolver(): void $container->compile(); $this->assertEquals(new MapDocument(null, null, null, [], null, null, null, true), $container->get('controller_resolver_defaults')); } + + public function testDefaultTransactionalFlush(): void + { + $container = $this->buildMinimalContainer(); + $container->setParameter('kernel.debug', false); + $container->setParameter('kernel.bundles', []); + $container->setParameter('kernel.bundles_metadata', []); + $loader = new DoctrineMongoDBExtension(); + $loader->load(self::buildConfiguration(), $container); + + $configuration = $container->getDefinition('doctrine_mongodb.odm.default_configuration'); + + $this->assertContains( + [ + 'setUseTransactionalFlush', + [false], + ], + $configuration->getMethodCalls(), + ); + } + + public function testUseTransactionalFlush(): void + { + $container = $this->buildMinimalContainer(); + $container->setParameter('kernel.debug', false); + $container->setParameter('kernel.bundles', []); + $container->setParameter('kernel.bundles_metadata', []); + $loader = new DoctrineMongoDBExtension(); + $loader->load(self::buildConfiguration(['document_managers' => ['default' => ['use_transactional_flush' => true]]]), $container); + + $configuration = $container->getDefinition('doctrine_mongodb.odm.default_configuration'); + + $this->assertContains( + [ + 'setUseTransactionalFlush', + [true], + ], + $configuration->getMethodCalls(), + ); + } }