Skip to content

Commit

Permalink
FIX TestMailer instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Oct 19, 2022
1 parent 1786ce1 commit ed37563
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/Context/EmailContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
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.
Expand Down Expand Up @@ -48,7 +50,9 @@ public function before(BeforeScenarioScope $event)
{
// 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);
}

Expand Down
10 changes: 8 additions & 2 deletions src/Utility/TestMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

namespace SilverStripe\BehatExtension\Utility;

use Psr\EventDispatcher\EventDispatcherInterface;
use SilverStripe\Dev\TestMailer as BaseTestMailer;
use SilverStripe\TestSession\TestSessionEnvironment;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mailer\Transport\TransportInterface;

/**
* Same principle as core TestMailer class,
Expand All @@ -17,8 +20,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();
}

Expand Down

0 comments on commit ed37563

Please sign in to comment.