CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.10 Red Velvet API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 3.10
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Auth
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Filesystem
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • Shell
    • TestSuite
      • Constraint
      • Fixture
      • Stub
    • Utility
    • Validation
    • View

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.

Namespace: Cake\TestSuite

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

  • 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 $expectedText, string $message = ''): void

Asserts an email contains an expected text content

Parameters
string $expectedText

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(string|array $address, string $message = ''): void

Asserts an email was sent from an address

Parameters
string|array $address

Email address or [$emailAddress => $displayName].

string $message optional

Message

Returns
void

assertMailSentFromAt() ¶ public

assertMailSentFromAt(int $at, string|array $address, string $message = ''): void

Asserts an email at a specific index was sent from an address

Parameters
int $at

Email index

string|array $address

Email address or [$emailAddress => $displayName].

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", "subject")

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

cleanupEmailTrait() ¶ public

cleanupEmailTrait(): void

Resets transport state

Returns
void

setupTransports() ¶ public

setupTransports(): void

Replaces all transports with the test transport during test setup

Returns
void
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs