Skip to content

Commit

Permalink
(rector) process results
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesDPC committed Aug 14, 2024
1 parent 8ef4f8f commit 7577fe4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
9 changes: 5 additions & 4 deletions src/Connector/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Email/MailgunEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions src/Email/MailgunMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down
22 changes: 16 additions & 6 deletions tests/MailgunSyncTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@ class MailgunSyncTest extends SapphireTest

protected $test_api_domain = 'testing.example.net';

// an email address
protected $to_address = "[email protected]";

// optional the recipient name
protected $to_name = "Test Tester";

protected $to_address = "[email protected]";// an email address
protected $to_name = "Test Tester";// optional the recipient name
// Ditto if testing cc
protected $cc_address = "";

// From header
protected $from_address = "[email protected]";

protected $from_name = "From Tester";// option the from name (e.g for 'Joe <[email protected]>' formatting)
// Test body HTML
protected $test_body = "<h1>Header provider strategic</h1>"
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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 . '>';
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -566,6 +575,7 @@ public function testAttachmentDelivery()
$email->setFrom($from);
$email->setTo($to);
$email->setSubject($subject);

$htmlBody = $this->test_body;
$email->setBody($htmlBody);

Expand Down

0 comments on commit 7577fe4

Please sign in to comment.