From 2890781a56235162f58b6fefa7e5e36e9ce99b0a Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Wed, 6 May 2026 22:06:30 +0300 Subject: [PATCH] add Emailer and EmailFactory interfaces with laravel + fake impls --- backend/app/Email/EmailFactory.php | 8 ++++++ backend/app/Email/Emailer.php | 8 ++++++ backend/app/Email/LaravelEmailFactory.php | 15 ++++++++++ backend/app/Email/LaravelMailer.php | 25 ++++++++++++++++ backend/tests/Fakes/FakeEmailFactory.php | 13 +++++++++ backend/tests/Fakes/FakeEmailer.php | 35 +++++++++++++++++++++++ 6 files changed, 104 insertions(+) create mode 100644 backend/app/Email/EmailFactory.php create mode 100644 backend/app/Email/Emailer.php create mode 100644 backend/app/Email/LaravelEmailFactory.php create mode 100644 backend/app/Email/LaravelMailer.php create mode 100644 backend/tests/Fakes/FakeEmailFactory.php create mode 100644 backend/tests/Fakes/FakeEmailer.php diff --git a/backend/app/Email/EmailFactory.php b/backend/app/Email/EmailFactory.php new file mode 100644 index 0000000..43307ad --- /dev/null +++ b/backend/app/Email/EmailFactory.php @@ -0,0 +1,8 @@ +confirmationUrlPrefix}{$token}"; + } +} diff --git a/backend/app/Email/LaravelMailer.php b/backend/app/Email/LaravelMailer.php new file mode 100644 index 0000000..cf41752 --- /dev/null +++ b/backend/app/Email/LaravelMailer.php @@ -0,0 +1,25 @@ +mailer->raw( + $body, + function (Message $message) use ($from, $to) { + $message->from($from) + ->to($to) + ->subject('TIDE'); + } + ); + } +} diff --git a/backend/tests/Fakes/FakeEmailFactory.php b/backend/tests/Fakes/FakeEmailFactory.php new file mode 100644 index 0000000..b6fb069 --- /dev/null +++ b/backend/tests/Fakes/FakeEmailFactory.php @@ -0,0 +1,13 @@ + + */ + private array $sentEmails = []; + + public function send(string $from, string $to, string $body): void + { + $this->sentEmails[] = [ + 'from' => $from, + 'to' => $to, + 'body' => $body, + ]; + } + + public function getNumberOfEmailsSent(): int + { + return count($this->sentEmails); + } + + /** + * @return array + */ + public function getSentEmails(): array + { + return $this->sentEmails; + } +}