mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 17:05:32 +02:00
FIX Restore adding sent emails to test session state
This commit is contained in:
parent
cd724e539d
commit
6c2f9b7b24
@ -2,10 +2,14 @@
|
|||||||
|
|
||||||
namespace SilverStripe\BehatExtension\Utility;
|
namespace SilverStripe\BehatExtension\Utility;
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
|
use SilverStripe\Control\Email\Email;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use SilverStripe\Dev\TestMailer as BaseTestMailer;
|
use SilverStripe\Dev\TestMailer as BaseTestMailer;
|
||||||
use SilverStripe\TestSession\TestSessionEnvironment;
|
use SilverStripe\TestSession\TestSessionEnvironment;
|
||||||
|
use Symfony\Component\Mailer\Envelope;
|
||||||
use Symfony\Component\Mailer\Transport\TransportInterface;
|
use Symfony\Component\Mailer\Transport\TransportInterface;
|
||||||
|
use Symfony\Component\Mime\RawMessage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Same principle as core TestMailer class,
|
* Same principle as core TestMailer class,
|
||||||
@ -27,6 +31,21 @@ class TestMailer extends BaseTestMailer
|
|||||||
$this->testSessionEnvironment = TestSessionEnvironment::singleton();
|
$this->testSessionEnvironment = TestSessionEnvironment::singleton();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function send(RawMessage $message, Envelope $envelope = null): void
|
||||||
|
{
|
||||||
|
parent::send($message, $envelope);
|
||||||
|
/** @var Email $email */
|
||||||
|
$email = $message;
|
||||||
|
$data = $this->createData($email);
|
||||||
|
// save email to testsession state
|
||||||
|
$state = $this->testSessionEnvironment->getState();
|
||||||
|
if (!isset($state->emails)) {
|
||||||
|
$state->emails = array();
|
||||||
|
}
|
||||||
|
$state->emails[] = array_filter($data ?? []);
|
||||||
|
$this->testSessionEnvironment->applyState($state);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear the log of emails sent
|
* Clear the log of emails sent
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user