From 6868ce0c818a9191f91d07bb547e97884fd8af26 Mon Sep 17 00:00:00 2001 From: Markus Schmid Date: Tue, 19 Jul 2022 11:55:59 +0200 Subject: [PATCH 1/2] symfony config: allow null values for connection_factory_class and factory_service --- .../DependencyInjection/TransportFactory.php | 8 ++++---- .../DependencyInjection/TransportFactoryTest.php | 14 +++++++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/pkg/enqueue/Symfony/DependencyInjection/TransportFactory.php b/pkg/enqueue/Symfony/DependencyInjection/TransportFactory.php index 54dba4bf7..944b1a30d 100644 --- a/pkg/enqueue/Symfony/DependencyInjection/TransportFactory.php +++ b/pkg/enqueue/Symfony/DependencyInjection/TransportFactory.php @@ -132,15 +132,15 @@ public function buildConnectionFactory(ContainerBuilder $container, array $confi $container->register($factoryFactoryId, $config['factory_class'] ?? ConnectionFactoryFactory::class); $factoryFactoryService = new Reference( - array_key_exists('factory_service', $config) ? $config['factory_service'] : $factoryFactoryId + $config['factory_service'] ?? $factoryFactoryId ); unset($config['factory_service'], $config['factory_class']); - if (array_key_exists('connection_factory_class', $config)) { - $connectionFactoryClass = $config['connection_factory_class']; - unset($config['connection_factory_class']); + $connectionFactoryClass = $config['connection_factory_class'] ?? null; + unset($config['connection_factory_class']); + if (isset($connectionFactoryClass)) { $container->register($factoryId, $connectionFactoryClass) ->addArgument($config) ; diff --git a/pkg/enqueue/Tests/Symfony/DependencyInjection/TransportFactoryTest.php b/pkg/enqueue/Tests/Symfony/DependencyInjection/TransportFactoryTest.php index 68868716b..a4f9d451a 100644 --- a/pkg/enqueue/Tests/Symfony/DependencyInjection/TransportFactoryTest.php +++ b/pkg/enqueue/Tests/Symfony/DependencyInjection/TransportFactoryTest.php @@ -259,7 +259,14 @@ public function testShouldBuildConnectionFactoryFromDSN() $transport = new TransportFactory('default'); - $transport->buildConnectionFactory($container, ['dsn' => 'foo://bar/baz']); + $config = [ + 'dsn' => 'foo://bar/baz', + 'connection_factory_class' => null, + 'factory_service' => null, + 'factory_class' => null, + ]; + + $transport->buildConnectionFactory($container, $config); $this->assertTrue($container->hasDefinition('enqueue.transport.default.connection_factory')); @@ -272,6 +279,11 @@ public function testShouldBuildConnectionFactoryFromDSN() [['dsn' => 'foo://bar/baz']], $container->getDefinition('enqueue.transport.default.connection_factory')->getArguments()) ; + + $this->assertEquals( + [new Reference('enqueue.transport.default.connection_factory_factory'), 'create'], + $container->getDefinition('enqueue.transport.default.connection_factory')->getFactory()) + ; } public function testShouldBuildConnectionFactoryUsingCustomFactoryClass() From 66865187fe180396778b9f9b50b96e9a2a4a7590 Mon Sep 17 00:00:00 2001 From: Markus Schmid Date: Tue, 19 Jul 2022 12:20:29 +0200 Subject: [PATCH 2/2] remove duplicated test --- .../Symfony/DependencyInjection/TransportFactoryTest.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pkg/enqueue/Tests/Symfony/DependencyInjection/TransportFactoryTest.php b/pkg/enqueue/Tests/Symfony/DependencyInjection/TransportFactoryTest.php index a4f9d451a..c5ff1c818 100644 --- a/pkg/enqueue/Tests/Symfony/DependencyInjection/TransportFactoryTest.php +++ b/pkg/enqueue/Tests/Symfony/DependencyInjection/TransportFactoryTest.php @@ -279,11 +279,6 @@ public function testShouldBuildConnectionFactoryFromDSN() [['dsn' => 'foo://bar/baz']], $container->getDefinition('enqueue.transport.default.connection_factory')->getArguments()) ; - - $this->assertEquals( - [new Reference('enqueue.transport.default.connection_factory_factory'), 'create'], - $container->getDefinition('enqueue.transport.default.connection_factory')->getFactory()) - ; } public function testShouldBuildConnectionFactoryUsingCustomFactoryClass()