Browse Source

Merge pull request #15380 from cakephp/3.x-mailsentwith-against-array

[3.x] Allow to compare "mail sent with" against an array
Mark Story 5 years ago
parent
commit
6c6fe3c206

+ 5 - 4
src/TestSuite/Constraint/Email/MailSentWith.php

@@ -52,15 +52,16 @@ class MailSentWith extends MailConstraintBase
         $emails = $this->getEmails();
         foreach ($emails as $email) {
             $value = $this->getValue($email);
+            if ($value === $other) {
+                return true;
+            }
             if (
-                in_array($this->method, ['to', 'cc', 'bcc', 'from'])
+                !is_array($other)
+                && in_array($this->method, ['to', 'cc', 'bcc', 'from'])
                 && array_key_exists($other, $value)
             ) {
                 return true;
             }
-            if ($value === $other) {
-                return true;
-            }
         }
 
         return false;

+ 2 - 2
tests/TestCase/TestSuite/EmailTraitTest.php

@@ -42,7 +42,7 @@ class EmailTraitTest extends TestCase
 
         Email::setConfig('default', [
             'transport' => 'test_tools',
-            'from' => 'default@example.com',
+            'from' => ['default@example.com' => 'Default Name'],
         ]);
         Email::setConfig('alternate', [
             'transport' => 'test_tools',
@@ -76,7 +76,7 @@ class EmailTraitTest extends TestCase
     {
         $this->sendEmails();
 
-        $this->assertMailSentFrom('default@example.com');
+        $this->assertMailSentFrom(['default@example.com' => 'Default Name']);
         $this->assertMailSentFrom('alternate@example.com');
 
         $this->assertMailSentTo('to@example.com');