Make sure $variables is an array in addRecipient() (#176)

* Write test to verify expected behaviour when we provide a String

* Fix broken test checking if the variable is an Array

* PSR Standard using single quote instead of double quote
This commit is contained in:
David Garcia 2016-09-30 15:03:35 +02:00 committed by Tobias Nyholm
parent 6513c12d8c
commit 3aeb602406
2 changed files with 15 additions and 1 deletions

View File

@ -97,7 +97,7 @@ class BatchMessage extends MessageBuilder
if (array_key_exists($headerName, $this->counters['recipients'])) {
$this->counters['recipients'][$headerName] += 1;
if (!array_key_exists('id', $variables)) {
if (is_array($variables) && !array_key_exists('id', $variables)) {
$variables['id'] = $this->counters['recipients'][$headerName];
}
}

View File

@ -41,6 +41,20 @@ class BatchMessageTest extends \Mailgun\Tests\MailgunTestCase
$this->assertEquals(1, $array['recipients']['to']);
}
public function testAddRecipientWithoutFirstAndLastName()
{
$message = $this->client->BatchMessage($this->sampleDomain);
$message->addToRecipient('test@samples.mailgun.org', 'this-is-not-an-array');
$messageObj = $message->getMessage();
$this->assertEquals(['to' => ['test@samples.mailgun.org']], $messageObj);
$reflectionClass = new \ReflectionClass(get_class($message));
$property = $reflectionClass->getProperty('counters');
$property->setAccessible(true);
$array = $property->getValue($message);
$this->assertEquals(1, $array['recipients']['to']);
}
public function testRecipientVariablesOnTo()
{
$message = $this->client->BatchMessage($this->sampleDomain);