Browse Source

Explicitly check against null, to enable testing attributes of email #0

Port #15490 to 4.x
gregs 5 years ago
parent
commit
46dde2d481

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

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

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

@@ -19,10 +19,12 @@ namespace Cake\Test\TestCase\TestSuite;
 use Cake\Mailer\Mailer;
 use Cake\Mailer\Message;
 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
@@ -118,6 +120,9 @@ class EmailTraitTest extends TestCase
         $this->assertMailSentFromAt(0, 'default@example.com');
         $this->assertMailSentFromAt(1, 'alternate@example.com');
 
+        // Confirm that "at 0" is really testing email 0, not all the emails
+        $this->assertThat('alternate@example.com', new LogicalNot(new MailSentFrom(0)));
+
         $this->assertMailSentToAt(0, 'to@example.com');
         $this->assertMailSentToAt(1, 'to2@example.com');
         $this->assertMailSentToAt(2, 'to3@example.com');