diff --git a/application/features/bootstrap/EmailContext.php b/application/features/bootstrap/EmailContext.php index a6bcfd03..262c28b3 100644 --- a/application/features/bootstrap/EmailContext.php +++ b/application/features/bootstrap/EmailContext.php @@ -1255,15 +1255,8 @@ public function iSendAbandonedUserEmail() */ public function theAbandonedUserEmailHasOrHasNotBeenSent($hasOrHasNot) { - $emails = $this->fakeEmailer->getFakeEmailsSent(); - $hasBeenSent = false; - - foreach ($emails as $email) { - if ($email[Emailer::PROP_SUBJECT] === $this->fakeEmailer->subjectForAbandonedUsers) { - $hasBeenSent = true; - break; - } - } + $numberSent = $this->countEmailsSent(EmailLog::MESSAGE_TYPE_ABANDONED_USERS); + $hasBeenSent = ($numberSent > 0); if ($hasOrHasNot === 'has') { Assert::true($hasBeenSent); @@ -1272,6 +1265,20 @@ public function theAbandonedUserEmailHasOrHasNotBeenSent($hasOrHasNot) } } + protected function countEmailsSent(string $messageType): int + { + $emails = $this->fakeEmailer->getFakeEmailsSent(); + $actualCount = 0; + + foreach ($emails as $email) { + $subject = $email[Emailer::PROP_SUBJECT]; + if ($this->fakeEmailer->isSubjectForMessageType($subject, $messageType)) { + $actualCount++; + } + } + return $actualCount; + } + /** * @Given the database has been purged */ diff --git a/application/features/bootstrap/fakes/FakeEmailer.php b/application/features/bootstrap/fakes/FakeEmailer.php index ce73f776..eb7603af 100644 --- a/application/features/bootstrap/fakes/FakeEmailer.php +++ b/application/features/bootstrap/fakes/FakeEmailer.php @@ -64,8 +64,11 @@ public function getFakeEmailsSent() return $this->getEmailServiceClient()->emailsSent; } - public function isSubjectForMessageType(string $subject, string $messageType, ?User $user) - { + public function isSubjectForMessageType( + string $subject, + string $messageType, + ?User $user = null + ): bool { $dataForEmail = ArrayHelper::merge( $user ? $user->getAttributesForEmail() : [], $this->otherDataForEmails