Skip to content

[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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2018

Conversation

yceruto
Copy link
Member

@yceruto yceruto commented Apr 13, 2018

Q A
Branch? master
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

@yceruto yceruto force-pushed the messenger/logging_middleware branch 6 times, most recently from a35bbe2 to 0f87c02 Compare April 13, 2018 04:45
@@ -49,10 +49,6 @@ public function process(ContainerBuilder $container)
return;
}

if (!$container->getParameter('kernel.debug') || !$container->has('logger')) {
$container->removeDefinition('messenger.middleware.debug.logging');
}
Copy link
Member Author

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 to FrameworkExtension 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",
Copy link
Member Author

@yceruto yceruto Apr 13, 2018

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')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the !$container->hasAlias('logger') part could be removed, as the Fwb always registers a default logger implementation since #24300

But anyway that'll be handled differently with #26864 as it'll have to be opt-in explicitly.

Copy link
Contributor

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 :)

Copy link
Contributor

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 a logger alias declared by the monolog bundle or the kernel LoggerPass, so it's wrong. But as stated above, this check is not necessary anyway, as there will always be a logger 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.

Copy link
Member Author

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')) {
Copy link
Contributor

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);
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@yceruto yceruto force-pushed the messenger/logging_middleware branch 2 times, most recently from 462ca65 to dafd241 Compare April 13, 2018 14:22
@yceruto
Copy link
Member Author

yceruto commented Apr 13, 2018

@ogizanagi the tests fail again, I guess LoggerPass is processed after MessengerPass? or not?

$container->addCompilerPass(new LoggerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -32);

Any suggestions?

@ogizanagi
Copy link
Contributor

@yceruto : IIUC, the FrameworkExtensionTest does not build the FrameworkBundle, so compiler passes like the LoggerPass registered in the fwb are never processed.

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.

@yceruto yceruto force-pushed the messenger/logging_middleware branch 7 times, most recently from 45ca387 to ecdb38c Compare April 13, 2018 17:09
@@ -52,7 +52,7 @@

<!-- Logging & Debug -->
<service id="messenger.middleware.debug.logging" class="Symfony\Component\Messenger\Debug\LoggingMiddleware">
Copy link
Member Author

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 in MessengerPass, only if debug and logger are enabled/exists, wdyt?

Copy link
Contributor

@ogizanagi ogizanagi Apr 14, 2018

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.

@nicolas-grekas nicolas-grekas added this to the 4.1 milestone Apr 14, 2018
nicolas-grekas
nicolas-grekas approved these changes Apr 14, 2018
Copy link
Member

@nicolas-grekas nicolas-grekas left a 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.

@yceruto yceruto force-pushed the messenger/logging_middleware branch from ecdb38c to eedad4c Compare April 14, 2018 17:36
@yceruto
Copy link
Member Author

yceruto commented Apr 14, 2018

Done! (failures are unrelated)

Status: Needs Review

@sroze
Copy link
Contributor

sroze commented Apr 15, 2018

Thank you @yceruto.

@sroze sroze merged commit eedad4c into symfony:master Apr 15, 2018
sroze added a commit that referenced this pull request Apr 15, 2018
…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
@yceruto yceruto deleted the messenger/logging_middleware branch April 16, 2018 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants