From 4ef57b35c1a0dae25548b6a81c3a4dca1fb881d0 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Mon, 24 Jun 2024 19:55:59 +0200 Subject: [PATCH 1/2] Update tests to check the twig_symfony mailer config --- .../FOSUserExtensionTest.php | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/DependencyInjection/FOSUserExtensionTest.php b/tests/DependencyInjection/FOSUserExtensionTest.php index fc8e8df3d..adb074c81 100644 --- a/tests/DependencyInjection/FOSUserExtensionTest.php +++ b/tests/DependencyInjection/FOSUserExtensionTest.php @@ -100,14 +100,14 @@ public function testDisableRegistration() $loader->load([$config], $this->configuration); $this->assertNotHasDefinition('fos_user.registration.form.factory'); - $mailer = $this->configuration->getDefinition('fos_user.mailer.twig_swift'); + $mailer = $this->configuration->getDefinition('fos_user.mailer.twig_symfony'); $parameters = $this->configuration->getParameterBag()->resolveValue( $mailer->getArgument(3) ); $this->assertSame( [ - 'confirmation' => ['no-registration@acme.com' => 'Acme Ltd'], - 'resetting' => ['admin@acme.org' => 'Acme Corp'], + 'confirmation' => ['address' => 'no-registration@acme.com', 'sender_name' => 'Acme Ltd'], + 'resetting' => ['address' => 'admin@acme.org', 'sender_name' => 'Acme Corp'], ], $parameters['from_email'] ); @@ -122,14 +122,14 @@ public function testDisableResetting() $loader->load([$config], $this->configuration); $this->assertNotHasDefinition('fos_user.resetting.form.factory'); - $mailer = $this->configuration->getDefinition('fos_user.mailer.twig_swift'); + $mailer = $this->configuration->getDefinition('fos_user.mailer.twig_symfony'); $parameters = $this->configuration->getParameterBag()->resolveValue( $mailer->getArgument(3) ); $this->assertSame( [ - 'confirmation' => ['admin@acme.org' => 'Acme Corp'], - 'resetting' => ['no-resetting@acme.com' => 'Acme Ltd'], + 'confirmation' => ['address' => 'admin@acme.org', 'sender_name' => 'Acme Corp'], + 'resetting' => ['address' => 'no-resetting@acme.com', 'sender_name' => 'Acme Ltd'], ], $parameters['from_email'] ); @@ -166,8 +166,8 @@ public function testEmailsDisabledFeature($testConfig, $registration, $resetting $config = array_merge($config, $testConfig); $loader->load([$config], $this->configuration); - $this->assertParameter($registration, 'fos_user.registration.confirmation.from_email'); - $this->assertParameter($resetting, 'fos_user.resetting.email.from_email'); + $this->assertParameter($registration, 'fos_user.registration.confirmation.from_address'); + $this->assertParameter($resetting, 'fos_user.resetting.email.from_address'); } public function providerEmailsDisabledFeature() @@ -190,13 +190,13 @@ public function providerEmailsDisabledFeature() ], ]; - $default = ['admin@acme.org' => 'Acme Corp']; - $overriden = ['ltd@acme.com' => 'Acme Ltd']; + $default = ['address' => 'admin@acme.org', 'sender_name' => 'Acme Corp']; + $overriden = ['address' => 'ltd@acme.com', 'sender_name' => 'Acme Ltd']; return [ - [$configBothFeaturesDisabled, ['no-registration@acme.com' => 'Acme Ltd'], ['no-resetting@acme.com' => 'Acme Ltd']], - [$configResettingDisabled, $default, ['no-resetting@acme.com' => 'Acme Ltd']], - [$configRegistrationDisabled, ['no-registration@acme.com' => 'Acme Ltd'], $default], + [$configBothFeaturesDisabled, ['address' => 'no-registration@acme.com', 'sender_name' => 'Acme Ltd'], ['address' => 'no-resetting@acme.com', 'sender_name' => 'Acme Ltd']], + [$configResettingDisabled, $default, ['address' => 'no-resetting@acme.com', 'sender_name' => 'Acme Ltd']], + [$configRegistrationDisabled, ['address' => 'no-registration@acme.com', 'sender_name' => 'Acme Ltd'], $default], [$configOverridenRegistrationEmail, $overriden, $default], [$configOverridenResettingEmail, $default, $overriden], ]; @@ -289,10 +289,10 @@ public function testUserLoadConfirmationEmailWithDefaults() $this->createEmptyConfiguration(); $this->assertParameter(false, 'fos_user.registration.confirmation.enabled'); - $this->assertParameter(['admin@acme.org' => 'Acme Corp'], 'fos_user.registration.confirmation.from_email'); + $this->assertParameter(['address' => 'admin@acme.org', 'sender_name' => 'Acme Corp'], 'fos_user.registration.confirmation.from_address'); $this->assertParameter('@FOSUser/Registration/email.txt.twig', 'fos_user.registration.confirmation.template'); $this->assertParameter('@FOSUser/Resetting/email.txt.twig', 'fos_user.resetting.email.template'); - $this->assertParameter(['admin@acme.org' => 'Acme Corp'], 'fos_user.resetting.email.from_email'); + $this->assertParameter(['address' => 'admin@acme.org', 'sender_name' => 'Acme Corp'], 'fos_user.resetting.email.from_address'); $this->assertParameter(86400, 'fos_user.resetting.token_ttl'); } @@ -301,10 +301,10 @@ public function testUserLoadConfirmationEmail() $this->createFullConfiguration(); $this->assertParameter(true, 'fos_user.registration.confirmation.enabled'); - $this->assertParameter(['register@acme.org' => 'Acme Corp'], 'fos_user.registration.confirmation.from_email'); + $this->assertParameter(['address' => 'register@acme.org', 'sender_name' => 'Acme Corp'], 'fos_user.registration.confirmation.from_address'); $this->assertParameter('AcmeMyBundle:Registration:mail.txt.twig', 'fos_user.registration.confirmation.template'); $this->assertParameter('AcmeMyBundle:Resetting:mail.txt.twig', 'fos_user.resetting.email.template'); - $this->assertParameter(['reset@acme.org' => 'Acme Corp'], 'fos_user.resetting.email.from_email'); + $this->assertParameter(['address' => 'reset@acme.org', 'sender_name' => 'Acme Corp'], 'fos_user.resetting.email.from_address'); $this->assertParameter(7200, 'fos_user.resetting.retry_ttl'); } From 1bd8db5b6f646ad40ec457d685fcf2363afea992 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Tue, 25 Jun 2024 10:34:02 +0200 Subject: [PATCH 2/2] Deprecate the TwigSwiftMailer implementation --- Changelog.md | 4 ++++ docs/emails.rst | 2 +- src/DependencyInjection/Configuration.php | 12 +++++++++++- src/DependencyInjection/FOSUserExtension.php | 9 +++++++++ src/Mailer/TwigSwiftMailer.php | 2 ++ 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index 5686ac0b3..35d5b4916 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,10 @@ Changelog ========= +### 3.4.0 (2024-06-25) + +* Deprecated the TwigSwiftMailer implementation + ### 3.3.0 (2024-06-24) * Added a mailer implementation based on symfony/mailer and Twig diff --git a/docs/emails.rst b/docs/emails.rst index 1d75549db..1b1c84886 100644 --- a/docs/emails.rst +++ b/docs/emails.rst @@ -42,7 +42,7 @@ The bundle comes with 3 mailer implementations. They are listed below by service id: - ``fos_user.mailer.twig_symfony`` uses symfony/mailer to send emails and Twig blocks to render the message. -- ``fos_user.mailer.twig_swift`` uses Swiftmailer to send emails and Twig blocks to render the message. +- ``fos_user.mailer.twig_swift`` (deprecated) uses Swiftmailer to send emails and Twig blocks to render the message. - ``fos_user.mailer.noop`` is a mailer implementation which performs no operation, so no emails are sent. .. note:: diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 2dbd8e6cc..09a2951e4 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -223,7 +223,17 @@ private function addServiceSection(ArrayNodeDefinition $node): void ->arrayNode('service') ->addDefaultsIfNotSet() ->children() - ->scalarNode('mailer')->defaultNull()->end() + ->scalarNode('mailer') + ->defaultNull() + ->validate() + ->ifInArray(['fos_user.mailer.twig_swift']) + ->then(function ($v) { + trigger_deprecation('friendsofsymfony/user-bundle', '3.4.0', 'The twig_swift mailer is deprecated because Swiftmailer itself is unmaintained.'); + + return $v; + }) + ->end() + ->end() ->scalarNode('email_canonicalizer')->defaultValue('fos_user.util.canonicalizer.default')->end() ->scalarNode('token_generator')->defaultValue('fos_user.util.token_generator.default')->end() ->scalarNode('username_canonicalizer')->defaultValue('fos_user.util.canonicalizer.default')->end() diff --git a/src/DependencyInjection/FOSUserExtension.php b/src/DependencyInjection/FOSUserExtension.php index 2e8aaae58..47e431eda 100644 --- a/src/DependencyInjection/FOSUserExtension.php +++ b/src/DependencyInjection/FOSUserExtension.php @@ -16,6 +16,7 @@ use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpKernel\DependencyInjection\Extension; @@ -77,6 +78,14 @@ public function load(array $configs, ContainerBuilder $container): void $loader->load(sprintf('%s.xml', $basename)); } + $twigSwiftMailerDefinition = $container->getDefinition('fos_user.mailer.twig_swift'); + if (method_exists(Definition::class, 'getDeprecation')) { + $twigSwiftMailerDefinition->setDeprecated('friendsofsymfony/user-bundle', '3.4.0', 'The "%service_id%" service is deprecated. Use a different mailer implementation instead.'); + } else { + // BC for Symfony <5.1 + $twigSwiftMailerDefinition->setDeprecated('The "fos_user.mailer.twig_swift" service is deprecated. Use a different mailer implementation instead.'); + } + if (!$config['use_authentication_listener']) { $container->removeDefinition('fos_user.listener.authentication'); } diff --git a/src/Mailer/TwigSwiftMailer.php b/src/Mailer/TwigSwiftMailer.php index d85bec015..c15fb7fbc 100644 --- a/src/Mailer/TwigSwiftMailer.php +++ b/src/Mailer/TwigSwiftMailer.php @@ -17,6 +17,8 @@ /** * @author Christophe Coevoet + * + * @deprecated */ class TwigSwiftMailer implements MailerInterface {