]> source.dussan.org Git - nextcloud-server.git/commitdiff
feat(Mailer): implement caching
authorThomas Lehmann <t.lehmann@strato.de>
Thu, 7 Nov 2024 10:02:17 +0000 (11:02 +0100)
committerThomas Lehmann <147605810+thlehmann-ionos@users.noreply.github.com>
Tue, 19 Nov 2024 10:32:39 +0000 (11:32 +0100)
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>
lib/private/Mail/Mailer.php
tests/lib/Mail/MailerTest.php

index da3fcd35888716e9714c205581460f71b0898298..b0c08815f1ef0e127a9804aa33dea10660c4fee7 100644 (file)
@@ -267,7 +267,9 @@ class Mailer implements IMailer {
                                break;
                }
 
-               return new SymfonyMailer($transport);
+               $this->instance = new SymfonyMailer($transport);
+
+               return $this->instance;
        }
 
        /**
index f215e385e3f75ca7f637c91b8f5199e15cf6664d..84015f38d242cffe2d1a393d0bd0954116cbbe97 100644 (file)
@@ -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);
+       }
 }