From c7d192d14e77b3d56842d156b36dd96c6ac9a606 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Sat, 7 Dec 2024 17:48:14 +0100 Subject: [PATCH] Fixes ACCOUNTS-BQ. Don't use mailer in constructor --- common/tasks/SendCurrentEmailConfirmation.php | 10 +++------- .../unit/tasks/SendCurrentEmailConfirmationTest.php | 3 +-- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/common/tasks/SendCurrentEmailConfirmation.php b/common/tasks/SendCurrentEmailConfirmation.php index a2dfa81..4484066 100644 --- a/common/tasks/SendCurrentEmailConfirmation.php +++ b/common/tasks/SendCurrentEmailConfirmation.php @@ -7,10 +7,9 @@ use common\emails\EmailHelper; use common\emails\templates\ChangeEmail; use common\models\confirmations\CurrentEmailConfirmation; use Yii; -use yii\mail\MailerInterface; use yii\queue\RetryableJobInterface; -class SendCurrentEmailConfirmation implements RetryableJobInterface { +final class SendCurrentEmailConfirmation implements RetryableJobInterface { public mixed $email = null; @@ -18,11 +17,8 @@ class SendCurrentEmailConfirmation implements RetryableJobInterface { public mixed $code = null; - public function __construct(public MailerInterface $mailer) { - } - public static function createFromConfirmation(CurrentEmailConfirmation $confirmation): self { - $result = new self(Yii::$app->mailer); + $result = new self(); $result->email = $confirmation->account->email; $result->username = $confirmation->account->username; $result->code = $confirmation->key; @@ -44,7 +40,7 @@ class SendCurrentEmailConfirmation implements RetryableJobInterface { */ public function execute($queue): void { Yii::$app->statsd->inc('queue.sendCurrentEmailConfirmation.attempt'); - $template = new ChangeEmail($this->mailer); + $template = new ChangeEmail(Yii::$app->mailer); $template->setKey($this->code); $template->send(EmailHelper::buildTo($this->username, $this->email)); } diff --git a/common/tests/unit/tasks/SendCurrentEmailConfirmationTest.php b/common/tests/unit/tasks/SendCurrentEmailConfirmationTest.php index 14d517b..042cacf 100644 --- a/common/tests/unit/tasks/SendCurrentEmailConfirmationTest.php +++ b/common/tests/unit/tasks/SendCurrentEmailConfirmationTest.php @@ -8,7 +8,6 @@ use common\models\AccountQuery; use common\models\confirmations\CurrentEmailConfirmation; use common\tasks\SendCurrentEmailConfirmation; use common\tests\unit\TestCase; -use Yii; use yii\queue\Queue; use yii\symfonymailer\Message; @@ -34,7 +33,7 @@ class SendCurrentEmailConfirmationTest extends TestCase { } public function testExecute(): void { - $task = new SendCurrentEmailConfirmation(Yii::$app->mailer); + $task = new SendCurrentEmailConfirmation(); $task->username = 'mock-username'; $task->email = 'mock@ely.by'; $task->code = 'GFEDCBA';