From 6c2f9b7b2451a9c3dec422a20b92e99660b7a878 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 25 Oct 2022 13:41:57 +1300 Subject: [PATCH] FIX Restore adding sent emails to test session state --- src/Utility/TestMailer.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Utility/TestMailer.php b/src/Utility/TestMailer.php index 2fc9586..b892812 100644 --- a/src/Utility/TestMailer.php +++ b/src/Utility/TestMailer.php @@ -2,10 +2,14 @@ namespace SilverStripe\BehatExtension\Utility; +use InvalidArgumentException; +use SilverStripe\Control\Email\Email; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use SilverStripe\Dev\TestMailer as BaseTestMailer; use SilverStripe\TestSession\TestSessionEnvironment; +use Symfony\Component\Mailer\Envelope; use Symfony\Component\Mailer\Transport\TransportInterface; +use Symfony\Component\Mime\RawMessage; /** * Same principle as core TestMailer class, @@ -27,6 +31,21 @@ class TestMailer extends BaseTestMailer $this->testSessionEnvironment = TestSessionEnvironment::singleton(); } + public function send(RawMessage $message, Envelope $envelope = null): void + { + parent::send($message, $envelope); + /** @var Email $email */ + $email = $message; + $data = $this->createData($email); + // save email to testsession state + $state = $this->testSessionEnvironment->getState(); + if (!isset($state->emails)) { + $state->emails = array(); + } + $state->emails[] = array_filter($data ?? []); + $this->testSessionEnvironment->applyState($state); + } + /** * Clear the log of emails sent */