mirror of
https://github.com/silverstripe/silverstripe-testsession
synced 2024-10-22 14:06:00 +02:00
FIX TestMailer instantiation
This commit is contained in:
parent
5c73330ba7
commit
bc5974e551
@ -21,6 +21,7 @@ use SilverStripe\ORM\DatabaseAdmin;
|
||||
use SilverStripe\ORM\DB;
|
||||
use SilverStripe\ORM\FieldType\DBDatetime;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
use Symfony\Component\Mailer\MailerInterface;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
@ -320,16 +321,14 @@ class TestSessionEnvironment
|
||||
}
|
||||
|
||||
// Mailer
|
||||
$mailer = (isset($state->mailer)) ? $state->mailer : null;
|
||||
|
||||
if ($mailer) {
|
||||
if (!class_exists($mailer ?? '') || !is_subclass_of($mailer, 'SilverStripe\\Control\\Email\\Mailer')) {
|
||||
$mailer = $state->mailer ?? null;
|
||||
if ($mailer && !is_a($mailer, MailerInterface::class, true)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Class "%s" is not a valid class, or subclass of Mailer',
|
||||
$mailer
|
||||
'Class "%s" does not implement %s',
|
||||
$mailer,
|
||||
MailerInterface::class
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// Date and time
|
||||
if (isset($state->datetime)) {
|
||||
|
@ -4,12 +4,14 @@ namespace SilverStripe\TestSession;
|
||||
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\Control\Email\Email;
|
||||
use SilverStripe\Control\Email\Mailer;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Control\Middleware\HTTPMiddleware;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\ORM\DB;
|
||||
use SilverStripe\ORM\FieldType\DBDatetime;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\Mailer\MailerInterface;
|
||||
use Symfony\Component\Mailer\Transport\NullTransport;
|
||||
|
||||
/**
|
||||
* Sets state previously initialized through {@link TestSessionController}.
|
||||
@ -67,7 +69,12 @@ class TestSessionHTTPMiddleware implements HTTPMiddleware
|
||||
// Register mailer
|
||||
if (isset($testState->mailer)) {
|
||||
$mailer = $testState->mailer;
|
||||
Injector::inst()->registerService(new $mailer(), Mailer::class);
|
||||
$dispatcher = Injector::inst()->get(EventDispatcherInterface::class . '.mailer');
|
||||
$transport = new NullTransport($dispatcher);
|
||||
Injector::inst()->registerService(
|
||||
new $mailer($transport, $dispatcher),
|
||||
MailerInterface::class
|
||||
);
|
||||
Email::config()->set("send_all_emails_to", null);
|
||||
Email::config()->update('admin_email', 'no-reply@example.com');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user