Skip to content

Commit

Permalink
Fix doctrine#1314, shard manager class option cannot be overridden
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberemissary committed Mar 30, 2021
1 parent 70be9d4 commit f331da8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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])) {
Expand Down
20 changes: 18 additions & 2 deletions Tests/DependencyInjection/DoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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([
Expand All @@ -987,6 +990,12 @@ public function testShardManager(): void
],
],
'bar' => [],
'baz' => [
'shards' => [
'test' => ['id' => 1],
],
'shard_manager_class' => $managerClass,
],
],
])
->build();
Expand All @@ -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
Expand Down

0 comments on commit f331da8

Please sign in to comment.