You are here

protected function AssertMailTrait::getMails in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Test/AssertMailTrait.php \Drupal\Core\Test\AssertMailTrait::getMails()
  2. 9 core/lib/Drupal/Core/Test/AssertMailTrait.php \Drupal\Core\Test\AssertMailTrait::getMails()

Gets an array containing all emails sent during this test case.

Parameters

array $filter: An array containing key/value pairs used to filter the emails that are returned.

Return value

array An array containing email messages captured during the current test.

3 calls to AssertMailTrait::getMails()
AssertMailTraitTest::testAssertMailTrait in core/tests/Drupal/KernelTests/Core/Test/AssertMailTraitTest.php
Tests that the maintenance theme initializes the theme and its base themes.
EmailActionTest::testEmailAction in core/tests/Drupal/KernelTests/Core/Action/EmailActionTest.php
Tests the email action plugin.
MailCaptureTest::testMailSend in core/tests/Drupal/FunctionalTests/MailCaptureTest.php
Tests to see if the wrapper function is executed correctly.

File

core/lib/Drupal/Core/Test/AssertMailTrait.php, line 22

Class

AssertMailTrait
Provides methods for testing emails sent during test runs.

Namespace

Drupal\Core\Test

Code

protected function getMails(array $filter = []) {
  $captured_emails = $this->container
    ->get('state')
    ->get('system.test_mail_collector', []);
  $filtered_emails = [];
  foreach ($captured_emails as $message) {
    foreach ($filter as $key => $value) {
      if (!isset($message[$key]) || $message[$key] != $value) {
        continue 2;
      }
    }
    $filtered_emails[] = $message;
  }
  return $filtered_emails;
}