From ec190a18194218f4d468009f640f038bc4922b05 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 20 Oct 2022 12:24:41 +1300 Subject: [PATCH] FIX TestMailer instantiation --- src/Context/EmailContext.php | 6 +++++- src/Utility/TestMailer.php | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Context/EmailContext.php b/src/Context/EmailContext.php index 4418430..dae187b 100644 --- a/src/Context/EmailContext.php +++ b/src/Context/EmailContext.php @@ -10,7 +10,9 @@ use PHPUnit\Framework\Assert; use SilverStripe\BehatExtension\Utility\TestMailer; use SilverStripe\Core\Injector\Injector; use Symfony\Component\DomCrawler\Crawler; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Mailer\MailerInterface; +use Symfony\Component\Mailer\Transport\NullTransport; /** * Context used to define steps related to email sending. @@ -48,7 +50,9 @@ class EmailContext implements Context { // Also set through the 'supportbehat' extension // to ensure its available both in CLI execution and the tested browser session - $this->mailer = new TestMailer(); + $dispatcher = Injector::inst()->get(EventDispatcherInterface::class . '.mailer'); + $transport = new NullTransport($dispatcher); + $this->mailer = new TestMailer($transport, $dispatcher); Injector::inst()->registerService($this->mailer, MailerInterface::class); } diff --git a/src/Utility/TestMailer.php b/src/Utility/TestMailer.php index 3960a9c..2fc9586 100644 --- a/src/Utility/TestMailer.php +++ b/src/Utility/TestMailer.php @@ -2,8 +2,10 @@ namespace SilverStripe\BehatExtension\Utility; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use SilverStripe\Dev\TestMailer as BaseTestMailer; use SilverStripe\TestSession\TestSessionEnvironment; +use Symfony\Component\Mailer\Transport\TransportInterface; /** * Same principle as core TestMailer class, @@ -17,8 +19,11 @@ class TestMailer extends BaseTestMailer */ protected $testSessionEnvironment; - public function __construct() - { + public function __construct( + TransportInterface $transport, + EventDispatcherInterface $dispatcher + ) { + parent::__construct($transport, $dispatcher); $this->testSessionEnvironment = TestSessionEnvironment::singleton(); }