From 741aa0d12079745d56fb70c8707773421725b29a Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Wed, 10 Aug 2016 17:26:24 +0200 Subject: [PATCH 1/3] Make sure we use proper POST data arrays --- src/Mailgun/Connection/RestClient.php | 3 ++- tests/Functional/NoSamePostNameTest.php | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Mailgun/Connection/RestClient.php b/src/Mailgun/Connection/RestClient.php index af1dfe3..849b981 100644 --- a/src/Mailgun/Connection/RestClient.php +++ b/src/Mailgun/Connection/RestClient.php @@ -133,9 +133,10 @@ class RestClient $postDataMultipart = []; foreach ($postData as $key => $value) { if (is_array($value)) { + $index = 0; foreach ($value as $subValue) { $postDataMultipart[] = [ - 'name' => $key, + 'name' => sprintf('%s[%d]', $key, $index++), 'contents' => $subValue, ]; } diff --git a/tests/Functional/NoSamePostNameTest.php b/tests/Functional/NoSamePostNameTest.php index 0f346ff..cf16a8b 100644 --- a/tests/Functional/NoSamePostNameTest.php +++ b/tests/Functional/NoSamePostNameTest.php @@ -26,7 +26,10 @@ class NoSamePostNameTest extends \PHPUnit_Framework_TestCase $builder = $mailgun->MessageBuilder(); $builder->setFromAddress("bob@example.com"); - $builder->addToRecipient("alice@example.com"); + $builder->addToRecipient("to1@example.com"); + $builder->addToRecipient("tp2@example.com"); + $builder->addBccRecipient("bcc1@example.com"); + $builder->addBccRecipient("bcc2@example.com"); $builder->setSubject("Foo"); $builder->setTextBody("Bar"); From 7119f18c264b37bac082bf249c2c9ac781cf5509 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Wed, 10 Aug 2016 17:32:10 +0200 Subject: [PATCH 2/3] Do not test same thing twice --- tests/Functional/InlineFileTest.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tests/Functional/InlineFileTest.php b/tests/Functional/InlineFileTest.php index 0942f27..91c9003 100644 --- a/tests/Functional/InlineFileTest.php +++ b/tests/Functional/InlineFileTest.php @@ -10,18 +10,13 @@ class InlineFileTest extends \PHPUnit_Framework_TestCase { public function testSimpleExample() { - // Create a Closure that validates the $files parameter to RestClient::send() $fileValidator = function($files) { - // Validate standard params - $this->assertContains(['name'=>'from', 'contents'=>'bob@example.com'], $files); - $this->assertContains(['name'=>'to', 'contents'=>'alice@example.com'], $files); - $this->assertContains(['name'=>'subject', 'contents'=>'Foo'], $files); - $this->assertContains(['name'=>'text', 'contents'=>'Bar'], $files); - $fileNames = [ ['name'=>'inline[0]', 'filename'=>'foo.png'], ['name'=>'inline[1]', 'filename'=>'bar.png'] ]; + + // Make sure that both files exists foreach ($fileNames as $idx => $fileName) { foreach ($files as $file) { if ($file['name'] === $fileName['name'] && $file['filename'] === $fileName['filename']) { From bf8d9627391dc1e3dc1edfc710bc4c0b31f88627 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Wed, 10 Aug 2016 18:28:19 +0200 Subject: [PATCH 3/3] Added more test cases --- tests/Functional/NoSamePostNameTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/Functional/NoSamePostNameTest.php b/tests/Functional/NoSamePostNameTest.php index cf16a8b..2e6678c 100644 --- a/tests/Functional/NoSamePostNameTest.php +++ b/tests/Functional/NoSamePostNameTest.php @@ -27,9 +27,15 @@ class NoSamePostNameTest extends \PHPUnit_Framework_TestCase $builder = $mailgun->MessageBuilder(); $builder->setFromAddress("bob@example.com"); $builder->addToRecipient("to1@example.com"); - $builder->addToRecipient("tp2@example.com"); + $builder->addToRecipient("to2@example.com"); + $builder->addCcRecipient("cc1@example.com"); + $builder->addCcRecipient("cc2@example.com"); $builder->addBccRecipient("bcc1@example.com"); $builder->addBccRecipient("bcc2@example.com"); + $builder->addCustomParameter('foo', 'bar'); + $builder->addCustomParameter('foo', 'baz'); + $builder->addCampaignId('campaign0'); + $builder->addCampaignId('campaign1'); $builder->setSubject("Foo"); $builder->setTextBody("Bar");