Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[Messenger] Testing LoggingMiddleware and minor improvements#26912
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
a35bbe2
to0f87c02
Compare@@ -49,10 +49,6 @@ public function process(ContainerBuilder $container) | |||
return; | |||
} | |||
if (!$container->getParameter('kernel.debug') || !$container->has('logger')) { | |||
$container->removeDefinition('messenger.middleware.debug.logging'); | |||
} |
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.
I needed move this part toFrameworkExtension
to make tests pass (see old failures)
"symfony/serializer": "~3.4|~4.0", | ||
"symfony/dependency-injection": "~3.4.6|~4.0", | ||
"symfony/http-kernel": "~3.4|~4.0", | ||
"symfony/property-access": "~3.4|~4.0", | ||
"symfony/var-dumper": "~3.4|~4.0", | ||
"symfony/property-access": "~3.4|~4.0", |
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.
Removing as duplicated entry (unrelated change)
@@ -1446,6 +1446,10 @@ private function registerMessengerConfiguration(array $config, ContainerBuilder | |||
$loader->load('messenger.xml'); | |||
if (!$container->getParameter('kernel.debug') || !$container->hasAlias('logger')) { |
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.
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.
AFAIK doing so will always remove the middleware. I don't see any value in changing what was just changed in#26896 :)
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.
The!$container->hasAlias('logger')
check in the fwb extension will indeed lead to the middleware removal, even if there is in fact alogger
alias declared by the monolog bundle or the kernelLoggerPass
, so it's wrong. But as stated above, this check is not necessary anyway, as there will always be alogger
alias.
Regarding#26896 , I agree with@yceruto: It doesn't really make sense to me having a LoggingMiddleware without a hard logger dependency. It solves an issue we usually solve at compilation time by removing proper services.
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.
I'll try this again soon.
@@ -1446,6 +1446,10 @@ private function registerMessengerConfiguration(array $config, ContainerBuilder | |||
$loader->load('messenger.xml'); | |||
if (!$container->getParameter('kernel.debug') || !$container->hasAlias('logger')) { |
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.
AFAIK doing so will always remove the middleware. I don't see any value in changing what was just changed in#26896 :)
$next = $this->createPartialMock(\stdClass::class, array('__invoke')); | ||
$next->expects($this->once())->method('__invoke')->with($message); | ||
(new LoggingMiddleware($logger))->handle($message, $next); |
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.
Can you test that it returns the value returned by the previous middleware as well?
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.
462ca65
todafd241
Compareyceruto commentedApr 13, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@ogizanagi thetests fail again, I guess
Any suggestions? |
@yceruto : IIUC, the FrameworkExtensionTest does not build the FrameworkBundle, so compiler passes like the Anyway, you moved it back to the MessengerPass, so this check is kind of required here as you can theoretically use the pass shipped within the component out of the Fwb usage, just with DI. So, let's keep this check. |
45ca387
toecdb38c
Compare@@ -52,7 +52,7 @@ | |||
<!-- Logging & Debug --> | |||
<service id="messenger.middleware.debug.logging" class="Symfony\Component\Messenger\Debug\LoggingMiddleware"> |
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.
Another workaround could be creating from scratch this service definition inMessengerPass
, only if debug and logger are enabled/exists, wdyt?
ogizanagiApr 14, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
We usually try as much as possible to declare all services in xml files so everything is in one place, favoring discovery/inspections and allowing to jump from classes to definitions with the PhpStorm Symfony plugin.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
composer.json should be alpha ordered
could also validator+process work with 3.4? if yes, let's do the change here.
ecdb38c
toeedad4c
CompareDone! (failures are unrelated) Status: Needs Review |
Thank you@yceruto. |
…ents (yceruto)This PR was merged into the 4.1-dev branch.Discussion----------[Messenger] Testing LoggingMiddleware and minor improvements| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | -| License | MIT| Doc PR | -- This add tests for `LoggingMiddleware` class- Similar to [`translator.logging`](https://github.com/symfony/symfony/blob/6bbb5bcc5294fdd540bec35541f77b87e212fc5f/src/Symfony/Component/Translation/LoggingTranslator.php#L33) a logging service doesn't make sense without a [hard `logger` dependency](https://github.com/symfony/symfony/blob/6bbb5bcc5294fdd540bec35541f77b87e212fc5f/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml#L25-L29) and according to:https://github.com/symfony/symfony/blob/6bbb5bcc5294fdd540bec35541f77b87e212fc5f/src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php#L52-L54 it must be removed if `logger` alias doesn't exists.Commits-------eedad4c Make logger arg a hard dependency, remove dead code and add tests
Uh oh!
There was an error while loading.Please reload this page.
This add tests for
LoggingMiddleware
classSimilar to
translator.logging
a logging service doesn't make sense without ahardlogger
dependency and according to:symfony/src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php
Lines 52 to 54 in6bbb5bc
it must be removed if
logger
alias doesn't exists.