Browse Source

Fix type error if a mailer methods calls reset()

ADmad 1 year ago
parent
commit
c92d2755ae

+ 5 - 1
src/Mailer/Mailer.php

@@ -500,7 +500,11 @@ class Mailer implements EventListenerInterface
     {
         foreach (array_keys($this->clonedInstances) as $key) {
             if ($this->clonedInstances[$key] === null) {
-                $this->{$key} = null;
+                if ($key === 'message') {
+                    $this->message->reset();
+                } else {
+                    $this->{$key} = null;
+                }
             } else {
                 $this->{$key} = clone $this->clonedInstances[$key];
                 $this->clonedInstances[$key] = null;

+ 6 - 0
tests/TestCase/Mailer/MailerTest.php

@@ -1213,6 +1213,12 @@ class MailerTest extends TestCase
         $this->assertSame(Message::EMAIL_PATTERN, $this->mailer->getEmailPattern());
     }
 
+    public function testRestore(): void
+    {
+        $this->expectNotToPerformAssertions();
+        $this->mailer->send('dummy');
+    }
+
     /**
      * testSendWithLog method
      */

+ 8 - 0
tests/test_app/TestApp/Mailer/TestMailer.php

@@ -17,6 +17,7 @@ declare(strict_types=1);
 namespace TestApp\Mailer;
 
 use Cake\Mailer\Mailer;
+use Cake\Mailer\Transport\DebugTransport;
 
 /**
  * Test Suite Test App Mailer class.
@@ -42,4 +43,11 @@ class TestMailer extends Mailer
 
         return $result;
     }
+
+    public function dummy(): void
+    {
+        $this->reset();
+
+        $this->setTransport(new DebugTransport());
+    }
 }