Commit c33a67ec authored by Adam Shepherd's avatar Adam Shepherd
Browse files

Issue #3271802 by AdamPS: Write automatic tests

parent 2c71c64e
Loading
Loading
Loading
Loading
+19 −0
Changes for src/Email.php: 19 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -539,4 +539,23 @@ class Email implements InternalEmailInterface {
    return $this;
  }

  /**
   * {@inheritdoc}
   *
   * Serialization is intended only for testing.
   *
   * @internal
   */
  public function __serialize() {
    return [$this->subject, $this->addresses, $this->inner];
  }

  /**
   * {@inheritdoc}
   */
  public function __unserialize(array $data) {
    $this->phase = self::PHASE_POST_SEND;
    [$this->subject, $this->addresses, $this->inner] = $data;
  }

}
+1 −0
Changes for src/Processor/EmailProcessorInterface.php: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ interface EmailProcessorInterface {
    EmailInterface::PHASE_BUILD => 'build',
    EmailInterface::PHASE_PRE_RENDER => 'preRender',
    EmailInterface::PHASE_POST_RENDER => 'postRender',
    EmailInterface::PHASE_POST_SEND => 'postSend',
  ];

  /**
+36 −0
Changes for tests/modules/symfony_mailer_test/src/MailerTest.php: 36 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\symfony_mailer_test;

use Drupal\symfony_mailer\EmailInterface;
use Drupal\symfony_mailer\Processor\EmailProcessorCustomBase;

/**
 * Tracks sent emails for testing.
 */
class MailerTest extends EmailProcessorCustomBase {

  /**
   * {@inheritdoc}
   */
  public function postRender(EmailInterface $email) {
    $email->setTransportDsn('null://default');
  }

  /**
   * {@inheritdoc}
   */
  public function postSend(EmailInterface $email) {
    $emails = \Drupal::state()->get('mailer_test.emails', []);
    $emails[] = $email;
    \Drupal::state()->set('mailer_test.emails', $emails);
  }

  /**
   * {@inheritdoc}
   */
  protected function getWeight(int $phase) {
    return 10000;
  }

}
+7 −0
Changes for tests/modules/symfony_mailer_test/symfony_mailer_test.info.yml: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
name: Symfony Mailer Test
type: module
package: Mail
hidden: true
core_version_requirement: ^9.1
dependencies:
  - symfony_mailer:symfony_mailer
+16 −0
Changes for tests/modules/symfony_mailer_test/symfony_mailer_test.module: 16 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Hook implementations for the Symfony Mailer test module.
 */

use Drupal\symfony_mailer\EmailInterface;
use Drupal\symfony_mailer_test\MailerTest;

/**
 * Implements hook_mailer_init().
 */
function symfony_mailer_test_mailer_init(EmailInterface $email) {
  (new MailerTest())->init($email);
}
Loading