diff --git a/core/tests/Drupal/KernelTests/Core/Test/AssertMailTraitTest.php b/core/tests/Drupal/KernelTests/Core/Test/AssertMailTraitTest.php index e368ead..7af7718 100644 --- a/core/tests/Drupal/KernelTests/Core/Test/AssertMailTraitTest.php +++ b/core/tests/Drupal/KernelTests/Core/Test/AssertMailTraitTest.php @@ -24,6 +24,9 @@ class AssertMailTraitTest extends KernelTestBase { * Tests that the maintenance theme initializes the theme and its base themes. */ public function testAssertMailTrait() { + /* @var \Drupal\Core\Mail\MailManagerInterface $mail_service */ + $mail_service = \Drupal::service('plugin.manager.mail'); + // Create an email. $subject = $this->randomString(64); $body = $this->randomString(128); @@ -35,12 +38,13 @@ public function testAssertMailTrait() { 'body' => $body, ]; - // Before we send the email, drupalGetMails should return an empty array. + // Before we send the email, \Drupal\Core\Test\AssertMailTrait::getMails() + // should return an empty array. $captured_emails = $this->getMails(); $this->assertCount(0, $captured_emails, 'The captured emails queue is empty.'); // Send the email. - \Drupal::service('plugin.manager.mail')->getInstance(['module' => 'simpletest', 'key' => 'drupal_mail_test'])->mail($message); + $mail_service->getInstance(['module' => 'simpletest', 'key' => 'drupal_mail_test'])->mail($message); // Ensure that there is one email in the captured emails array. $captured_emails = $this->getMails(); @@ -49,7 +53,7 @@ public function testAssertMailTrait() { // Assert that the email was sent by iterating over the message properties // and ensuring that they are captured intact. foreach ($message as $field => $value) { - $this->assertMail($field, $value, sprintf('The email was sent and the value for property %s is intact.', $field)); + $this->assertMail($field, $value, "The email was sent and the value for property $field is intact."); } // Send additional emails so more than one email is captured. @@ -61,14 +65,15 @@ public function testAssertMailTrait() { 'to' => $this->randomMachineName(32) . '@example.com', 'body' => $this->randomString(512), ]; - \Drupal::service('plugin.manager.mail')->getInstance(['module' => 'drupal_mail_test', 'key' => $index])->mail($message); + $mail_service->getInstance(['module' => 'drupal_mail_test', 'key' => $index])->mail($message); } // There should now be 6 emails captured. $captured_emails = $this->getMails(); $this->assertCount(6, $captured_emails, 'All emails were captured.'); - // Test different ways of getting filtered emails via drupalGetMails(). + // Test different ways of getting filtered emails via + // \Drupal\Core\Test\AssertMailTrait::getMails(). $captured_emails = $this->getMails(['id' => 'drupal_mail_test']); $this->assertCount(1, $captured_emails, 'Only one email is returned when filtering by id.'); $captured_emails = $this->getMails(['id' => 'drupal_mail_test', 'subject' => $subject]); @@ -80,10 +85,10 @@ public function testAssertMailTrait() { ]); $this->assertCount(0, $captured_emails, 'No emails are returned when querying with an unused from address.'); - // Send the last email again, so we can confirm that the - // drupalGetMails-filter correctly returns all emails with a given - // property/value. - \Drupal::service('plugin.manager.mail')->getInstance(['module' => 'drupal_mail_test', 'key' => $index])->mail($message); + // Send the last email again, so we can confirm that + // \Drupal\Core\Test\AssertMailTrait::getMails() filters correctly returns + // all emails with a given property/value. + $mail_service->getInstance(['module' => 'drupal_mail_test', 'key' => $index])->mail($message); $captured_emails = $this->getMails(['id' => 'drupal_mail_test_4']); $this->assertCount(2, $captured_emails, 'All emails with the same id are returned when filtering by id.'); }