Refactor mailerInstance property to mailerMethod
Naming mailerInstance was confusing since it is not instance of Mailer class but instance of MailerMethod. [MAILPOET-4115]
This commit is contained in:
committed by
Veljko V
parent
708333e68a
commit
789385b0c4
@@ -53,7 +53,7 @@ class Mailer {
|
||||
}
|
||||
|
||||
public function getProcessingMethod() {
|
||||
return ($this->mailer->mailerInstance instanceof MailPoet) ?
|
||||
return ($this->mailer->mailerMethod instanceof MailPoet) ?
|
||||
'bulk' :
|
||||
'individual';
|
||||
}
|
||||
@@ -66,7 +66,7 @@ class Mailer {
|
||||
if ($this->getProcessingMethod() === 'individual') {
|
||||
throw new \LogicException('Trying to send a batch with individual processing method');
|
||||
}
|
||||
return $this->mailer->mailerInstance->send(
|
||||
return $this->mailer->mailerMethod->send(
|
||||
$preparedNewsletters,
|
||||
$preparedSubscribers,
|
||||
$extraParams
|
||||
@@ -77,7 +77,7 @@ class Mailer {
|
||||
if ($this->getProcessingMethod() === 'bulk') {
|
||||
throw new \LogicException('Trying to send an individual email with a bulk processing method');
|
||||
}
|
||||
return $this->mailer->mailerInstance->send(
|
||||
return $this->mailer->mailerMethod->send(
|
||||
$preparedNewsletter,
|
||||
$preparedSubscriber,
|
||||
$extraParams
|
||||
|
@@ -8,7 +8,7 @@ use MailPoet\Models\Subscriber;
|
||||
|
||||
class Mailer {
|
||||
/** @var MailerMethod */
|
||||
public $mailerInstance;
|
||||
public $mailerMethod;
|
||||
|
||||
const MAILER_CONFIG_SETTING_NAME = 'mta';
|
||||
const SENDING_LIMIT_INTERVAL_MULTIPLIER = 60;
|
||||
@@ -19,9 +19,9 @@ class Mailer {
|
||||
const METHOD_SMTP = 'SMTP';
|
||||
|
||||
public function __construct(
|
||||
MailerMethod $mailerInstance
|
||||
MailerMethod $mailerMethod
|
||||
) {
|
||||
$this->mailerInstance = $mailerInstance;
|
||||
$this->mailerMethod = $mailerMethod;
|
||||
}
|
||||
|
||||
public function send($newsletter, $subscriber, $extraParams = []) {
|
||||
@@ -31,7 +31,7 @@ class Mailer {
|
||||
$subscriber = Subscriber::findOne($subscriber->getId());
|
||||
}
|
||||
$subscriber = $this->formatSubscriberNameAndEmailAddress($subscriber);
|
||||
return $this->mailerInstance->send($newsletter, $subscriber, $extraParams);
|
||||
return $this->mailerMethod->send($newsletter, $subscriber, $extraParams);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -50,7 +50,7 @@ class MailerFactory {
|
||||
$returnPath = $returnPath ?? $this->getReturnPathAddress($sender);
|
||||
switch ($mailerConfig['method']) {
|
||||
case Mailer::METHOD_AMAZONSES:
|
||||
$mailerInstance = new AmazonSES(
|
||||
$mailerMethod = new AmazonSES(
|
||||
$mailerConfig['region'],
|
||||
$mailerConfig['access_key'],
|
||||
$mailerConfig['secret_key'],
|
||||
@@ -61,7 +61,7 @@ class MailerFactory {
|
||||
);
|
||||
break;
|
||||
case Mailer::METHOD_MAILPOET:
|
||||
$mailerInstance = new MailPoet(
|
||||
$mailerMethod = new MailPoet(
|
||||
$mailerConfig['mailpoet_api_key'],
|
||||
$sender,
|
||||
$replyTo,
|
||||
@@ -70,7 +70,7 @@ class MailerFactory {
|
||||
);
|
||||
break;
|
||||
case Mailer::METHOD_SENDGRID:
|
||||
$mailerInstance = new SendGrid(
|
||||
$mailerMethod = new SendGrid(
|
||||
$mailerConfig['api_key'],
|
||||
$sender,
|
||||
$replyTo,
|
||||
@@ -78,7 +78,7 @@ class MailerFactory {
|
||||
);
|
||||
break;
|
||||
case Mailer::METHOD_PHPMAIL:
|
||||
$mailerInstance = new PHPMail(
|
||||
$mailerMethod = new PHPMail(
|
||||
$sender,
|
||||
$replyTo,
|
||||
$returnPath,
|
||||
@@ -86,7 +86,7 @@ class MailerFactory {
|
||||
);
|
||||
break;
|
||||
case Mailer::METHOD_SMTP:
|
||||
$mailerInstance = new SMTP(
|
||||
$mailerMethod = new SMTP(
|
||||
$mailerConfig['host'],
|
||||
$mailerConfig['port'],
|
||||
$mailerConfig['authentication'],
|
||||
@@ -102,7 +102,7 @@ class MailerFactory {
|
||||
default:
|
||||
throw new InvalidStateException(__('Mailing method does not exist.', 'mailpoet'));
|
||||
}
|
||||
return new Mailer($mailerInstance);
|
||||
return new Mailer($mailerMethod);
|
||||
}
|
||||
|
||||
private function getMailerConfig(): array {
|
||||
|
@@ -110,7 +110,7 @@ class MailerTest extends \MailPoetTest {
|
||||
public function testItCanSend() {
|
||||
$phpMailClass = 'MailPoet\Mailer\Methods\PHPMail';
|
||||
$mailerMock = Stub::makeEmpty(Mailer::class, [
|
||||
'mailerInstance' => Stub::make(
|
||||
'mailerMethod' => Stub::make(
|
||||
$phpMailClass,
|
||||
['send' => Expected::exactly(1, function() {
|
||||
return ['response' => true];
|
||||
|
@@ -101,32 +101,32 @@ class MailerFactoryTest extends \MailPoetTest {
|
||||
public function testItCanBuildCorrectMailerMethodsBasedOnConfig() {
|
||||
$this->settings->set('mta', $this->mtaConfigs[Mailer::METHOD_PHPMAIL]);
|
||||
$mailer = $this->factory->getDefaultMailer();
|
||||
$this->assertInstanceOf(PHPMail::class, $mailer->mailerInstance);
|
||||
$this->assertInstanceOf(PHPMail::class, $mailer->mailerMethod);
|
||||
|
||||
$this->factory = new MailerFactory($this->settings, $this->diContainer->get(WPFunctions::class));
|
||||
$this->settings->set('mta', $this->mtaConfigs[Mailer::METHOD_AMAZONSES]);
|
||||
$mailer = $this->factory->getDefaultMailer();
|
||||
$this->assertInstanceOf(AmazonSES::class, $mailer->mailerInstance);
|
||||
$this->assertInstanceOf(AmazonSES::class, $mailer->mailerMethod);
|
||||
|
||||
$this->factory = new MailerFactory($this->settings, $this->diContainer->get(WPFunctions::class));
|
||||
$this->settings->set('mta', $this->mtaConfigs[Mailer::METHOD_MAILPOET]);
|
||||
$mailer = $this->factory->getDefaultMailer();
|
||||
$this->assertInstanceOf(MailPoet::class, $mailer->mailerInstance);
|
||||
$this->assertInstanceOf(MailPoet::class, $mailer->mailerMethod);
|
||||
|
||||
$this->factory = new MailerFactory($this->settings, $this->diContainer->get(WPFunctions::class));
|
||||
$this->settings->set('mta', $this->mtaConfigs[Mailer::METHOD_SMTP]);
|
||||
$mailer = $this->factory->getDefaultMailer();
|
||||
$this->assertInstanceOf(SMTP::class, $mailer->mailerInstance);
|
||||
$this->assertInstanceOf(SMTP::class, $mailer->mailerMethod);
|
||||
|
||||
$this->factory = new MailerFactory($this->settings, $this->diContainer->get(WPFunctions::class));
|
||||
$this->settings->set('mta', $this->mtaConfigs[Mailer::METHOD_SENDGRID]);
|
||||
$mailer = $this->factory->getDefaultMailer();
|
||||
$this->assertInstanceOf(SendGrid::class, $mailer->mailerInstance);
|
||||
$this->assertInstanceOf(SendGrid::class, $mailer->mailerMethod);
|
||||
}
|
||||
|
||||
public function testItUsesProcessedSenderDataFromSettings() {
|
||||
$mailer = $this->factory->getDefaultMailer();
|
||||
$mailerMethod = $mailer->mailerInstance;
|
||||
$mailerMethod = $mailer->mailerMethod;
|
||||
$this->assertInstanceOf(PHPMail::class, $mailerMethod);
|
||||
expect($mailerMethod->sender)->equals([
|
||||
'from_name' => 'Sender',
|
||||
@@ -144,7 +144,7 @@ class MailerFactoryTest extends \MailPoetTest {
|
||||
public function testItUsesSenderAsReplyToWhenReplyToIsNotSet() {
|
||||
$this->settings->set('reply_to', null);
|
||||
$mailer = $this->factory->getDefaultMailer();
|
||||
$mailerMethod = $mailer->mailerInstance;
|
||||
$mailerMethod = $mailer->mailerMethod;
|
||||
$this->assertInstanceOf(PHPMail::class, $mailerMethod);
|
||||
expect($mailerMethod->replyTo)->equals([
|
||||
'reply_to_name' => 'Sender',
|
||||
@@ -156,7 +156,7 @@ class MailerFactoryTest extends \MailPoetTest {
|
||||
public function testItIgnoresInvalidBounceAddressAndUsesSenderAddressInstead() {
|
||||
$this->settings->set('bounce.address', 'invalid');
|
||||
$mailer = $this->factory->getDefaultMailer();
|
||||
$mailerMethod = $mailer->mailerInstance;
|
||||
$mailerMethod = $mailer->mailerMethod;
|
||||
$this->assertInstanceOf(PHPMail::class, $mailerMethod);
|
||||
expect($mailerMethod->returnPath)->equals('sender@email.com');
|
||||
}
|
||||
@@ -164,7 +164,7 @@ class MailerFactoryTest extends \MailPoetTest {
|
||||
public function testItUsesSenderAddressInReplyToInCaseReplyToHasOnlyName() {
|
||||
$this->settings->set('reply_to', ['name' => 'Reply To']);
|
||||
$mailer = $this->factory->getDefaultMailer();
|
||||
$mailerMethod = $mailer->mailerInstance;
|
||||
$mailerMethod = $mailer->mailerMethod;
|
||||
$this->assertInstanceOf(PHPMail::class, $mailerMethod);
|
||||
expect($mailerMethod->replyTo)->equals([
|
||||
'reply_to_name' => 'Reply To',
|
||||
@@ -184,7 +184,7 @@ class MailerFactoryTest extends \MailPoetTest {
|
||||
'address' => 'staff@mailinator.com',
|
||||
]);
|
||||
$mailer = $this->factory->getDefaultMailer();
|
||||
$mailerMethod = $mailer->mailerInstance;
|
||||
$mailerMethod = $mailer->mailerMethod;
|
||||
$this->assertInstanceOf(PHPMail::class, $mailerMethod);
|
||||
expect($mailerMethod->sender['from_name'])->equals(sprintf('=?utf-8?B?%s?=', base64_encode('Sender Außergewöhnlichen тест системы')));
|
||||
expect($mailerMethod->replyTo['reply_to_name'])->equals(sprintf('=?utf-8?B?%s?=', base64_encode('Reply-To Außergewöhnlichen тест системы')));
|
||||
|
Reference in New Issue
Block a user