You are here

private function ConnectionTesterTest::getMockMailer in SMTP Authentication Support 8

Create a mock PHPMailer class for testing the exceptions.

Parameters

$result: Expected Result.

$exception: Exception passed in.

Return value

\PHPMailer\PHPMailer\PHPMailer|__anonymous@4029

1 call to ConnectionTesterTest::getMockMailer()
ConnectionTesterTest::testHookRequirements in tests/src/Kernel/ConnectionTester/ConnectionTesterTest.php
Test for hookRequirements().

File

tests/src/Kernel/ConnectionTester/ConnectionTesterTest.php, line 144

Class

ConnectionTesterTest
Tests SMTP connections.

Namespace

Drupal\Tests\smtp\Kernel\ConnectionTester

Code

private function getMockMailer($result, $exception) {
  $class = new class($result, $exception) extends PHPMailer {
    public function __construct($result, $exception) {
      $this->result = $result;
      $this->exception = $exception;
    }

    /**
     * Mock function for connection.
     */
    public function smtpConnect($options = NULL) {
      if ($this->exception) {
        $class = $this->exception;
        throw new $class('EXCEPTION MESSAGE');
      }
      return $this->result;
    }

  };
  return $class;
}