diff --git a/tests/behat/features/bootstrap/EmailContext.php b/tests/behat/features/bootstrap/EmailContext.php index 01beb84976c..2868e185efe 100644 --- a/tests/behat/features/bootstrap/EmailContext.php +++ b/tests/behat/features/bootstrap/EmailContext.php @@ -10,7 +10,7 @@ use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\SplFileInfo; use Symfony\Component\Mime\Email as MimeEmail; -use Drupal\symfony_mailer\Email as SymfonyEmail; +use Drupal\symfony_mailer\Email as DrupalSymfonyEmail; use Symfony\Component\Mime\Header\Headers; use Symfony\Component\Mime\Header\UnstructuredHeader; use Drupal\symfony_mailer\Address; @@ -88,26 +88,14 @@ public function extractSentEmails(AfterScenarioScope $afterScenario) : void { return; } - $exts = [ - "text/html" => "html", - "text/plain" => "txt", - ]; - $spool_directory = $this->getSpoolDir(); $emails = $this->getSpooledEmails(); foreach ($emails as $serialized) { $path = $spool_directory . DIRECTORY_SEPARATOR . $serialized->getBasename($serialized->getExtension()); - $email = $this->getEmailContent($serialized); - assert($email instanceof MimeEmail); - - // foreach ($email->getChildren() as $i => $part) { - // file_put_contents($path . ($exts[$part->getContentType()] ?? "{$i}.unknown"), $part->getHtmlBody()); - // } - // The primary (preferred) body is not considered to be a child, so we - // must treat it separately. - file_put_contents($path . "body", $email->getHtmlBody()); + file_put_contents($path . "html", $email->getHtmlBody()); + file_put_contents($path . "txt", $email->getTextBody()); file_put_contents($path . "metadata", $email->getHeaders()->toString()); } } @@ -344,7 +332,6 @@ protected function findEmailsWithSubject(string $subject) : array { $emails = []; foreach ($finder as $file) { $email = $this->getEmailContent($file); - assert($email instanceof SymfonyEmail); if ($email->getSubject() === $subject) { $emails[] = $email; @@ -395,13 +382,13 @@ protected function getSpoolDir() : string { * @param \Symfony\Component\Finder\SplFileInfo $file * The .message file to get content for. * - * @return + * @return \Drupal\symfony_mailer\Email * A deserialized email. */ - protected function getEmailContent(SplFileInfo $file) { + protected function getEmailContent(SplFileInfo $file) : DrupalSymfonyEmail { assert($file->getExtension() === "message", "File passed to " . __FUNCTION__ . " must be a serialized .message file."); return unserialize(file_get_contents($file), ["allowed_classes" => [ - SymfonyEmail::class, + DrupalSymfonyEmail::class, Headers::class, UnstructuredHeader::class, Address::class,