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