mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-24 05:26:02 +03:00
Apply fixes from StyleCI and make sure we add MIT license properly (#163)
* Applied fixes from StyleCI * Create LICENSE
This commit is contained in:
parent
5d04bc63a7
commit
8fe342f5b9
17
LICENSE
Normal file
17
LICENSE
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Connection\Exceptions;
|
namespace Mailgun\Connection\Exceptions;
|
||||||
|
|
||||||
class GenericHTTPError extends \Exception
|
class GenericHTTPError extends \Exception
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Connection\Exceptions;
|
namespace Mailgun\Connection\Exceptions;
|
||||||
|
|
||||||
class InvalidCredentials extends \Exception
|
class InvalidCredentials extends \Exception
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Connection\Exceptions;
|
namespace Mailgun\Connection\Exceptions;
|
||||||
|
|
||||||
class MissingEndpoint extends \Exception
|
class MissingEndpoint extends \Exception
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Connection\Exceptions;
|
namespace Mailgun\Connection\Exceptions;
|
||||||
|
|
||||||
class MissingRequiredParameters extends \Exception
|
class MissingRequiredParameters extends \Exception
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Connection\Exceptions;
|
namespace Mailgun\Connection\Exceptions;
|
||||||
|
|
||||||
class NoDomainsConfigured extends \Exception
|
class NoDomainsConfigured extends \Exception
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
<?PHP
|
<?PHP
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Connection;
|
namespace Mailgun\Connection;
|
||||||
|
|
||||||
use Http\Client\HttpClient;
|
use Http\Client\HttpClient;
|
||||||
@ -254,11 +261,11 @@ class RestClient
|
|||||||
*
|
*
|
||||||
* @param string $fieldName
|
* @param string $fieldName
|
||||||
* @param string|array $filePath
|
* @param string|array $filePath
|
||||||
* @param integer $fileIndex
|
* @param int $fileIndex
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function prepareFile($fieldName, $filePath, $fileIndex=0)
|
protected function prepareFile($fieldName, $filePath, $fileIndex = 0)
|
||||||
{
|
{
|
||||||
$filename = null;
|
$filename = null;
|
||||||
$resource = null;
|
$resource = null;
|
||||||
@ -285,7 +292,7 @@ class RestClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add index for multiple file support
|
// Add index for multiple file support
|
||||||
$fieldName .= '[' . $fileIndex . ']';
|
$fieldName .= '['.$fileIndex.']';
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'name' => $fieldName,
|
'name' => $fieldName,
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Constants;
|
namespace Mailgun\Constants;
|
||||||
|
|
||||||
class Api
|
class Api
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Constants;
|
namespace Mailgun\Constants;
|
||||||
|
|
||||||
class ExceptionMessages
|
class ExceptionMessages
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
<?PHP
|
<?PHP
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Lists;
|
namespace Mailgun\Lists;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
<?PHP
|
<?PHP
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun;
|
namespace Mailgun;
|
||||||
|
|
||||||
use Http\Client\HttpClient;
|
use Http\Client\HttpClient;
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
<?PHP
|
<?PHP
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Messages;
|
namespace Mailgun\Messages;
|
||||||
|
|
||||||
use Mailgun\Constants\Api;
|
use Mailgun\Constants\Api;
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Messages\Exceptions;
|
namespace Mailgun\Messages\Exceptions;
|
||||||
|
|
||||||
class InvalidParameter extends \Exception
|
class InvalidParameter extends \Exception
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Messages\Exceptions;
|
namespace Mailgun\Messages\Exceptions;
|
||||||
|
|
||||||
class InvalidParameterType extends \Exception
|
class InvalidParameterType extends \Exception
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Messages\Exceptions;
|
namespace Mailgun\Messages\Exceptions;
|
||||||
|
|
||||||
class MissingRequiredMIMEParameters extends \Exception
|
class MissingRequiredMIMEParameters extends \Exception
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Messages\Exceptions;
|
namespace Mailgun\Messages\Exceptions;
|
||||||
|
|
||||||
class TooManyParameters extends \Exception
|
class TooManyParameters extends \Exception
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
<?PHP
|
<?PHP
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Messages;
|
namespace Mailgun\Messages;
|
||||||
|
|
||||||
use Mailgun\Constants\Api;
|
use Mailgun\Constants\Api;
|
||||||
@ -309,7 +316,6 @@ class MessageBuilder
|
|||||||
];
|
];
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,26 +1,32 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Tests\Functional;
|
namespace Mailgun\Tests\Functional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
||||||
*/
|
*/
|
||||||
class InlineFileTest extends \PHPUnit_Framework_TestCase
|
class InlineFileTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testSimpleExample()
|
public function testSimpleExample()
|
||||||
{
|
{
|
||||||
$fileValidator = function($files) {
|
$fileValidator = function ($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
|
// 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']) {
|
||||||
unset ($fileNames[$idx]);
|
unset($fileNames[$idx]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -33,14 +39,14 @@ class InlineFileTest extends \PHPUnit_Framework_TestCase
|
|||||||
$mailgun = MockedMailgun::create($this, 'POST', 'domain/messages', [], $fileValidator);
|
$mailgun = MockedMailgun::create($this, 'POST', 'domain/messages', [], $fileValidator);
|
||||||
|
|
||||||
$builder = $mailgun->MessageBuilder();
|
$builder = $mailgun->MessageBuilder();
|
||||||
$builder->setFromAddress("bob@example.com");
|
$builder->setFromAddress('bob@example.com');
|
||||||
$builder->addToRecipient("alice@example.com");
|
$builder->addToRecipient('alice@example.com');
|
||||||
$builder->setSubject("Foo");
|
$builder->setSubject('Foo');
|
||||||
$builder->setTextBody("Bar");
|
$builder->setTextBody('Bar');
|
||||||
|
|
||||||
$builder->addInlineImage("@./tests/TestAssets/mailgun_icon1.png", 'foo.png');
|
$builder->addInlineImage('@./tests/TestAssets/mailgun_icon1.png', 'foo.png');
|
||||||
$builder->addInlineImage("@./tests/TestAssets/mailgun_icon2.png", 'bar.png');
|
$builder->addInlineImage('@./tests/TestAssets/mailgun_icon2.png', 'bar.png');
|
||||||
|
|
||||||
$mailgun->post("domain/messages", $builder->getMessage(), $builder->getFiles());
|
$mailgun->post('domain/messages', $builder->getMessage(), $builder->getFiles());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Tests\Functional;
|
namespace Mailgun\Tests\Functional;
|
||||||
|
|
||||||
use Mailgun\Mailgun;
|
use Mailgun\Mailgun;
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Tests\Functional;
|
namespace Mailgun\Tests\Functional;
|
||||||
|
|
||||||
use Mailgun\Connection\RestClient;
|
use Mailgun\Connection\RestClient;
|
||||||
|
@ -1,19 +1,25 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Tests\Functional;
|
namespace Mailgun\Tests\Functional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
||||||
*/
|
*/
|
||||||
class NoSamePostNameTest extends \PHPUnit_Framework_TestCase
|
class NoSamePostNameTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* No post names should ever be the same
|
* No post names should ever be the same.
|
||||||
*/
|
*/
|
||||||
public function testNames()
|
public function testNames()
|
||||||
{
|
{
|
||||||
$fileValidator = function($files) {
|
$fileValidator = function ($files) {
|
||||||
$usedNames = [];
|
$usedNames = [];
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
$this->assertFalse(in_array($file['name'], $usedNames), 'No files should have the same POST name.');
|
$this->assertFalse(in_array($file['name'], $usedNames), 'No files should have the same POST name.');
|
||||||
@ -25,25 +31,25 @@ class NoSamePostNameTest extends \PHPUnit_Framework_TestCase
|
|||||||
$mailgun = MockedMailgun::create($this, 'POST', 'domain/messages', [], $fileValidator);
|
$mailgun = MockedMailgun::create($this, 'POST', 'domain/messages', [], $fileValidator);
|
||||||
|
|
||||||
$builder = $mailgun->MessageBuilder();
|
$builder = $mailgun->MessageBuilder();
|
||||||
$builder->setFromAddress("bob@example.com");
|
$builder->setFromAddress('bob@example.com');
|
||||||
$builder->addToRecipient("to1@example.com");
|
$builder->addToRecipient('to1@example.com');
|
||||||
$builder->addToRecipient("to2@example.com");
|
$builder->addToRecipient('to2@example.com');
|
||||||
$builder->addCcRecipient("cc1@example.com");
|
$builder->addCcRecipient('cc1@example.com');
|
||||||
$builder->addCcRecipient("cc2@example.com");
|
$builder->addCcRecipient('cc2@example.com');
|
||||||
$builder->addBccRecipient("bcc1@example.com");
|
$builder->addBccRecipient('bcc1@example.com');
|
||||||
$builder->addBccRecipient("bcc2@example.com");
|
$builder->addBccRecipient('bcc2@example.com');
|
||||||
$builder->addCustomParameter('foo', 'bar');
|
$builder->addCustomParameter('foo', 'bar');
|
||||||
$builder->addCustomParameter('foo', 'baz');
|
$builder->addCustomParameter('foo', 'baz');
|
||||||
$builder->addCampaignId('campaign0');
|
$builder->addCampaignId('campaign0');
|
||||||
$builder->addCampaignId('campaign1');
|
$builder->addCampaignId('campaign1');
|
||||||
$builder->setSubject("Foo");
|
$builder->setSubject('Foo');
|
||||||
$builder->setTextBody("Bar");
|
$builder->setTextBody('Bar');
|
||||||
|
|
||||||
$builder->addAttachment("@./tests/TestAssets/mailgun_icon1.png", 'foo.png');
|
$builder->addAttachment('@./tests/TestAssets/mailgun_icon1.png', 'foo.png');
|
||||||
$builder->addAttachment("@./tests/TestAssets/mailgun_icon1.png", 'foo.png');
|
$builder->addAttachment('@./tests/TestAssets/mailgun_icon1.png', 'foo.png');
|
||||||
$builder->addInlineImage("@./tests/TestAssets/mailgun_icon2.png", 'bar.png');
|
$builder->addInlineImage('@./tests/TestAssets/mailgun_icon2.png', 'bar.png');
|
||||||
$builder->addInlineImage("@./tests/TestAssets/mailgun_icon2.png", 'bar.png');
|
$builder->addInlineImage('@./tests/TestAssets/mailgun_icon2.png', 'bar.png');
|
||||||
|
|
||||||
$mailgun->post("domain/messages", $builder->getMessage(), $builder->getFiles());
|
$mailgun->post('domain/messages', $builder->getMessage(), $builder->getFiles());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Tests\Functional;
|
namespace Mailgun\Tests\Functional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple test to show how to use the MockedMailgun client
|
* Simple test to show how to use the MockedMailgun client.
|
||||||
*
|
*
|
||||||
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
||||||
*/
|
*/
|
||||||
@ -12,20 +19,20 @@ class SendMessageTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testSimpleExample()
|
public function testSimpleExample()
|
||||||
{
|
{
|
||||||
// Create a Closure that validates the $files parameter to RestClient::send()
|
// Create a Closure that validates the $files parameter to RestClient::send()
|
||||||
$fileValidator = function($files) {
|
$fileValidator = function ($files) {
|
||||||
$this->assertContains(['name'=>'from', 'contents'=>'bob@example.com'], $files);
|
$this->assertContains(['name' => 'from', 'contents' => 'bob@example.com'], $files);
|
||||||
$this->assertContains(['name'=>'to', 'contents'=>'alice@example.com'], $files);
|
$this->assertContains(['name' => 'to', 'contents' => 'alice@example.com'], $files);
|
||||||
$this->assertContains(['name'=>'subject', 'contents'=>'Foo'], $files);
|
$this->assertContains(['name' => 'subject', 'contents' => 'Foo'], $files);
|
||||||
$this->assertContains(['name'=>'text', 'contents'=>'Bar'], $files);
|
$this->assertContains(['name' => 'text', 'contents' => 'Bar'], $files);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create the mocked mailgun client. We use $this->assertEquals on $method, $uri and $body parameters.
|
// Create the mocked mailgun client. We use $this->assertEquals on $method, $uri and $body parameters.
|
||||||
$mailgun = MockedMailgun::create($this, 'POST', 'domain/messages', [], $fileValidator);
|
$mailgun = MockedMailgun::create($this, 'POST', 'domain/messages', [], $fileValidator);
|
||||||
|
|
||||||
$mailgun->sendMessage('domain', array(
|
$mailgun->sendMessage('domain', [
|
||||||
'from' => 'bob@example.com',
|
'from' => 'bob@example.com',
|
||||||
'to' => 'alice@example.com',
|
'to' => 'alice@example.com',
|
||||||
'subject' => 'Foo',
|
'subject' => 'Foo',
|
||||||
'text' => 'Bar'));
|
'text' => 'Bar', ]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
<?PHP
|
<?PHP
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Tests\Lists;
|
namespace Mailgun\Tests\Lists;
|
||||||
|
|
||||||
use Mailgun\Tests\Mock\Mailgun;
|
use Mailgun\Tests\Mock\Mailgun;
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
<?PHP
|
<?PHP
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Tests;
|
namespace Mailgun\Tests;
|
||||||
|
|
||||||
use Mailgun\Mailgun;
|
use Mailgun\Mailgun;
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
<?PHP
|
<?PHP
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Tests;
|
namespace Mailgun\Tests;
|
||||||
|
|
||||||
abstract class MailgunTestCase extends \PHPUnit_Framework_TestCase
|
abstract class MailgunTestCase extends \PHPUnit_Framework_TestCase
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
<?PHP
|
<?PHP
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Tests\Messages;
|
namespace Mailgun\Tests\Messages;
|
||||||
|
|
||||||
use Mailgun\Tests\Mock\Mailgun;
|
use Mailgun\Tests\Mock\Mailgun;
|
||||||
|
@ -1,15 +1,22 @@
|
|||||||
<?PHP
|
<?PHP
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Tests\Messages;
|
namespace Mailgun\Tests\Messages;
|
||||||
|
|
||||||
use Mailgun\Tests\Mock\Mailgun;
|
|
||||||
use Mailgun\Connection\RestClient;
|
use Mailgun\Connection\RestClient;
|
||||||
|
use Mailgun\Tests\Mock\Mailgun;
|
||||||
|
|
||||||
|
class mockRestClient extends RestClient
|
||||||
class mockRestClient extends RestClient{
|
{
|
||||||
public function send($method, $uri, $body = null, $files = [], array $headers = [])
|
public function send($method, $uri, $body = null, $files = [], array $headers = [])
|
||||||
{
|
{
|
||||||
$result = new \stdClass;
|
$result = new \stdClass();
|
||||||
|
|
||||||
$result->method = $method;
|
$result->method = $method;
|
||||||
$result->uri = $uri;
|
$result->uri = $uri;
|
||||||
@ -21,7 +28,8 @@ class mockRestClient extends RestClient{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class mockMailgun extends Mailgun{
|
class mockMailgun extends Mailgun
|
||||||
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
$apiKey = null,
|
$apiKey = null,
|
||||||
HttpClient $httpClient = null,
|
HttpClient $httpClient = null,
|
||||||
@ -44,25 +52,24 @@ class ComplexMessageTest extends \Mailgun\Tests\MailgunTestCase
|
|||||||
|
|
||||||
public function testSendComplexMessage()
|
public function testSendComplexMessage()
|
||||||
{
|
{
|
||||||
|
|
||||||
$message = [
|
$message = [
|
||||||
'to' => 'test@test.mailgun.org',
|
'to' => 'test@test.mailgun.org',
|
||||||
'from' => 'sender@test.mailgun.org',
|
'from' => 'sender@test.mailgun.org',
|
||||||
'subject' => 'This is my test subject',
|
'subject' => 'This is my test subject',
|
||||||
'text' => 'Testing!'
|
'text' => 'Testing!',
|
||||||
];
|
];
|
||||||
|
|
||||||
$files = [
|
$files = [
|
||||||
'inline' => [
|
'inline' => [
|
||||||
[
|
[
|
||||||
'remoteName'=> 'mailgun_icon1.png',
|
'remoteName' => 'mailgun_icon1.png',
|
||||||
'filePath' => 'tests/TestAssets/mailgun_icon1.png'
|
'filePath' => 'tests/TestAssets/mailgun_icon1.png',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'remoteName'=> 'mailgun_icon2.png',
|
'remoteName' => 'mailgun_icon2.png',
|
||||||
'filePath' => 'tests/TestAssets/mailgun_icon2.png'
|
'filePath' => 'tests/TestAssets/mailgun_icon2.png',
|
||||||
]
|
],
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$result = $this->client->sendMessage('test.mailgun.org', $message, $files);
|
$result = $this->client->sendMessage('test.mailgun.org', $message, $files);
|
||||||
@ -74,28 +81,28 @@ class ComplexMessageTest extends \Mailgun\Tests\MailgunTestCase
|
|||||||
// Start a counter, make sure all files are asserted
|
// Start a counter, make sure all files are asserted
|
||||||
$testCount = 0;
|
$testCount = 0;
|
||||||
|
|
||||||
foreach($result->files as $file){
|
foreach ($result->files as $file) {
|
||||||
if ($file['name'] == 'to'){
|
if ($file['name'] == 'to') {
|
||||||
$this->assertEquals($file['contents'], 'test@test.mailgun.org');
|
$this->assertEquals($file['contents'], 'test@test.mailgun.org');
|
||||||
$testCount++;
|
$testCount++;
|
||||||
}
|
}
|
||||||
if ($file['name'] == 'from'){
|
if ($file['name'] == 'from') {
|
||||||
$this->assertEquals($file['contents'], 'sender@test.mailgun.org');
|
$this->assertEquals($file['contents'], 'sender@test.mailgun.org');
|
||||||
$testCount++;
|
$testCount++;
|
||||||
}
|
}
|
||||||
if ($file['name'] == 'subject'){
|
if ($file['name'] == 'subject') {
|
||||||
$this->assertEquals($file['contents'], 'This is my test subject');
|
$this->assertEquals($file['contents'], 'This is my test subject');
|
||||||
$testCount++;
|
$testCount++;
|
||||||
}
|
}
|
||||||
if ($file['name'] == 'text'){
|
if ($file['name'] == 'text') {
|
||||||
$this->assertEquals($file['contents'], 'Testing!');
|
$this->assertEquals($file['contents'], 'Testing!');
|
||||||
$testCount++;
|
$testCount++;
|
||||||
}
|
}
|
||||||
if ($file['name'] == 'inline[0]'){
|
if ($file['name'] == 'inline[0]') {
|
||||||
$this->assertEquals($file['filename'], 'mailgun_icon1.png');
|
$this->assertEquals($file['filename'], 'mailgun_icon1.png');
|
||||||
$testCount++;
|
$testCount++;
|
||||||
}
|
}
|
||||||
if ($file['name'] == 'inline[1]'){
|
if ($file['name'] == 'inline[1]') {
|
||||||
$this->assertEquals($file['filename'], 'mailgun_icon2.png');
|
$this->assertEquals($file['filename'], 'mailgun_icon2.png');
|
||||||
$testCount++;
|
$testCount++;
|
||||||
}
|
}
|
||||||
@ -106,6 +113,5 @@ class ComplexMessageTest extends \Mailgun\Tests\MailgunTestCase
|
|||||||
|
|
||||||
$this->assertEquals([], $result->body);
|
$this->assertEquals([], $result->body);
|
||||||
$this->assertEquals([], $result->headers);
|
$this->assertEquals([], $result->headers);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
<?PHP
|
<?PHP
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Tests\Messages;
|
namespace Mailgun\Tests\Messages;
|
||||||
|
|
||||||
use Mailgun\Tests\Mock\Mailgun;
|
use Mailgun\Tests\Mock\Mailgun;
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
<?PHP
|
<?PHP
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Tests\Messages;
|
namespace Mailgun\Tests\Messages;
|
||||||
|
|
||||||
use Mailgun\Tests\Mock\Mailgun;
|
use Mailgun\Tests\Mock\Mailgun;
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Tests\Mock\Connection;
|
namespace Mailgun\Tests\Mock\Connection;
|
||||||
|
|
||||||
use Mailgun\Connection\Exceptions\GenericHTTPError;
|
use Mailgun\Connection\Exceptions\GenericHTTPError;
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
<?PHP
|
<?PHP
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Mailgun\Tests\Mock;
|
namespace Mailgun\Tests\Mock;
|
||||||
|
|
||||||
use Mailgun\Mailgun as Base;
|
use Mailgun\Mailgun as Base;
|
||||||
|
Loading…
Reference in New Issue
Block a user