-
Notifications
You must be signed in to change notification settings - Fork 39
feat: allow mails to be intercepted using events #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
dca7c44
5bcf28e
afa7637
907f280
93c851d
d536116
ab5ccc5
7adc7f7
83ac70a
d5eb9a5
d853a39
602a67c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,9 @@ | |
use yii\base\ExitException; | ||
use yii\base\Security; | ||
use yii\base\UserException; | ||
use yii\mail\BaseMailer; | ||
use yii\mail\MailerInterface; | ||
use yii\mail\MailEvent; | ||
use yii\mail\MessageInterface; | ||
use yii\web\Application; | ||
use yii\web\ErrorHandler; | ||
|
@@ -30,6 +33,19 @@ | |
{ | ||
use Shared\PhpSuperGlobalsConverter; | ||
|
||
const MAIL_METHODS = [ | ||
self::MAIL_CATCH, | ||
self::MAIL_EVENT_AFTER, | ||
self::MAIL_EVENT_BEFORE, | ||
self::MAIL_IGNORE | ||
]; | ||
|
||
public const MAIL_CATCH = 'catch'; | ||
public const MAIL_EVENT_AFTER = 'after'; | ||
public const MAIL_EVENT_BEFORE = 'before'; | ||
public const MAIL_IGNORE = 'ignore'; | ||
|
||
|
||
const CLEAN_METHODS = [ | ||
self::CLEAN_RECREATE, | ||
self::CLEAN_CLEAR, | ||
|
@@ -64,6 +80,10 @@ | |
*/ | ||
public $configFile; | ||
|
||
/** | ||
* @var self::MAIL_CATCH|self::MAIL_IGNORE|self::MAIL_AFTER|self::MAIL_BEFORE $mailMethod method for handling mails | ||
*/ | ||
public $mailMethod; | ||
Check failure on line 86 in src/Codeception/Lib/Connector/Yii2.php
|
||
/** | ||
* @var string method for cleaning the response object before each request | ||
*/ | ||
|
@@ -267,7 +287,15 @@ | |
unset($config['container']); | ||
} | ||
|
||
$config = $this->mockMailer($config); | ||
match ($this->mailMethod) { | ||
Check failure on line 290 in src/Codeception/Lib/Connector/Yii2.php
|
||
self::MAIL_CATCH => $config= $this->mockMailer($config), | ||
self::MAIL_EVENT_AFTER => $config['components']['mailer']['on ' . BaseMailer::EVENT_AFTER_SEND] = fn(MailEvent $event) => $this->emails[] = $event->message, | ||
SamMousa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self::MAIL_EVENT_BEFORE => $config['components']['mailer']['on ' . BaseMailer::EVENT_BEFORE_SEND] = function(MailEvent $event) { | ||
$this->emails[] = $event->message; | ||
return true; | ||
}, | ||
self::MAIL_IGNORE => null// Do nothing | ||
}; | ||
Yii::$app = Yii::createObject($config); | ||
|
||
if ($logger instanceof \yii\log\Logger) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.