Skip to content

Improve Mailable assertion error messages with expected vs actual values #56221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 7, 2025

Conversation

ahinkle
Copy link
Contributor

@ahinkle ahinkle commented Jul 5, 2025

Currently, when mailable assertions fail, developers only see generic error messages that don't show what was actually found vs what was expected. This forces developers to dig through code to understand why tests are failing.

Changes:

  • assertHasSubject() - Shows expected vs actual subject
  • assertFrom() - Shows expected vs actual sender information
  • assertTo() / assertHasTo() - Shows expected vs actual recipients
  • assertHasCc() - Shows expected vs actual CC recipients
  • assertHasBcc() - Shows expected vs actual BCC recipients
  • assertHasReplyTo() - Shows expected vs actual reply-to addresses
  • assertHasTag() - Shows expected tag vs actual tags list
  • assertHasMetadata() - Shows expected vs actual metadata values

Usage:

$mailable->assertHasSubject('Welcome to Laravel!');

// Before:
// "Did not see expected text [Welcome to Laravel!] in email subject."

// After:
// "Email subject does not match expected value.
// Expected: [Welcome to Laravel!]
// Actual: [Order Confirmation Email]"
$mailable->assertTo('john@example.com', 'John Doe');

// Before:
// "Did not see expected recipient [john@example.com (John Doe)] in email 'to' recipients."

// After:
// "Did not see expected recipient in email 'to' recipients.
// Expected: [john@example.com (John Doe)]
// Actual: [jane@example.com (Jane Smith)]"

@taylorotwell taylorotwell merged commit 5474ddb into laravel:12.x Jul 7, 2025
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants