-
-
Notifications
You must be signed in to change notification settings - Fork 474
feat: add logging middleware registration per connection with logger service #2156
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
Open
shakaran
wants to merge
8
commits into
doctrine:3.1.x
Choose a base branch
from
shakaran:feat/issue-1697-doctrine-loggin-middleware
base: 3.1.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+99
−5
Open
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e65b266
feat: add logging middleware registration per connection with logger …
shakaran a5456ac
fix: coding standard with phpcbf
shakaran 1aafca1
fix: add logger for phpunit tests
shakaran 9c72fc3
feat: move bwloe code and remove connName in channel
shakaran bab865a
feat: update test with moving code below
shakaran 03dde76
fix: remove variable no needed
shakaran 30d17ab
fix: preserve old legacy behaviour
shakaran 508856f
fix: reverse the tests to changed behaviour
shakaran File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1064,6 +1064,8 @@ public function testAsDoctrineListenerAttribute(): void | |
| public function testRegistrationsWithMiddlewaresAndSfDebugMiddleware(): void | ||
| { | ||
| $container = $this->getContainer(); | ||
| // Register a dummy logger service to enable logging middleware registration | ||
| $container->setDefinition('logger', (new Definition('\stdClass'))->setPublic(true)); | ||
|
Comment on lines
+1067
to
+1068
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see why are these needed. Probably because of my other comment. |
||
| $extension = new DoctrineExtension(); | ||
|
|
||
| $config = BundleConfigurationBuilder::createBuilder() | ||
|
|
@@ -1133,6 +1135,8 @@ public function testRegistrationsWithMiddlewaresAndSfDebugMiddleware(): void | |
| public function testDefinitionsToLogAndProfile(): void | ||
| { | ||
| $container = $this->getContainer(); | ||
| // Register a dummy logger service to enable logging middleware registration | ||
| $container->setDefinition('logger', (new Definition('\stdClass'))->setPublic(true)); | ||
| $extension = new DoctrineExtension(); | ||
|
|
||
| $config = BundleConfigurationBuilder::createBuilder() | ||
|
|
@@ -1206,6 +1210,84 @@ public function testDefinitionsToLogQueriesLoggingFalse(): void | |
| $this->assertArrayNotHasKey('doctrine.middleware', $abstractMiddlewareDefTags); | ||
| } | ||
|
|
||
| public function testLoggingMiddlewarePerConnectionWithLoggerPresent(): void | ||
| { | ||
| $container = $this->getContainer(); | ||
| // Register a dummy logger service to enable logging middleware registration | ||
| $container->setDefinition('logger', (new Definition('\stdClass'))->setPublic(true)); | ||
|
|
||
| $extension = new DoctrineExtension(); | ||
|
|
||
| $config = BundleConfigurationBuilder::createBuilder() | ||
| ->addConnection([ | ||
| 'connections' => [ | ||
| 'conn1' => [ | ||
| 'password' => 'foo', | ||
| 'logging' => true, | ||
| 'profiling' => false, | ||
| ], | ||
| 'conn2' => [ | ||
| 'password' => 'bar', | ||
| 'logging' => true, | ||
| 'profiling' => false, | ||
| ], | ||
| ], | ||
| ]) | ||
| ->build(); | ||
|
|
||
| $extension->load([$config], $container); | ||
|
|
||
| // Abstract definition should be present and tagged per connection | ||
| $this->assertTrue($container->hasDefinition('doctrine.dbal.logging_middleware')); | ||
| $abstractTags = $container->getDefinition('doctrine.dbal.logging_middleware')->getTags(); | ||
| $this->assertArrayHasKey('doctrine.middleware', $abstractTags); | ||
| $this->assertContains(['connection' => 'conn1', 'priority' => 10], $abstractTags['doctrine.middleware']); | ||
| $this->assertContains(['connection' => 'conn2', 'priority' => 10], $abstractTags['doctrine.middleware']); | ||
|
|
||
| // Child services should be created per connection with proper tags | ||
| $this->assertTrue($container->hasDefinition('doctrine.dbal.logging_middleware.conn1')); | ||
| $this->assertTrue($container->hasDefinition('doctrine.dbal.logging_middleware.conn2')); | ||
|
|
||
| $child1Tags = $container->getDefinition('doctrine.dbal.logging_middleware.conn1')->getTags(); | ||
| $child2Tags = $container->getDefinition('doctrine.dbal.logging_middleware.conn2')->getTags(); | ||
|
|
||
| $this->assertArrayHasKey('doctrine.middleware', $child1Tags); | ||
| $this->assertContains(['connection' => 'conn1', 'priority' => 10], $child1Tags['doctrine.middleware']); | ||
| $this->assertArrayNotHasKey('monolog.logger', $child1Tags); | ||
|
|
||
| $this->assertArrayHasKey('doctrine.middleware', $child2Tags); | ||
| $this->assertContains(['connection' => 'conn2', 'priority' => 10], $child2Tags['doctrine.middleware']); | ||
| $this->assertArrayNotHasKey('monolog.logger', $child2Tags); | ||
| } | ||
|
|
||
| public function testLoggingMiddlewareNotRegisteredWithoutLogger(): void | ||
| { | ||
| $container = $this->getContainer(); | ||
| // No logger service defined here | ||
|
|
||
| $extension = new DoctrineExtension(); | ||
|
|
||
| $config = BundleConfigurationBuilder::createBuilder() | ||
| ->addConnection([ | ||
| 'connections' => [ | ||
| 'conn1' => [ | ||
| 'password' => 'foo', | ||
| 'logging' => true, | ||
| 'profiling' => false, | ||
| ], | ||
| ], | ||
| ]) | ||
| ->build(); | ||
|
|
||
| $extension->load([$config], $container); | ||
|
|
||
| // Abstract definition exists by default, but should not be tagged nor should child definitions exist | ||
| $this->assertTrue($container->hasDefinition('doctrine.dbal.logging_middleware')); | ||
| $abstractTags = $container->getDefinition('doctrine.dbal.logging_middleware')->getTags(); | ||
| $this->assertArrayNotHasKey('doctrine.middleware', $abstractTags); | ||
| $this->assertFalse($container->hasDefinition('doctrine.dbal.logging_middleware.conn1')); | ||
| } | ||
|
|
||
| #[RequiresMethod(Driver::class, '__construct')] | ||
| public function testDefinitionsIdleConnection(): void | ||
| { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be moved below? Otherwise doctrine.middleware tag is not being added to logging middleware
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 9c72fc3 and bab865a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not really solved. Line 1475 is still skipped if logger doesn't exist, while that is not the case without this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, should be resolved now at 30d17ab