-
Notifications
You must be signed in to change notification settings - Fork 30
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
Add an adapter to support the Symfony Mailer component and deprecate the Swiftmailer integration #102
Conversation
d99600f
to
628ca55
Compare
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.
Hello @mbabker, we can finally move forward with this one 🎉 I've left some comments, please, take a look at them. Do you think you would have some time to work on this PR in the nearest future, or should I take it over and finish the work? Thank you for your contribution! 🖖 🏅
0d6a673
to
4dd60bb
Compare
4dd60bb
to
c18092a
Compare
composer.json
Outdated
@@ -45,6 +45,8 @@ | |||
"phpunit/phpunit": "^9.4", | |||
"sylius-labs/coding-standard": "^4.0", | |||
"symfony/console": "^4.4 || ^5.4", | |||
"symfony/event-dispatcher": "^4.4 || ^5.4", |
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 event dispatcher is used in a few classes, but even for development, it was only installed through transient dependencies.
@@ -40,7 +40,7 @@ | |||
|
|||
<service id="sylius.email_renderer.adapter.abstract" class="Sylius\Component\Mailer\Renderer\Adapter\AbstractAdapter" abstract="true"> | |||
<call method="setEventDispatcher"> | |||
<argument type="service" id="event_dispatcher" /> | |||
<argument type="service" id="event_dispatcher" on-invalid="ignore" /> |
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.
This (and the change immediately below) ends up being a bug fix. The event dispatcher is an optional dependency in the classes that support it, yet compiling the container would fail hard if the dispatcher service isn't there. This ensures that the dispatcher stays optional.
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.
isn't on-invalid="null"? is this different?
I don't find any documentation about this value.
https://symfony.com/doc/current/service_container/optional_dependencies.html
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 the “ignoring missing dependencies” section on that page.
The null behavior is valid if you’re working with a nullable argument. The $dispatcher
argument on the abstract adapter’s setEventDispatcher()
method is not nullable, so the invalid behavior is the right behavior for this case (which means it just won’t be called).
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.
oh yes, I just had not seen it was with a call method, excuxe me.
6b7a3cb
to
22a6c57
Compare
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.
0594f68
to
ad5eaf1
Compare
I believe it still has some problems :D Let's take a look at this build (this PR enhanced with additional steps in the build): https://github.com/Zales0123/SyliusMailerBundle/runs/6384899456?check_suite_focus=true As I said, we need a few different cases covered with the test application:
The alternative is to require cc @loic425 @lchrusciel I need you opinions :) |
d2c5925
to
26d2ccc
Compare
26d2ccc
to
df91db8
Compare
The build setup you used won't work. The To simplify testing, I've reworked things again to use feature detection though On a side note, trying to do the entire CI in one build is rather limiting. By my count, there should be at least four separate workflows (Psalm and PHPStan as separate jobs in one workflow, code style checks in another workflow, PHPSpec in a 3rd workflow, and PHPUnit in a 4th). This would ensure that the entirety of the CI suite runs on every build instead of half of it not even running because of a code style issue somewhere in the package. You also wouldn't need things like the four separate |
Thank you for the clarification, I agree 👍 I've checked a few cases with the current state of PR on Sylius (I assumed swiftmailer is always installed via composer, as it's provided by Sylius itself):
Can you please check out scenario 3? it can happen when one has a Sylius application with swiftmailer adapter configured (even though it's the default one), updates the mailer bundle and sees the exception (as there is a service created that has a dependency to Symfony Mailer probably). cc @loic425 @lchrusciel I still need your eye on it as well 😄 Regarding the test suite - I totally agree, that we should refactor it to multiple builds 👍 The proposed suite was just for now 🖖 |
rm -rf src/Bundle/test/var/cache | ||
mv src/Bundle/test/config/packages/mailer.yaml mailer.yaml | ||
composer remove symfony/mailer --dev | ||
(cd src/Bundle/test && bin/console lint:container) |
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.
if we keep this test suite this way for a moment, I think we have to add composer require --dev symfony/mailer
at the end
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’m not following what it is you’re suggesting to do. The order of operations for all the Composer commands is fine as is, there is no point in doing a full reset to the starting state at the end of each lint step (everything a step is doing is building off the state the previous step left things in).
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 think depending on a previous one is a little bit risky. On resource bundle, we do that : https://github.com/Sylius/SyliusResourceBundle/blob/1.10/.github/workflows/build.yml#L106
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.
By that same logic, you can’t rely on the previous steps to have set up the environment correctly either 😉 (if these were parallel or separately running jobs it’d be another story, but it’s a single threaded build).
The only difference in workflows is where certain commands are run, and running less Composer commands overall since each step builds on the previous.
…the Swiftmailer integration Co-authored-by: Michael Babker <[email protected]>
df91db8
to
e9862b2
Compare
I've taken the feature detection around the services as far as I can sanely take it. |
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 also checked all scenarios described here with this implementation and it seems to work like a charm ✨ 🎉
->shouldBeCalled() | ||
; | ||
|
||
$mailer->send(Argument::type(Email::class))->shouldBeCalled(); |
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 could work a little bit at this prophecy to check the Email content as well 🖖
What an adventure! 🎉 Thank you, @mbabker, for this amazing work 🥇 |
Replaces #18