public function Maillog::emailsWereSent in Maillog / Mail Developer 7
@Then /^(\d+) emails? should be sent:$/i.
File
- ./
maillog.behat.inc, line 63 - Behat subcontext for testing whether specific emails have been sent.
Class
- Maillog
- Behat subcontext for testing whether specific emails have been sent.
Code
public function emailsWereSent($num, TableNode $table) {
$expected_emails = $table
->getHash();
$actual_emails = db_select('maillog', 'm')
->fields('m')
->condition('id', $this->lastId, '>')
->orderBy('id', 'DESC')
->execute()
->fetchAllAssoc('id', PDO::FETCH_ASSOC);
if (count($actual_emails) < $num) {
throw new Exception('Only ' . count($actual_emails) . ' were sent.');
}
$missing_emails = array();
foreach ($expected_emails as $expected_email) {
foreach ($actual_emails as $actual_email) {
if ($this
->emailsMatch($actual_email, $expected_email)) {
continue 2;
}
}
// No matches for the expected email.
$missing_emails[] = $expected_email;
}
if (count($missing_emails) > 0) {
$message = "Missing Emails:\n" . implode("\n", array_map('drupal_json_encode', $missing_emails));
throw new Exception($message);
}
}