aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Lehmann <t.lehmann@strato.de>2024-11-07 11:02:17 +0100
committerThomas Lehmann <147605810+thlehmann-ionos@users.noreply.github.com>2024-11-19 11:32:39 +0100
commit46d8a7333b9b77ccc440afd0a3c3fe7c5bc3901c (patch)
treeaa47a3157bda319a5fc4c10a564a92ec234f03d6
parent6559c2075e46c796ff518b0e23e38534783ed194 (diff)
downloadnextcloud-server-46d8a7333b9b77ccc440afd0a3c3fe7c5bc3901c.tar.gz
nextcloud-server-46d8a7333b9b77ccc440afd0a3c3fe7c5bc3901c.zip
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 <t.lehmann@strato.de>
-rw-r--r--lib/private/Mail/Mailer.php4
-rw-r--r--tests/lib/Mail/MailerTest.php6
2 files changed, 9 insertions, 1 deletions
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);
+ }
}