diff --git a/DependencyInjection/DoctrineExtension.php b/DependencyInjection/DoctrineExtension.php index b5fa3dd96..7515ea151 100644 --- a/DependencyInjection/DoctrineExtension.php +++ b/DependencyInjection/DoctrineExtension.php @@ -387,6 +387,7 @@ protected function getConnectionOptions($connection) 'profiling' => true, 'mapping_types' => true, 'platform_service' => true, + 'shardManagerClass' => true, ]; foreach ($options as $key => $value) { if (isset($nonRewrittenKeys[$key])) { diff --git a/Tests/DependencyInjection/DoctrineExtensionTest.php b/Tests/DependencyInjection/DoctrineExtensionTest.php index 9f2c0f1ee..712e57e5c 100644 --- a/Tests/DependencyInjection/DoctrineExtensionTest.php +++ b/Tests/DependencyInjection/DoctrineExtensionTest.php @@ -7,6 +7,8 @@ use Doctrine\Bundle\DoctrineBundle\Tests\Builder\BundleConfigurationBuilder; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver\Connection as DriverConnection; +use Doctrine\DBAL\Sharding\PoolingShardManager; +use Doctrine\DBAL\Sharding\SQLAzure\SQLAzureShardManager; use Doctrine\ORM\EntityManagerInterface; use InvalidArgumentException; use LogicException; @@ -975,8 +977,9 @@ public static function cacheConfigurationProvider(): array public function testShardManager(): void { - $container = $this->getContainer(); - $extension = new DoctrineExtension(); + $container = $this->getContainer(); + $extension = new DoctrineExtension(); + $managerClass = SQLAzureShardManager::class; $config = BundleConfigurationBuilder::createBuilder() ->addConnection([ @@ -987,6 +990,12 @@ public function testShardManager(): void ], ], 'bar' => [], + 'baz' => [ + 'shards' => [ + 'test' => ['id' => 1], + ], + 'shard_manager_class' => $managerClass, + ], ], ]) ->build(); @@ -995,6 +1004,13 @@ public function testShardManager(): void $this->assertTrue($container->hasDefinition('doctrine.dbal.foo_shard_manager')); $this->assertFalse($container->hasDefinition('doctrine.dbal.bar_shard_manager')); + $this->assertTrue($container->hasDefinition('doctrine.dbal.baz_shard_manager')); + + $fooManagerDef = $container->getDefinition('doctrine.dbal.foo_shard_manager'); + $bazManagerDef = $container->getDefinition('doctrine.dbal.baz_shard_manager'); + + $this->assertEquals(PoolingShardManager::class, $fooManagerDef->getClass()); + $this->assertEquals($managerClass, $bazManagerDef->getClass()); } private function getContainer($bundles = 'YamlBundle', $vendor = null): ContainerBuilder