From 187fc88a38f64f668e3bf9d1dc7b142312d2fc52 Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Wed, 13 Dec 2023 21:54:05 +0100 Subject: [PATCH] Remove unused and .class parameters --- .../DoctrineMongoDBExtension.php | 12 +++--- Resources/config/mongodb.php | 15 +------ .../AbstractMongoDBExtensionTestCase.php | 39 +++++++++---------- 3 files changed, 27 insertions(+), 39 deletions(-) diff --git a/DependencyInjection/DoctrineMongoDBExtension.php b/DependencyInjection/DoctrineMongoDBExtension.php index 14e1ba48..62a9fd83 100644 --- a/DependencyInjection/DoctrineMongoDBExtension.php +++ b/DependencyInjection/DoctrineMongoDBExtension.php @@ -17,8 +17,10 @@ use Doctrine\Common\Cache\RedisCache; use Doctrine\Common\DataFixtures\Loader as DataFixturesLoader; use Doctrine\Common\EventSubscriber; +use Doctrine\ODM\MongoDB\Configuration as MongoDBConfiguration; use Doctrine\ODM\MongoDB\DocumentManager; use InvalidArgumentException; +use MongoDB\Client; use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension; use Symfony\Bridge\Doctrine\Messenger\DoctrineClearEntityManagerWorkerSubscriber; use Symfony\Component\Cache\Adapter\ApcuAdapter; @@ -229,7 +231,7 @@ protected function loadDocumentManager(array $documentManager, $defaultDM, $defa $configurationId = sprintf('doctrine_mongodb.odm.%s_configuration', $documentManager['name']); $defaultDatabase = $documentManager['database'] ?? $defaultDB; - $odmConfigDef = new Definition('%doctrine_mongodb.odm.configuration.class%'); + $odmConfigDef = new Definition(MongoDBConfiguration::class); $odmConfigDef->addTag(self::CONFIGURATION_TAG); $container->setDefinition( $configurationId, @@ -318,8 +320,8 @@ protected function loadDocumentManager(array $documentManager, $defaultDM, $defa // Document managers will share their connection's event manager new Reference(sprintf('doctrine_mongodb.odm.%s_connection.event_manager', $connectionName)), ]; - $odmDmDef = new Definition('%doctrine_mongodb.odm.document_manager.class%', $odmDmArgs); - $odmDmDef->setFactory(['%doctrine_mongodb.odm.document_manager.class%', 'create']); + $odmDmDef = new Definition(DocumentManager::class, $odmDmArgs); + $odmDmDef->setFactory([DocumentManager::class, 'create']); $odmDmDef->addTag('doctrine_mongodb.odm.document_manager'); $odmDmDef->setPublic(true); @@ -363,7 +365,7 @@ protected function loadConnections(array $connections, ContainerBuilder $contain $configurationId = sprintf('doctrine_mongodb.odm.%s_configuration', $name); $container->setDefinition( $configurationId, - new Definition('%doctrine_mongodb.odm.configuration.class%'), + new Definition(MongoDBConfiguration::class), ); $odmConnArgs = [ @@ -373,7 +375,7 @@ protected function loadConnections(array $connections, ContainerBuilder $contain $this->normalizeDriverOptions($connection), ]; - $odmConnDef = new Definition('%doctrine_mongodb.odm.connection.class%', $odmConnArgs); + $odmConnDef = new Definition(Client::class, $odmConnArgs); $odmConnDef->setPublic(true); $id = sprintf('doctrine_mongodb.odm.%s_connection', $name); $container->setDefinition($id, $odmConnDef); diff --git a/Resources/config/mongodb.php b/Resources/config/mongodb.php index 932f9509..16c36cb0 100644 --- a/Resources/config/mongodb.php +++ b/Resources/config/mongodb.php @@ -7,12 +7,10 @@ use Doctrine\Bundle\MongoDBBundle\ManagerRegistry; use Doctrine\Bundle\MongoDBBundle\Mapping\Driver\XmlDriver; use Doctrine\Bundle\MongoDBBundle\Repository\ContainerRepositoryFactory; -use Doctrine\ODM\MongoDB\Configuration; use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\ODM\MongoDB\Mapping\Driver\AttributeDriver; use Doctrine\ODM\MongoDB\Tools\ResolveTargetDocumentListener; use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; -use MongoDB\Client; use ProxyManager\Proxy\GhostObjectInterface; use Symfony\Bridge\Doctrine\ContainerAwareEventManager; use Symfony\Bridge\Doctrine\Security\User\EntityUserProvider; @@ -31,18 +29,9 @@ ->set('doctrine_mongodb.odm.cache.memcache_port', 11211) ->set('doctrine_mongodb.odm.cache.memcache_instance.class', 'Memcache') ->set('doctrine_mongodb.odm.cache.xcache.class', 'Doctrine\Common\Cache\XcacheCache') - ->set('doctrine_mongodb.odm.connection.class', Client::class) - ->set('doctrine_mongodb.odm.configuration.class', Configuration::class) - ->set('doctrine_mongodb.odm.document_manager.class', DocumentManager::class) - ->set('doctrine_mongodb.odm.manager_configurator.class', ManagerConfigurator::class) - ->set('doctrine_mongodb.odm.class', ManagerRegistry::class) ->set('doctrine_mongodb.odm.metadata.driver_chain.class', MappingDriverChain::class) ->set('doctrine_mongodb.odm.metadata.attribute.class', AttributeDriver::class) - ->set('doctrine_mongodb.odm.metadata.xml.class', XmlDriver::class) - ->set('doctrine_mongodb.odm.mapping_dirs', []) - ->set('doctrine_mongodb.odm.xml_mapping_dirs', '%doctrine_mongodb.odm.mapping_dirs%') - ->set('doctrine_mongodb.odm.document_dirs', []) - ->set('doctrine_mongodb.odm.fixtures_dirs', []); + ->set('doctrine_mongodb.odm.metadata.xml.class', XmlDriver::class); $containerConfigurator->services() @@ -73,7 +62,7 @@ service('doctrine_mongodb'), ]) - ->set('doctrine_mongodb', '%doctrine_mongodb.odm.class%') + ->set('doctrine_mongodb', ManagerRegistry::class) ->public() ->args([ 'MongoDB', diff --git a/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php b/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php index c4a4ac46..889f8828 100644 --- a/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php +++ b/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php @@ -49,9 +49,6 @@ public function testDependencyInjectionConfigurationDefaults(): void $loader->load(DoctrineMongoDBExtensionTest::buildConfiguration(), $container); - $this->assertEquals(Client::class, $container->getParameter('doctrine_mongodb.odm.connection.class')); - $this->assertEquals(Configuration::class, $container->getParameter('doctrine_mongodb.odm.configuration.class')); - $this->assertEquals(DocumentManager::class, $container->getParameter('doctrine_mongodb.odm.document_manager.class')); $this->assertEquals('MongoDBODMProxies', $container->getParameter('doctrine_mongodb.odm.proxy_namespace')); $this->assertEquals(Configuration::AUTOGENERATE_EVAL, $container->getParameter('doctrine_mongodb.odm.auto_generate_proxy_classes')); $this->assertEquals(ArrayCache::class, $container->getParameter('doctrine_mongodb.odm.cache.array.class')); @@ -77,7 +74,7 @@ public function testDependencyInjectionConfigurationDefaults(): void $this->assertEquals(true, $container->getParameter('doctrine_mongodb.odm.auto_generate_proxy_classes')); $definition = $container->getDefinition('doctrine_mongodb.odm.default_connection'); - $this->assertEquals('%doctrine_mongodb.odm.connection.class%', $definition->getClass()); + $this->assertEquals(Client::class, $definition->getClass()); $arguments = $definition->getArguments(); $this->assertEquals(null, $arguments[0]); @@ -86,8 +83,8 @@ public function testDependencyInjectionConfigurationDefaults(): void $this->assertSame(['root' => 'array', 'document' => 'array'], $arguments[2]['typeMap']); $definition = $container->getDefinition('doctrine_mongodb.odm.default_document_manager'); - $this->assertEquals('%doctrine_mongodb.odm.document_manager.class%', $definition->getClass()); - $this->assertEquals(['%doctrine_mongodb.odm.document_manager.class%', 'create'], $definition->getFactory()); + $this->assertEquals(DocumentManager::class, $definition->getClass()); + $this->assertEquals([DocumentManager::class, 'create'], $definition->getFactory()); $this->assertArrayHasKey('doctrine_mongodb.odm.document_manager', $definition->getTags()); $arguments = $definition->getArguments(); @@ -115,7 +112,7 @@ public function testSingleDocumentManagerConfiguration(): void $loader->load([$config], $container); $definition = $container->getDefinition('doctrine_mongodb.odm.default_connection'); - $this->assertEquals('%doctrine_mongodb.odm.connection.class%', $definition->getClass()); + $this->assertEquals(Client::class, $definition->getClass()); $arguments = $definition->getArguments(); $this->assertEquals('mongodb://localhost:27017', $arguments[0]); @@ -126,8 +123,8 @@ public function testSingleDocumentManagerConfiguration(): void $this->assertEquals(new Reference('my_context'), $arguments[2]['context']); $definition = $container->getDefinition('doctrine_mongodb.odm.default_document_manager'); - $this->assertEquals('%doctrine_mongodb.odm.document_manager.class%', $definition->getClass()); - $this->assertEquals(['%doctrine_mongodb.odm.document_manager.class%', 'create'], $definition->getFactory()); + $this->assertEquals(DocumentManager::class, $definition->getClass()); + $this->assertEquals([DocumentManager::class, 'create'], $definition->getFactory()); $this->assertArrayHasKey('doctrine_mongodb.odm.document_manager', $definition->getTags()); $arguments = $definition->getArguments(); @@ -150,7 +147,7 @@ public function testLoadSimpleSingleConnection(): void $container->compile(); $definition = $container->getDefinition('doctrine_mongodb.odm.default_connection'); - $this->assertEquals('%doctrine_mongodb.odm.connection.class%', $definition->getClass()); + $this->assertEquals(Client::class, $definition->getClass()); $arguments = $definition->getArguments(); $this->assertEquals('mongodb://localhost:27017', $arguments[0]); @@ -165,8 +162,8 @@ public function testLoadSimpleSingleConnection(): void $this->assertEquals('mydb', $methodCalls[$pos][1][0]); $definition = $container->getDefinition('doctrine_mongodb.odm.default_document_manager'); - $this->assertEquals('%doctrine_mongodb.odm.document_manager.class%', $definition->getClass()); - $this->assertEquals(['%doctrine_mongodb.odm.document_manager.class%', 'create'], $definition->getFactory()); + $this->assertEquals(DocumentManager::class, $definition->getClass()); + $this->assertEquals([DocumentManager::class, 'create'], $definition->getFactory()); $this->assertArrayHasKey('doctrine_mongodb.odm.document_manager', $definition->getTags()); $arguments = $definition->getArguments(); @@ -192,7 +189,7 @@ public function testLoadSingleConnection(): void $container->compile(); $definition = $container->getDefinition('doctrine_mongodb.odm.default_connection'); - $this->assertEquals('%doctrine_mongodb.odm.connection.class%', $definition->getClass()); + $this->assertEquals(Client::class, $definition->getClass()); $arguments = $definition->getArguments(); $this->assertEquals('mongodb://localhost:27017', $arguments[0]); @@ -201,8 +198,8 @@ public function testLoadSingleConnection(): void $this->assertSame(['root' => 'array', 'document' => 'array'], $arguments[2]['typeMap']); $definition = $container->getDefinition('doctrine_mongodb.odm.default_document_manager'); - $this->assertEquals('%doctrine_mongodb.odm.document_manager.class%', $definition->getClass()); - $this->assertEquals(['%doctrine_mongodb.odm.document_manager.class%', 'create'], $definition->getFactory()); + $this->assertEquals(DocumentManager::class, $definition->getClass()); + $this->assertEquals([DocumentManager::class, 'create'], $definition->getFactory()); $this->assertArrayHasKey('doctrine_mongodb.odm.document_manager', $definition->getTags()); $arguments = $definition->getArguments(); @@ -228,7 +225,7 @@ public function testLoadMultipleConnections(): void $container->compile(); $definition = $container->getDefinition('doctrine_mongodb.odm.conn1_connection'); - $this->assertEquals('%doctrine_mongodb.odm.connection.class%', $definition->getClass()); + $this->assertEquals(Client::class, $definition->getClass()); $arguments = $definition->getArguments(); $this->assertEquals('mongodb://localhost:27017', $arguments[0]); @@ -237,8 +234,8 @@ public function testLoadMultipleConnections(): void $this->assertSame(['root' => 'array', 'document' => 'array'], $arguments[2]['typeMap']); $definition = $container->getDefinition('doctrine_mongodb.odm.dm1_document_manager'); - $this->assertEquals('%doctrine_mongodb.odm.document_manager.class%', $definition->getClass()); - $this->assertEquals(['%doctrine_mongodb.odm.document_manager.class%', 'create'], $definition->getFactory()); + $this->assertEquals(DocumentManager::class, $definition->getClass()); + $this->assertEquals([DocumentManager::class, 'create'], $definition->getFactory()); $this->assertArrayHasKey('doctrine_mongodb.odm.document_manager', $definition->getTags()); $arguments = $definition->getArguments(); @@ -248,7 +245,7 @@ public function testLoadMultipleConnections(): void $this->assertEquals('doctrine_mongodb.odm.dm1_configuration', (string) $arguments[1]); $definition = $container->getDefinition('doctrine_mongodb.odm.conn2_connection'); - $this->assertEquals('%doctrine_mongodb.odm.connection.class%', $definition->getClass()); + $this->assertEquals(Client::class, $definition->getClass()); $arguments = $definition->getArguments(); $this->assertEquals('mongodb://localhost:27017', $arguments[0]); @@ -257,8 +254,8 @@ public function testLoadMultipleConnections(): void $this->assertSame(['root' => 'array', 'document' => 'array'], $arguments[2]['typeMap']); $definition = $container->getDefinition('doctrine_mongodb.odm.dm2_document_manager'); - $this->assertEquals('%doctrine_mongodb.odm.document_manager.class%', $definition->getClass()); - $this->assertEquals(['%doctrine_mongodb.odm.document_manager.class%', 'create'], $definition->getFactory()); + $this->assertEquals(DocumentManager::class, $definition->getClass()); + $this->assertEquals([DocumentManager::class, 'create'], $definition->getFactory()); $this->assertArrayHasKey('doctrine_mongodb.odm.document_manager', $definition->getTags()); $arguments = $definition->getArguments();