Trait EmailTrait
Make assertions on emails sent through the Cake\TestSuite\TestEmailTransport
After adding the trait to your test case, all mail transports will be replaced with TestEmailTransport which is used for making assertions and will not actually send emails.
Method Summary
-
assertMailContains() public
Asserts an email contains expected contents
-
assertMailContainsAt() public
Asserts an email at a specific index contains expected contents
-
assertMailContainsAttachment() public
Asserts an email contains expected attachment
-
assertMailContainsHtml() public
Asserts an email contains expected html contents
-
assertMailContainsHtmlAt() public
Asserts an email at a specific index contains expected html contents
-
assertMailContainsText() public
Asserts an email contains an expected text content
-
assertMailContainsTextAt() public
Asserts an email at a specific index contains expected text contents
-
assertMailCount() public
Asserts an expected number of emails were sent
-
assertMailSentFrom() public
Asserts an email was sent from an address
-
assertMailSentFromAt() public
Asserts an email at a specific index was sent from an address
-
assertMailSentTo() public
Asserts an email was sent to an address
-
assertMailSentToAt() public
Asserts an email at a specific index was sent to an address
-
assertMailSentWith() public
Asserts an email contains the expected value within an Email getter
-
assertMailSentWithAt() public
Asserts an email at a specific index contains the expected value within an Email getter
-
assertMailSubjectContains() public
Asserts an email subject contains expected contents
-
assertMailSubjectContainsAt() public
Asserts an email at a specific index contains expected html contents
-
assertNoMailSent() public
Asserts that no emails were sent
-
cleanupEmailTrait() public
Resets transport state
-
setupTransports() public
Replaces all transports with the test transport during test setup
Method Detail
assertMailContains() ¶ public
assertMailContains(string $contents, string $message = ''): void
Asserts an email contains expected contents
Parameters
-
string
$contents Contents
-
string
$message optional Message
Returns
void
assertMailContainsAt() ¶ public
assertMailContainsAt(int $at, string $contents, string $message = ''): void
Asserts an email at a specific index contains expected contents
Parameters
-
int
$at Email index
-
string
$contents Contents
-
string
$message optional Message
Returns
void
assertMailContainsAttachment() ¶ public
assertMailContainsAttachment(string $filename, array $file = [], string $message = ''): void
Asserts an email contains expected attachment
Parameters
-
string
$filename Filename
-
array
$file optional Additional file properties
-
string
$message optional Message
Returns
void
assertMailContainsHtml() ¶ public
assertMailContainsHtml(string $contents, string $message = ''): void
Asserts an email contains expected html contents
Parameters
-
string
$contents Contents
-
string
$message optional Message
Returns
void
assertMailContainsHtmlAt() ¶ public
assertMailContainsHtmlAt(int $at, string $contents, string $message = ''): void
Asserts an email at a specific index contains expected html contents
Parameters
-
int
$at Email index
-
string
$contents Contents
-
string
$message optional Message
Returns
void
assertMailContainsText() ¶ public
assertMailContainsText(string $expected, string $message = ''): void
Asserts an email contains an expected text content
Parameters
-
string
$expected Expected text.
-
string
$message optional Message to display if assertion fails.
Returns
void
assertMailContainsTextAt() ¶ public
assertMailContainsTextAt(int $at, string $contents, string $message = ''): void
Asserts an email at a specific index contains expected text contents
Parameters
-
int
$at Email index
-
string
$contents Contents
-
string
$message optional Message
Returns
void
assertMailCount() ¶ public
assertMailCount(int $count, string $message = ''): void
Asserts an expected number of emails were sent
Parameters
-
int
$count Email count
-
string
$message optional Message
Returns
void
assertMailSentFrom() ¶ public
assertMailSentFrom(list<string>|string $address, string $message = ''): void
Asserts an email was sent from an address
Parameters
-
list<string>|string
$address Email address
-
string
$message optional Message
Returns
void
assertMailSentFromAt() ¶ public
assertMailSentFromAt(int $at, string $address, string $message = ''): void
Asserts an email at a specific index was sent from an address
Parameters
-
int
$at Email index
-
string
$address Email address
-
string
$message optional Message
Returns
void
assertMailSentTo() ¶ public
assertMailSentTo(string $address, string $message = ''): void
Asserts an email was sent to an address
Parameters
-
string
$address Email address
-
string
$message optional Message
Returns
void
assertMailSentToAt() ¶ public
assertMailSentToAt(int $at, string $address, string $message = ''): void
Asserts an email at a specific index was sent to an address
Parameters
-
int
$at Email index
-
string
$address Email address
-
string
$message optional Message
Returns
void
assertMailSentWith() ¶ public
assertMailSentWith(string $expected, string $parameter, string $message = ''): void
Asserts an email contains the expected value within an Email getter
Parameters
-
string
$expected Contents
-
string
$parameter Email getter parameter (e.g. "cc", "subject")
-
string
$message optional Message
Returns
void
assertMailSentWithAt() ¶ public
assertMailSentWithAt(int $at, string $expected, string $parameter, string $message = ''): void
Asserts an email at a specific index contains the expected value within an Email getter
Parameters
-
int
$at Email index
-
string
$expected Contents
-
string
$parameter Email getter parameter (e.g. "cc", "bcc")
-
string
$message optional Message
Returns
void
assertMailSubjectContains() ¶ public
assertMailSubjectContains(string $contents, string $message = ''): void
Asserts an email subject contains expected contents
Parameters
-
string
$contents Contents
-
string
$message optional Message
Returns
void
assertMailSubjectContainsAt() ¶ public
assertMailSubjectContainsAt(int $at, string $contents, string $message = ''): void
Asserts an email at a specific index contains expected html contents
Parameters
-
int
$at Email index
-
string
$contents Contents
-
string
$message optional Message
Returns
void
assertNoMailSent() ¶ public
assertNoMailSent(string $message = ''): void
Asserts that no emails were sent
Parameters
-
string
$message optional Message
Returns
void
setupTransports() ¶ public
setupTransports(): void
Replaces all transports with the test transport during test setup
Returns
void