Skip to content

Commit 7adc7f7

Browse files
committed
fix: dont add mails that were not sent
1 parent ab5ccc5 commit 7adc7f7

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Codeception/Lib/Connector/Yii2.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,11 @@ public function startApp(?\yii\log\Logger $logger = null): void
308308

309309
match ($this->mailMethod) {
310310
self::MAIL_CATCH => $config= $this->mockMailer($config),
311-
self::MAIL_EVENT_AFTER => $config['components']['mailer']['on ' . BaseMailer::EVENT_AFTER_SEND] = fn(MailEvent $event) => $this->emails[] = $event->message,
311+
self::MAIL_EVENT_AFTER => $config['components']['mailer']['on ' . BaseMailer::EVENT_AFTER_SEND] = function(MailEvent $event): void {
312+
if ($event->isSuccessful) {
313+
$this->emails[] = $event->message;
314+
}
315+
},
312316
self::MAIL_EVENT_BEFORE => $config['components']['mailer']['on ' . BaseMailer::EVENT_BEFORE_SEND] = fn(MailEvent $event) => $this->emails[] = $event->message,
313317
self::MAIL_IGNORE => null// Do nothing
314318
};

0 commit comments

Comments
 (0)