From 46d8a7333b9b77ccc440afd0a3c3fe7c5bc3901c Mon Sep 17 00:00:00 2001 From: Thomas Lehmann Date: Thu, 7 Nov 2024 11:02:17 +0100 Subject: [PATCH] feat(Mailer): implement caching Currently $this->instance is never set, so the code is no-op. This brings back caching of the instance. Caching broke with be7db1573dc8c6e7309ec9db124a7a74b8b41199 Swift to \Swift_Mailer as abstraction Signed-off-by: Thomas Lehmann --- lib/private/Mail/Mailer.php | 4 +++- tests/lib/Mail/MailerTest.php | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/private/Mail/Mailer.php b/lib/private/Mail/Mailer.php index da3fcd35888..b0c08815f1e 100644 --- a/lib/private/Mail/Mailer.php +++ b/lib/private/Mail/Mailer.php @@ -267,7 +267,9 @@ class Mailer implements IMailer { break; } - return new SymfonyMailer($transport); + $this->instance = new SymfonyMailer($transport); + + return $this->instance; } /** diff --git a/tests/lib/Mail/MailerTest.php b/tests/lib/Mail/MailerTest.php index f215e385e3f..84015f38d24 100644 --- a/tests/lib/Mail/MailerTest.php +++ b/tests/lib/Mail/MailerTest.php @@ -337,4 +337,10 @@ class MailerTest extends TestCase { self::assertInstanceOf(EsmtpTransport::class, $transport); self::assertEquals('[127.0.0.1]', $transport->getLocalDomain()); } + + public function testCaching(): void { + $symfonyMailer1 = self::invokePrivate($this->mailer, 'getInstance'); + $symfonyMailer2 = self::invokePrivate($this->mailer, 'getInstance'); + self::assertSame($symfonyMailer1, $symfonyMailer2); + } } -- 2.39.5