diff --git a/src/Connector/Message.php b/src/Connector/Message.php index 79fc242..6ba9969 100644 --- a/src/Connector/Message.php +++ b/src/Connector/Message.php @@ -179,7 +179,8 @@ public function decodeAttachments(&$parameters) private function getSendDateTime(mixed $in): ?\DateTime { try { - $dt = $default = null; + $dt = null; + $default = null; if ((is_int($in) || is_float($in)) && $in > 0) { $dt = new \DateTime("now +{$in} seconds"); } @@ -193,10 +194,10 @@ private function getSendDateTime(mixed $in): ?\DateTime * Send via the queued job * @param string $domain the Mailgun API domain e.g sandboxXXXXXX.mailgun.org * @param array $parameters Mailgun API parameters - * @param mixed $in + * @param mixed $in See:http://php.net/manual/en/datetime.formats.relative.php * @return QueuedJobDescriptor|false */ - protected function queueAndSend($domain, $parameters, $in) + protected function queueAndSend(string $domain, array $parameters, mixed $in) { $this->encodeAttachments($parameters); $startAfter = null; @@ -253,7 +254,7 @@ public static function cleanMessageId($message_id): string * This is not the "o:deliverytime" option ("Messages can be scheduled for a maximum of 3 days in the future.") * To set "deliverytime" set it as an option to setOptions() */ - public function setSendIn(int $seconds) + public function setSendIn(int $seconds): static { $this->send_in_seconds = $seconds; return $this; diff --git a/src/Email/MailgunEmail.php b/src/Email/MailgunEmail.php index bd4d04b..17342a7 100644 --- a/src/Email/MailgunEmail.php +++ b/src/Email/MailgunEmail.php @@ -38,7 +38,7 @@ class MailgunEmail extends TaggableEmail implements EmailWithCustomParameters * @var \NSWDPC\Messaging\Mailgun\Connector\Message|null * @deprecated */ - private $connector = null; + private $connector; /** * Retrieve the connector instance diff --git a/src/Email/MailgunMailer.php b/src/Email/MailgunMailer.php index c64a68c..86f9d0f 100644 --- a/src/Email/MailgunMailer.php +++ b/src/Email/MailgunMailer.php @@ -64,7 +64,6 @@ public function getAlwaysFrom() /** * Retrieve and set custom parameters on the API connector - * @param EmailWithCustomParameters $email * @param MessageConnector $connector instance for this send attempt */ protected function assignCustomParameters(EmailWithCustomParameters &$email, MessageConnector &$connector): MessageConnector @@ -84,16 +83,15 @@ protected function assignCustomParameters(EmailWithCustomParameters &$email, Mes /** * Taggable: retrieve tags set via setNotificationTags() * Doing so will replace any tags assigned through setCustomParameters - * @param TaggableEmail $email * @param MessageConnector $connector connector instance for this send attempt - * @return MessageConnector */ protected function assignNotificationTags(TaggableEmail &$email, MessageConnector &$connector): MessageConnector { $tags = $email->getNotificationTags(); - if (empty($tags)) { + if ($tags === []) { return $connector; } + return $connector->setOption('tag', $tags); } @@ -147,7 +145,6 @@ public function processEmailDisplayName(array $data): array /** * Given a Swift_Message, prepare parameters for the API send - * @param Email $email * @return array of parameters for the Mailgun API */ public function prepareParameters(Email $email, MessageConnector $connector): array diff --git a/tests/MailgunSyncTest.php b/tests/MailgunSyncTest.php index eb20024..89f0f07 100644 --- a/tests/MailgunSyncTest.php +++ b/tests/MailgunSyncTest.php @@ -32,13 +32,18 @@ class MailgunSyncTest extends SapphireTest protected $test_api_domain = 'testing.example.net'; + // an email address + protected $to_address = "test@example.com"; + + // optional the recipient name + protected $to_name = "Test Tester"; - protected $to_address = "test@example.com";// an email address - protected $to_name = "Test Tester";// optional the recipient name // Ditto if testing cc protected $cc_address = ""; + // From header protected $from_address = "from@example.com"; + protected $from_name = "From Tester";// option the from name (e.g for 'Joe ' formatting) // Test body HTML protected $test_body = "

Header provider strategic

" @@ -168,6 +173,7 @@ public function testMailerDelivery($subject = "test_mailer_delivery", $send_in = if ($cc = $this->cc_address) { $email->setCc($cc); } + $htmlBody = $this->test_body; $email->setBody($htmlBody); @@ -360,14 +366,16 @@ public function testAPIDelivery(): void Config::modify()->set(Base::class, 'send_via_job', 'no'); $connector = MessageConnector::create(); - $to = $to_address = $this->to_address; + $to = $this->to_address; + $to_address = $this->to_address; $to_name = $this->to_name; if ($to_name) { $to = $to_name . ' <' . $to_address . '>'; } $this->assertNotEmpty($to_address); - $from = $from_address = $this->from_address; + $from = $this->from_address; + $from_address = $this->from_address; $from_name = $this->from_name; if ($from_name) { $from = $from_name . ' <' . $from_address . '>'; @@ -411,7 +419,7 @@ public function testAPIDelivery(): void /** * Test that tags can be set via Taggable */ - public function testTaggableEmail() + public function testTaggableEmail(): void { $limit = 3; @@ -443,6 +451,7 @@ public function testTaggableEmail() if ($cc = $this->cc_address) { $email->setCc($cc); } + $email->setBody($this->test_body); $tags = ['tagheader1','tagheader2','tagheader3']; $email->setNotificationTags($tags); @@ -542,7 +551,7 @@ public function testSendWithDefaultConfiguration(): void /** * test a message with attachments */ - public function testAttachmentDelivery() + public function testAttachmentDelivery(): void { $to_address = $this->to_address; $to_name = $this->to_name; @@ -566,6 +575,7 @@ public function testAttachmentDelivery() $email->setFrom($from); $email->setTo($to); $email->setSubject($subject); + $htmlBody = $this->test_body; $email->setBody($htmlBody);