Browse Source

Merge pull request #15490 from Zuluru/3.next

Explicitly check against null, to enable testing attributes of email #0
Mark Story 4 years ago
parent
commit
9ba92363cb

+ 1 - 1
src/TestSuite/Constraint/Email/MailConstraintBase.php

@@ -50,7 +50,7 @@ abstract class MailConstraintBase extends Constraint
     {
         $emails = TestEmailTransport::getEmails();
 
-        if ($this->at) {
+        if ($this->at !== null) {
             if (!isset($emails[$this->at])) {
                 return [];
             }

+ 20 - 0
tests/TestCase/TestSuite/EmailTraitTest.php

@@ -16,10 +16,12 @@ namespace Cake\Test\TestCase\TestSuite;
 
 use Cake\Mailer\Email;
 use Cake\Mailer\TransportFactory;
+use Cake\TestSuite\Constraint\Email\MailSentFrom;
 use Cake\TestSuite\EmailTrait;
 use Cake\TestSuite\TestCase;
 use Cake\TestSuite\TestEmailTransport;
 use PHPUnit\Framework\AssertionFailedError;
+use PHPUnit\Framework\Constraint\LogicalNot;
 
 /**
  * Tests EmailTrait assertions
@@ -125,6 +127,24 @@ class EmailTraitTest extends TestCase
     }
 
     /**
+     * confirm that "at 0" is really testing email 0, not all the emails
+     *
+     * @return void
+     */
+    public function testAt0()
+    {
+        $this->skipIf(!class_exists('PHPUnit\Framework\Constraint\LogicalNot'), 'LogicalNot class not supported on PHP5.6');
+
+        $this->assertNoMailSent();
+
+        $this->sendEmails();
+
+        $this->assertMailCount(3);
+
+        $this->assertThat('alternate@example.com', new LogicalNot(new MailSentFrom(0)));
+    }
+
+    /**
      * tests assertNoMailSent fails when no mail is sent
      *
      * @return void