Merge pull request #157 from Nyholm/issue-150

Make sure we use proper POST data arrays
This commit is contained in:
Tobias Nyholm 2016-08-10 18:58:18 +02:00 committed by GitHub
commit 54b7f851b8
3 changed files with 14 additions and 9 deletions

View File

@ -133,9 +133,10 @@ class RestClient
$postDataMultipart = []; $postDataMultipart = [];
foreach ($postData as $key => $value) { foreach ($postData as $key => $value) {
if (is_array($value)) { if (is_array($value)) {
$index = 0;
foreach ($value as $subValue) { foreach ($value as $subValue) {
$postDataMultipart[] = [ $postDataMultipart[] = [
'name' => $key, 'name' => sprintf('%s[%d]', $key, $index++),
'contents' => $subValue, 'contents' => $subValue,
]; ];
} }

View File

@ -10,18 +10,13 @@ class InlineFileTest extends \PHPUnit_Framework_TestCase
{ {
public function testSimpleExample() public function testSimpleExample()
{ {
// Create a Closure that validates the $files parameter to RestClient::send()
$fileValidator = function($files) { $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 = [ $fileNames = [
['name'=>'inline[0]', 'filename'=>'foo.png'], ['name'=>'inline[0]', 'filename'=>'foo.png'],
['name'=>'inline[1]', 'filename'=>'bar.png'] ['name'=>'inline[1]', 'filename'=>'bar.png']
]; ];
// Make sure that both files exists
foreach ($fileNames as $idx => $fileName) { foreach ($fileNames as $idx => $fileName) {
foreach ($files as $file) { foreach ($files as $file) {
if ($file['name'] === $fileName['name'] && $file['filename'] === $fileName['filename']) { if ($file['name'] === $fileName['name'] && $file['filename'] === $fileName['filename']) {

View File

@ -26,7 +26,16 @@ class NoSamePostNameTest extends \PHPUnit_Framework_TestCase
$builder = $mailgun->MessageBuilder(); $builder = $mailgun->MessageBuilder();
$builder->setFromAddress("bob@example.com"); $builder->setFromAddress("bob@example.com");
$builder->addToRecipient("alice@example.com"); $builder->addToRecipient("to1@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->setSubject("Foo");
$builder->setTextBody("Bar"); $builder->setTextBody("Bar");