-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Messenger: validate options for AMQP and Redis Connections #34925
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
Messenger: validate options for AMQP and Redis Connections #34925
Conversation
src/Symfony/Component/Messenger/Transport/RedisExt/Connection.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Messenger/Tests/Transport/AmqpExt/AmqpTransportFactoryTest.php
Outdated
Show resolved
Hide resolved
Can you please add an entry to |
@chalasr done |
Tests need to use @expectedDeprecation
instead of expectedException
indeed, i had to update tests |
I don't know where this error comes from in appveyor:
i guess because redis is unreachable on app veryor, but, even if i add an assertion in the test, i still get the error |
@nikophil The mentioned failure seems to be gone. Can you rebase to see tests green? |
i've done that sooner this morning, but still see the failure on app veyor + some new errors in travis which are not related to this PR |
Ok thanks, I'm looking at it. |
@@ -155,6 +217,30 @@ public static function fromDsn(string $dsn, array $options = [], AmqpFactory $am | |||
return new self($amqpOptions, $exchangeOptions, $queuesOptions, $amqpFactory); | |||
} | |||
|
|||
private static function validateOptions(array $options): void | |||
{ | |||
if (0 < \count($invalidOptions = array_diff(array_keys($options), self::AVAILABLE_OPTIONS))) { |
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.
Why not use option resolver component?
IMO the options resolver should indeed be used for this to not reinvent the wheel. |
ok, i'm gonna do that 👍 |
@Tobion @Nyholm i've started to work on the usage of an option resolver, but it seems that's not the good solution, because we want to only deprecate the use of invalid options (look at this resolved comment). But I wanted to replace my $resolver = new OptionsResolver();
self::configureOptions($resolver);
try {
$amqpOptions = $resolver->resolve($options);
} catch (OptionResolverInvalidArgumentException $exception) {
@trigger_error($exception->getMessage()."\nPassing invalid options is deprecated since Symfony 5.1.", E_USER_DEPRECATED);
} but this would lead to WDYT? |
You should still define deprecated options as valid. Then after you do the option resolver validation, you can check if the deprecated options were used. |
The actual problem is not to define some known options as deprecated, but to deprecate the use of any invalid option which we can't know in advance... i think this behavior does not exist in option resolver |
Oh, sorry that is right.. We currently allow all options, and you want do deprecate all but a few named... Hm... Could we do a hack? (Or do we want to do a hack?)
That would always deprecate options that are not valid, right? |
haha, this seems terribly hacky! that would definitely work, but because i'll do some i'll follow your decision ;) |
Given the current implementation works, I’d not try to « hijack » the option-resolver here. |
I agree with Robin. |
it would have been nice to use the option resolver here. This have to be done in the 6.0 version! |
Yeah. =) Could you rebase the PR? Most of these files has been moved to Messenger\Bridge |
yep i was doing that right now ;) |
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.
Just a small thing
@@ -7,6 +7,7 @@ CHANGELOG | |||
* Moved AmqpExt transport to package `symfony/amqp-messenger`. All classes in `Symfony\Component\Messenger\Transport\AmqpExt` have been moved to `Symfony\Component\Messenger\Bridge\Amqp\Transport` | |||
* Moved Doctrine transport to package `symfony/doctrine-messenger`. All classes in `Symfony\Component\Messenger\Transport\Doctrine` have been moved to `Symfony\Component\Messenger\Bridge\Doctrine\Transport` | |||
* Moved RedisExt transport to package `symfony/redis-messenger`. All classes in `Symfony\Component\Messenger\Transport\RedisExt` have been moved to `Symfony\Component\Messenger\Bridge\Redis\Transport` | |||
* Deprecated use of invalid options in Redis and AMQP connections. |
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.
You dont need to add this changelog here. The Redis and AMQP have a separate changelog.
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've split this one between amqp & redis' changelogs
Wait! Now that we moved transports to separate packages, do we really care about providing an upgrade path here? I mean, can't we only patch the new transports and make them throw directly in case of unknown options instead of triggering deprecation notices? Note that this question applies to any change that has BC concerns for 5.1 features on messenger transports, do we want to introduce the new packages with deprecations? EDIT: Not relevant as per #34925 (comment). |
No, sorry. |
@Nyholm Right, thank you. |
it seems ok, but i don't know why the deprecation tests fails... where is coming from this weird
it's on Travis, but i've got that in local as well |
…eprecations (chalasr) This PR was merged into the 3.4 branch. Discussion ---------- [PhpUnitBridge] Fix running skipped tests expecting only deprecations | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - If a test class has unsatisfied `@requires` and contains test methods expecting deprecation only, you get: > Fatal error: Uncaught Error: Call to a member function beStrictAboutTestsThatDoNotTestAnything() on null in ./symfony/symfony-dev/vendor/symfony/phpunit-bridge/Legacy/SymfonyTestsListenerTrait.php:229 Spotted in #34925's build. Commits ------- 6b02362 [Phpunit] Fix running skipped tests expecting only deprecations
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.
Just rebased and fixed tests. 👍
Thank you @nikophil. |
This does not seem to respect the options forwarded to the amqp ext, see #37618 |
This PR validates options for AMQP and Redis connections.
Regarding AMQP, I've merged symfony's specific options (
exchange
,delay
...) with the ones available in the AMQP Extension and i've enhanced the phpdoc with the one found here