Browse Source

Fix existence check in MailSentWith.

Closes #13636
ADmad 6 years ago
parent
commit
2297484f72

+ 3 - 1
src/TestSuite/Constraint/Email/MailSentWith.php

@@ -49,7 +49,9 @@ class MailSentWith extends MailConstraintBase
         $emails = $this->getEmails();
         foreach ($emails as $email) {
             $value = $email->{'get' . ucfirst($this->method)}();
-            if (in_array($this->method, ['to', 'cc', 'bcc', 'from']) && isset($value[$other])) {
+            if (in_array($this->method, ['to', 'cc', 'bcc', 'from'])
+                && array_key_exists($other, $value)
+            ) {
                 return true;
             }
             if ($value === $other) {

+ 6 - 1
tests/TestCase/TestSuite/EmailTraitTest.php

@@ -103,13 +103,14 @@ class EmailTraitTest extends TestCase
 
         $this->sendEmails();
 
-        $this->assertMailCount(2);
+        $this->assertMailCount(3);
 
         $this->assertMailSentFromAt(0, 'default@example.com');
         $this->assertMailSentFromAt(1, 'alternate@example.com');
 
         $this->assertMailSentToAt(0, 'to@example.com');
         $this->assertMailSentToAt(1, 'to2@example.com');
+        $this->assertMailSentToAt(2, 'to3@example.com');
 
         $this->assertMailContainsAt(0, 'text');
         $this->assertMailContainsAt(1, 'html');
@@ -235,5 +236,9 @@ class EmailTraitTest extends TestCase
             ->setCc('cc2@example.com')
             ->setEmailFormat(Email::MESSAGE_HTML)
             ->send('html');
+
+        (new Email('alternate'))
+            ->setTo(['to3@example.com' => null])
+            ->send('html');
     }
 }