Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1314, shard manager class option cannot be overridden #1316

Merged
merged 1 commit into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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