kirschbaum-development / mail-intercept

A testing package for intercepting mail sent from Laravel
MIT License
105 stars 7 forks source link

Use HTML body when email is HTML for body assertions #12

Closed therobfonz closed 2 years ago

therobfonz commented 2 years ago

$mail->getBody()->bodyToString() includes line break and carriage return characters injected at unpredictable areas within the email message, making the assertMailBodyContainsString assertion unreliable and in the case of finding strings over a certain length, return false every time.

Screen Shot 2022-06-14 at 7 17 22 AM

This PR uses the $mail->getHtmlBody() method if it is an HTML email and falls back to $mail->getBody()->bodyToString() in case it is a plain text email. This method does not output line breaks, making assertions against body text far more reliable.

Screen Shot 2022-06-14 at 7 16 47 AM