Skip to content

Commit

Permalink
Logging: allow disabling logging for all connections
Browse files Browse the repository at this point in the history
  • Loading branch information
glaubinix committed Apr 5, 2022
1 parent b700275 commit 6026f74
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
1 change: 0 additions & 1 deletion Resources/config/middlewares.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<service id="doctrine.dbal.logging_middleware" class="Doctrine\DBAL\Logging\Middleware" abstract="true">
<argument type="service" id="logger" />
<tag name="monolog.logger" channel="doctrine" />
<tag name="doctrine.middleware" />
</service>
</services>
</container>
29 changes: 29 additions & 0 deletions Tests/DependencyInjection/DoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> $bundles */
Expand Down

0 comments on commit 6026f74

Please sign in to comment.