Merge pull request #231 from creative-commoners/pulls/5/broken-builds

FIX Restore adding sent emails to test session state
This commit is contained in:
Guy Sartorelli 2022-10-25 14:14:53 +13:00 committed by GitHub
commit 8c06503294
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 0 deletions

View File

@ -2,10 +2,14 @@
namespace SilverStripe\BehatExtension\Utility;
use InvalidArgumentException;
use SilverStripe\Control\Email\Email;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use SilverStripe\Dev\TestMailer as BaseTestMailer;
use SilverStripe\TestSession\TestSessionEnvironment;
use Symfony\Component\Mailer\Envelope;
use Symfony\Component\Mailer\Transport\TransportInterface;
use Symfony\Component\Mime\RawMessage;
/**
* Same principle as core TestMailer class,
@ -27,6 +31,21 @@ class TestMailer extends BaseTestMailer
$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
*/