Skip to content

Commit

Permalink
Expose use_transactional_flush setting
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Dec 14, 2023
1 parent c53d147 commit 21d6ef8
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/DoctrineMongoDBExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']) {
Expand Down
13 changes: 8 additions & 5 deletions Tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public function testFullConfiguration(array $config): void
'enabled' => true,
'pretty' => false,
],
'use_transactional_flush' => false,
],
'dm2' => [
'connection' => 'dm2_connection',
Expand All @@ -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'],
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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],
],
],
];
Expand Down Expand Up @@ -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],
],
],
];
Expand Down Expand Up @@ -435,6 +437,7 @@ public static function provideNormalizeOptions(): array
'profiler' => ['enabled' => '%kernel.debug%', 'pretty' => '%kernel.debug%'],
'auto_mapping' => false,
'filters' => [],
'use_transactional_flush' => false,
],
],
],
Expand Down
40 changes: 40 additions & 0 deletions Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
}
}

0 comments on commit 21d6ef8

Please sign in to comment.