From fc9685182bd1e0279019fd488a721777bbdf1ab4 Mon Sep 17 00:00:00 2001 From: Travis Swientek Date: Mon, 7 Oct 2013 13:53:23 -0700 Subject: [PATCH] Fixed missing IDs for batch message recipients. Closes #15. --- src/Mailgun/Messages/BatchMessage.php | 4 +++- tests/Mailgun/Tests/Messages/BatchMessageTest.php | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Mailgun/Messages/BatchMessage.php b/src/Mailgun/Messages/BatchMessage.php index 04a7715..f1c8094 100644 --- a/src/Mailgun/Messages/BatchMessage.php +++ b/src/Mailgun/Messages/BatchMessage.php @@ -36,7 +36,9 @@ class BatchMessage extends MessageBuilder{ } $this->addRecipient("to", $address, $variables); - $attributes["id"] = $this->toRecipientCount; + if(!array_key_exists("id", $variables)){ + $variables['id'] = $this->toRecipientCount; + } $this->batchRecipientAttributes["$address"] = $variables; } diff --git a/tests/Mailgun/Tests/Messages/BatchMessageTest.php b/tests/Mailgun/Tests/Messages/BatchMessageTest.php index 6d17da6..dea0af9 100644 --- a/tests/Mailgun/Tests/Messages/BatchMessageTest.php +++ b/tests/Mailgun/Tests/Messages/BatchMessageTest.php @@ -59,6 +59,16 @@ class BatchMessageTest extends \Mailgun\Tests\MailgunTestCase{ $property->setAccessible(true); $this->assertEquals(1, $property->getValue($message)); } + public function testDefaultIDInVariables() { + $message = $this->client->BatchMessage($this->sampleDomain); + $message->addToRecipient("test-user@samples.mailgun.org", array("first" => "Test", "last" => "User")); + + $reflectionClass = new \ReflectionClass(get_class($message)); + $property = $reflectionClass->getProperty('batchRecipientAttributes'); + $property->setAccessible(True); + $propertyValue = $property->getValue($message); + $this->assertEquals(1, $propertyValue['test-user@samples.mailgun.org']['id']); + } } ?>