Browse Source

implementation of getAssertedMessages for MailContainsHtml and
MailContains including $this->at

Mario Rothauer 6 years ago
parent
commit
e2c8f80e64

+ 6 - 2
src/TestSuite/Constraint/Email/MailContains.php

@@ -62,6 +62,7 @@ class MailContains extends MailConstraintBase
 
     /**
      * Returns the type-dependent strings of all messages
+     * respects $this->at
      *
      * @return string
      */
@@ -73,6 +74,9 @@ class MailContains extends MailConstraintBase
             $method = $this->getTypeMethod();
             $messageMembers[] = $message->$method();
         }
+        if ($this->at && isset($messageMembers[$this->at - 1])) {
+            $messageMembers = [$messageMembers[$this->at - 1]];
+        }
         $result = join(PHP_EOL, $messageMembers);
 
         return PHP_EOL . 'was: ' . mb_substr($result, 0, 1000);
@@ -86,9 +90,9 @@ class MailContains extends MailConstraintBase
     public function toString(): string
     {
         if ($this->at) {
-            return sprintf('is in email #%d', $this->at);
+            return sprintf('is in email #%d', $this->at) . $this->getAssertedMessages();
         }
 
-        return 'is in an email';
+        return 'is in an email' . $this->getAssertedMessages();
     }
 }

+ 2 - 2
src/TestSuite/Constraint/Email/MailContainsHtml.php

@@ -38,9 +38,9 @@ class MailContainsHtml extends MailContains
     public function toString(): string
     {
         if ($this->at) {
-            return sprintf('is in the html message of email #%d', $this->at);
+            return sprintf('is in the html message of email #%d', $this->at) . $this->getAssertedMessages();
         }
 
-        return 'is in the html message of an email';
+        return 'is in the html message of an email' . $this->getAssertedMessages();
     }
 }

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

@@ -38,7 +38,7 @@ class MailContainsText extends MailContains
     public function toString(): string
     {
         if ($this->at) {
-            return sprintf('is in the text message of email #%d', $this->at);
+            return sprintf('is in the text message of email #%d', $this->at) . $this->getAssertedMessages();
         }
 
         return 'is in the text message of an email' . $this->getAssertedMessages();

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

@@ -215,13 +215,13 @@ class EmailTraitTest extends TestCase
             'assertMailSentFromAt' => ['assertMailSentFromAt', 'Failed asserting that \'missing@example.com\' sent email #1.', [1, 'missing@example.com']],
             'assertMailSentWith' => ['assertMailSentWith', 'Failed asserting that \'Missing\' is in an email `subject`.', ['Missing', 'subject']],
             'assertMailSentWithAt' => ['assertMailSentWithAt', 'Failed asserting that \'Missing\' is in email #1 `subject`.', [1, 'Missing', 'subject']],
-            'assertMailContains' => ['assertMailContains', 'Failed asserting that \'Missing\' is in an email.', ['Missing']],
+            'assertMailContains' => ['assertMailContains', 'Failed asserting that \'Missing\' is in an email' . PHP_EOL . 'was: .', ['Missing']],
             'assertMailContainsAttachment' => ['assertMailContainsAttachment', 'Failed asserting that \'no_existing_file.php\' is an attachment of an email.', ['no_existing_file.php']],
-            'assertMailContainsHtml' => ['assertMailContainsHtml', 'Failed asserting that \'Missing\' is in the html message of an email.', ['Missing']],
+            'assertMailContainsHtml' => ['assertMailContainsHtml', 'Failed asserting that \'Missing\' is in the html message of an email' . PHP_EOL . 'was: .', ['Missing']],
             'assertMailContainsText' => ['assertMailContainsText', 'Failed asserting that \'Missing\' is in the text message of an email' . PHP_EOL . 'was: .', ['Missing']],
-            'assertMailContainsAt' => ['assertMailContainsAt', 'Failed asserting that \'Missing\' is in email #1.', [1, 'Missing']],
-            'assertMailContainsHtmlAt' => ['assertMailContainsHtmlAt', 'Failed asserting that \'Missing\' is in the html message of email #1.', [1, 'Missing']],
-            'assertMailContainsTextAt' => ['assertMailContainsTextAt', 'Failed asserting that \'Missing\' is in the text message of email #1.', [1, 'Missing']],
+            'assertMailContainsAt' => ['assertMailContainsAt', 'Failed asserting that \'Missing\' is in email #1' . PHP_EOL . 'was: .', [1, 'Missing']],
+            'assertMailContainsHtmlAt' => ['assertMailContainsHtmlAt', 'Failed asserting that \'Missing\' is in the html message of email #1' . PHP_EOL . 'was: .', [1, 'Missing']],
+            'assertMailContainsTextAt' => ['assertMailContainsTextAt', 'Failed asserting that \'Missing\' is in the text message of email #1' . PHP_EOL . 'was: .', [1, 'Missing']],
         ];
     }