From 380f442241a1fc00a555e5691c9963977f4eafac Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Tue, 25 Jun 2024 10:15:22 +0200 Subject: [PATCH 1/5] Fix invalid mock in tests --- tests/Doctrine/UserManagerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/UserManagerTest.php b/tests/Doctrine/UserManagerTest.php index 41a30dc9d..ed9bf9f37 100644 --- a/tests/Doctrine/UserManagerTest.php +++ b/tests/Doctrine/UserManagerTest.php @@ -80,7 +80,7 @@ public function testGetClass() public function testFindUserBy() { $crit = ['foo' => 'bar']; - $this->repository->expects($this->once())->method('findOneBy')->with($this->equalTo($crit))->will($this->returnValue([])); + $this->repository->expects($this->once())->method('findOneBy')->with($this->equalTo($crit))->will($this->returnValue(null)); $this->userManager->findUserBy($crit); } From 4ef57b35c1a0dae25548b6a81c3a4dca1fb881d0 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Mon, 24 Jun 2024 19:55:59 +0200 Subject: [PATCH 2/5] 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 3/5] 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 { From 03b2593dc6e9f7925c0724590aa6adcfa1f72561 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Tue, 25 Jun 2024 10:35:26 +0200 Subject: [PATCH 4/5] Enable the static analysis CI workflow for the 3.x branch --- .github/workflows/static-analysis.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/static-analysis.yaml b/.github/workflows/static-analysis.yaml index 016959040..2fe338076 100644 --- a/.github/workflows/static-analysis.yaml +++ b/.github/workflows/static-analysis.yaml @@ -3,7 +3,7 @@ name: Code style and composer validate on: pull_request: push: - branches: [ master, 2.x ] + branches: [ master, 2.x, 3.x ] jobs: composer-validate: From cdd9fe277206c2a85aeea33645234a5b0bbe16b7 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Tue, 25 Jun 2024 10:36:18 +0200 Subject: [PATCH 5/5] Remove the reference to ZetaWebmailBundle in the documentation This bundle was last updated in 2012. --- docs/emails.rst | 7 ------- 1 file changed, 7 deletions(-) diff --git a/docs/emails.rst b/docs/emails.rst index 1d75549db..9e20433c0 100644 --- a/docs/emails.rst +++ b/docs/emails.rst @@ -212,10 +212,3 @@ An example is listed below. # ... service: mailer: app.custom_fos_user_mailer - -To see an example of a working implementation of the ``MailerInterface`` -see the `ZetaMailer`_ class of the `ZetaWebmailBundle`_. This implementation -uses the Zeta Components Mail to send emails instead of Swiftmailer. - -.. _ZetaMailer: https://github.com/simplethings/ZetaWebmailBundle/blob/master/UserBundle/ZetaMailer.php -.. _ZetaWebmailBundle: https://github.com/simplethings/ZetaWebmailBundle