mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-22 12:36:02 +03:00
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:
parent
6513c12d8c
commit
3aeb602406
@ -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];
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user