Skip to content
Snippets Groups Projects
Commit d9220bf4 authored by Ted Bowman's avatar Ted Bowman
Browse files

Issue #3380698: Make EmailNotificationsTestTrait::assertMessagesSent() clearer...

Issue #3380698: Make EmailNotificationsTestTrait::assertMessagesSent() clearer by renaming variables
parent 4ef42b95
No related branches found
No related tags found
No related merge requests found
...@@ -56,40 +56,40 @@ trait EmailNotificationsTestTrait { ...@@ -56,40 +56,40 @@ trait EmailNotificationsTestTrait {
/** /**
* Asserts that all recipients received a given email. * Asserts that all recipients received a given email.
* *
* @param string $subject * @param string $expected_subject
* The subject line of the email that should have been sent. * The subject line of the email that should have been sent.
* @param string $body * @param string $expected_body
* The beginning of the body text of the email that should have been sent. * The beginning of the body text of the email that should have been sent.
* *
* @see ::$emailRecipients * @see ::$emailRecipients
*/ */
protected function assertMessagesSent(string $subject, string $body): void { protected function assertMessagesSent(string $expected_subject, string $expected_body): void {
$sent_messages = $this->getMails([ $sent_messages = $this->getMails([
'subject' => $subject, 'subject' => $expected_subject,
]); ]);
$this->assertNotEmpty($sent_messages); $this->assertNotEmpty($sent_messages);
$this->assertCount(count($this->emailRecipients), $sent_messages); $this->assertCount(count($this->emailRecipients), $sent_messages);
// Ensure the body is formatted the way the PHP mailer would do it. // Ensure the body is formatted the way the PHP mailer would do it.
$message = [ $expected_message = [
'body' => [$body], 'body' => [$expected_body],
]; ];
$message = $this->container->get('plugin.manager.mail') $expected_message = $this->container->get('plugin.manager.mail')
->createInstance('php_mail') ->createInstance('php_mail')
->format($message); ->format($expected_message);
$body = $message['body']; $expected_body = $expected_message['body'];
foreach ($sent_messages as $message) { foreach ($sent_messages as $sent_message) {
$email = $message['to']; $email = $sent_message['to'];
$expected_langcode = $this->emailRecipients[$email]; $expected_langcode = $this->emailRecipients[$email];
$this->assertSame($expected_langcode, $message['langcode']); $this->assertSame($expected_langcode, $sent_message['langcode']);
// The message, and every line in it, should have been sent in the // The message, and every line in it, should have been sent in the
// expected language. // expected language.
// @see automatic_updates_test_mail_alter() // @see automatic_updates_test_mail_alter()
$this->assertArrayHasKey('line_langcodes', $message); $this->assertArrayHasKey('line_langcodes', $sent_message);
$this->assertSame([$expected_langcode], $message['line_langcodes']); $this->assertSame([$expected_langcode], $sent_message['line_langcodes']);
$this->assertStringStartsWith($body, $message['body']); $this->assertStringStartsWith($expected_body, $sent_message['body']);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment