From 6026f742086a16f5e0439efce9404afd4f13fdc0 Mon Sep 17 00:00:00 2001 From: Stephan Vock Date: Tue, 5 Apr 2022 14:44:35 +0100 Subject: [PATCH] Logging: allow disabling logging for all connections --- Resources/config/middlewares.xml | 1 - .../DoctrineExtensionTest.php | 29 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Resources/config/middlewares.xml b/Resources/config/middlewares.xml index f1c0d1f2f..a0d408c52 100644 --- a/Resources/config/middlewares.xml +++ b/Resources/config/middlewares.xml @@ -8,7 +8,6 @@ - diff --git a/Tests/DependencyInjection/DoctrineExtensionTest.php b/Tests/DependencyInjection/DoctrineExtensionTest.php index e9da37289..fe5881001 100644 --- a/Tests/DependencyInjection/DoctrineExtensionTest.php +++ b/Tests/DependencyInjection/DoctrineExtensionTest.php @@ -1223,6 +1223,35 @@ public function testDefinitionsToLogQueries(bool $withMiddleware, bool $loggerIn $this->assertFalse(in_array(['connection' => 'conn2'], $middleWareTagAttributes, true), 'Tag with connection conn2 found'); } + public function testDefinitionsToLogQueriesLoggingFalse(): void + { + /** @psalm-suppress UndefinedClass */ + if (! class_exists(Middleware::class)) { + $this->markTestSkipped(sprintf('%s needs %s to not exist', __METHOD__, Middleware::class)); + } + + $container = $this->getContainer(); + $extension = new DoctrineExtension(); + + $config = BundleConfigurationBuilder::createBuilderWithBaseValues() + ->addConnection([ + 'connections' => [ + 'conn' => [ + 'password' => 'foo', + 'logging' => false, + ], + ], + ]) + ->addBaseEntityManager() + ->build(); + + $extension->load([$config], $container); + + $this->assertTrue($container->hasDefinition('doctrine.dbal.logging_middleware')); + $abstractMiddlewareDefTags = $container->getDefinition('doctrine.dbal.logging_middleware')->getTags(); + $this->assertArrayNotHasKey('doctrine.middleware', $abstractMiddlewareDefTags); + } + // phpcs:enable /** @param list $bundles */