FIX TestMailer instantiation

This commit is contained in:
Steve Boyd 2022-10-20 12:24:41 +13:00
parent 1786ce115d
commit ec190a1819
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();
}