Merge pull request #230 from creative-commoners/pulls/5/mailer

FIX TestMailer instantiation
This commit is contained in:
Guy Sartorelli 2022-10-20 12:41:55 +13:00 committed by GitHub
commit cd724e539d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View File

@ -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);
}

View File

@ -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();
}