Add basic interface for MailerMethod

[MAILPOET-4115]
This commit is contained in:
Rostislav Wolny
2022-03-24 14:53:17 +01:00
committed by Veljko V
parent eb07872d13
commit b10c30a7b1
7 changed files with 19 additions and 12 deletions

View File

@ -8,7 +8,7 @@ use MailPoet\Mailer\Methods\ErrorMappers\AmazonSESMapper;
use MailPoet\WP\Functions as WPFunctions; use MailPoet\WP\Functions as WPFunctions;
use MailPoetVendor\Swift_Message; use MailPoetVendor\Swift_Message;
class AmazonSES { class AmazonSES implements MailerMethod {
public $awsAccessKey; public $awsAccessKey;
public $awsSecretKey; public $awsSecretKey;
public $awsRegion; public $awsRegion;
@ -93,7 +93,7 @@ class AmazonSES {
$this->blacklist = new BlacklistCheck(); $this->blacklist = new BlacklistCheck();
} }
public function send($newsletter, $subscriber, $extraParams = []) { public function send($newsletter, $subscriber, $extraParams = []): array {
if ($this->blacklist->isBlacklisted($subscriber)) { if ($this->blacklist->isBlacklisted($subscriber)) {
$error = $this->errorMapper->getBlacklistError($subscriber); $error = $this->errorMapper->getBlacklistError($subscriber);
return Mailer::formatMailerErrorResult($error); return Mailer::formatMailerErrorResult($error);

View File

@ -11,7 +11,7 @@ use MailPoet\Services\AuthorizedEmailsController;
use MailPoet\Services\Bridge; use MailPoet\Services\Bridge;
use MailPoet\Services\Bridge\API; use MailPoet\Services\Bridge\API;
class MailPoet { class MailPoet implements MailerMethod {
public $api; public $api;
public $sender; public $sender;
public $replyTo; public $replyTo;
@ -42,7 +42,7 @@ class MailPoet {
$this->blacklist = new BlacklistCheck(); $this->blacklist = new BlacklistCheck();
} }
public function send($newsletter, $subscriber, $extraParams = []) { public function send($newsletter, $subscriber, $extraParams = []): array {
if ($this->servicesChecker->isMailPoetAPIKeyValid() === false) { if ($this->servicesChecker->isMailPoetAPIKeyValid() === false) {
return Mailer::formatMailerErrorResult($this->errorMapper->getInvalidApiKeyError()); return Mailer::formatMailerErrorResult($this->errorMapper->getInvalidApiKeyError());
} }

View File

@ -0,0 +1,7 @@
<?php
namespace MailPoet\Mailer\Methods;
interface MailerMethod {
public function send($newsletter, $subscriber, $extraParams = []): array;
}

View File

@ -9,7 +9,7 @@ use MailPoet\Mailer\WordPress\PHPMailerLoader;
PHPMailerLoader::load(); PHPMailerLoader::load();
class PHPMail { class PHPMail implements MailerMethod {
public $sender; public $sender;
public $replyTo; public $replyTo;
public $returnPath; public $returnPath;
@ -37,7 +37,7 @@ class PHPMail {
$this->blacklist = new BlacklistCheck(); $this->blacklist = new BlacklistCheck();
} }
public function send($newsletter, $subscriber, $extraParams = []) { public function send($newsletter, $subscriber, $extraParams = []): array {
if ($this->blacklist->isBlacklisted($subscriber)) { if ($this->blacklist->isBlacklisted($subscriber)) {
$error = $this->errorMapper->getBlacklistError($subscriber); $error = $this->errorMapper->getBlacklistError($subscriber);
return Mailer::formatMailerErrorResult($error); return Mailer::formatMailerErrorResult($error);

View File

@ -12,7 +12,7 @@ use MailPoetVendor\Swift_Plugins_LoggerPlugin;
use MailPoetVendor\Swift_Plugins_Loggers_ArrayLogger; use MailPoetVendor\Swift_Plugins_Loggers_ArrayLogger;
use MailPoetVendor\Swift_SmtpTransport; use MailPoetVendor\Swift_SmtpTransport;
class SMTP { class SMTP implements MailerMethod {
public $host; public $host;
public $port; public $port;
public $authentication; public $authentication;
@ -65,7 +65,7 @@ class SMTP {
$this->blacklist = new BlacklistCheck(); $this->blacklist = new BlacklistCheck();
} }
public function send($newsletter, $subscriber, $extraParams = []) { public function send($newsletter, $subscriber, $extraParams = []): array {
if ($this->blacklist->isBlacklisted($subscriber)) { if ($this->blacklist->isBlacklisted($subscriber)) {
$error = $this->errorMapper->getBlacklistError($subscriber); $error = $this->errorMapper->getBlacklistError($subscriber);
return Mailer::formatMailerErrorResult($error); return Mailer::formatMailerErrorResult($error);

View File

@ -7,7 +7,7 @@ use MailPoet\Mailer\Methods\Common\BlacklistCheck;
use MailPoet\Mailer\Methods\ErrorMappers\SendGridMapper; use MailPoet\Mailer\Methods\ErrorMappers\SendGridMapper;
use MailPoet\WP\Functions as WPFunctions; use MailPoet\WP\Functions as WPFunctions;
class SendGrid { class SendGrid implements MailerMethod {
public $url = 'https://api.sendgrid.com/api/mail.send.json'; public $url = 'https://api.sendgrid.com/api/mail.send.json';
public $apiKey; public $apiKey;
public $sender; public $sender;
@ -35,7 +35,7 @@ class SendGrid {
$this->blacklist = new BlacklistCheck(); $this->blacklist = new BlacklistCheck();
} }
public function send($newsletter, $subscriber, $extraParams = []) { public function send($newsletter, $subscriber, $extraParams = []): array {
if ($this->blacklist->isBlacklisted($subscriber)) { if ($this->blacklist->isBlacklisted($subscriber)) {
$error = $this->errorMapper->getBlacklistError($subscriber); $error = $this->errorMapper->getBlacklistError($subscriber);
return Mailer::formatMailerErrorResult($error); return Mailer::formatMailerErrorResult($error);

View File

@ -117,7 +117,7 @@ class MailerTest extends \MailPoetTest {
'mailerInstance' => Stub::make( 'mailerInstance' => Stub::make(
$phpMailClass, $phpMailClass,
['send' => Expected::exactly(1, function() { ['send' => Expected::exactly(1, function() {
return true; return ['response' => true];
})], })],
$this $this
), ),
@ -130,7 +130,7 @@ class MailerTest extends \MailPoetTest {
expect($mailerTask->mailer->mailerInstance instanceof $phpMailClass) expect($mailerTask->mailer->mailerInstance instanceof $phpMailClass)
->true(); ->true();
// send method should return true // send method should return true
expect($mailerTask->send('Newsletter', 'Subscriber'))->true(); expect($mailerTask->send('Newsletter', 'Subscriber'))->equals(['response' => true]);
} }
public function _after() { public function _after() {