Apply fixes from StyleCI and make sure we add MIT license properly (#163)

* Applied fixes from StyleCI

* Create LICENSE
This commit is contained in:
Tobias Nyholm 2016-09-18 09:56:14 +02:00 committed by GitHub
parent 5d04bc63a7
commit 8fe342f5b9
31 changed files with 317 additions and 94 deletions

17
LICENSE Normal file
View 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.

View File

@ -1,5 +1,12 @@
<?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;
class GenericHTTPError extends \Exception

View File

@ -1,5 +1,12 @@
<?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;
class InvalidCredentials extends \Exception

View File

@ -1,5 +1,12 @@
<?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;
class MissingEndpoint extends \Exception

View File

@ -1,5 +1,12 @@
<?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;
class MissingRequiredParameters extends \Exception

View File

@ -1,5 +1,12 @@
<?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;
class NoDomainsConfigured extends \Exception

View File

@ -1,5 +1,12 @@
<?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;
use Http\Client\HttpClient;
@ -254,11 +261,11 @@ class RestClient
*
* @param string $fieldName
* @param string|array $filePath
* @param integer $fileIndex
* @param int $fileIndex
*
* @return array
*/
protected function prepareFile($fieldName, $filePath, $fileIndex=0)
protected function prepareFile($fieldName, $filePath, $fileIndex = 0)
{
$filename = null;
$resource = null;
@ -285,7 +292,7 @@ class RestClient
}
// Add index for multiple file support
$fieldName .= '[' . $fileIndex . ']';
$fieldName .= '['.$fileIndex.']';
return [
'name' => $fieldName,

View File

@ -1,5 +1,12 @@
<?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;
class Api

View File

@ -1,5 +1,12 @@
<?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;
class ExceptionMessages

View File

@ -1,5 +1,12 @@
<?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;
/**

View File

@ -1,5 +1,12 @@
<?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;
use Http\Client\HttpClient;

View File

@ -1,5 +1,12 @@
<?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;
use Mailgun\Constants\Api;

View File

@ -1,5 +1,12 @@
<?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;
class InvalidParameter extends \Exception

View File

@ -1,5 +1,12 @@
<?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;
class InvalidParameterType extends \Exception

View File

@ -1,5 +1,12 @@
<?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;
class MissingRequiredMIMEParameters extends \Exception

View File

@ -1,5 +1,12 @@
<?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;
class TooManyParameters extends \Exception

View File

@ -1,5 +1,12 @@
<?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;
use Mailgun\Constants\Api;
@ -309,7 +316,6 @@ class MessageBuilder
];
return true;
}
/**

View File

@ -1,26 +1,32 @@
<?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;
/**
*
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
class InlineFileTest extends \PHPUnit_Framework_TestCase
{
public function testSimpleExample()
{
$fileValidator = function($files) {
$fileValidator = function ($files) {
$fileNames = [
['name'=>'inline[0]', 'filename'=>'foo.png'],
['name'=>'inline[1]', 'filename'=>'bar.png']
['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']) {
unset ($fileNames[$idx]);
unset($fileNames[$idx]);
break;
}
}
@ -33,14 +39,14 @@ class InlineFileTest extends \PHPUnit_Framework_TestCase
$mailgun = MockedMailgun::create($this, 'POST', 'domain/messages', [], $fileValidator);
$builder = $mailgun->MessageBuilder();
$builder->setFromAddress("bob@example.com");
$builder->addToRecipient("alice@example.com");
$builder->setSubject("Foo");
$builder->setTextBody("Bar");
$builder->setFromAddress('bob@example.com');
$builder->addToRecipient('alice@example.com');
$builder->setSubject('Foo');
$builder->setTextBody('Bar');
$builder->addInlineImage("@./tests/TestAssets/mailgun_icon1.png", 'foo.png');
$builder->addInlineImage("@./tests/TestAssets/mailgun_icon2.png", 'bar.png');
$builder->addInlineImage('@./tests/TestAssets/mailgun_icon1.png', 'foo.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());
}
}

View File

@ -1,5 +1,12 @@
<?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;
use Mailgun\Mailgun;

View File

@ -1,5 +1,12 @@
<?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;
use Mailgun\Connection\RestClient;

View File

@ -1,19 +1,25 @@
<?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;
/**
*
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
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()
{
$fileValidator = function($files) {
$fileValidator = function ($files) {
$usedNames = [];
foreach ($files as $file) {
$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);
$builder = $mailgun->MessageBuilder();
$builder->setFromAddress("bob@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->setFromAddress('bob@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->setTextBody("Bar");
$builder->setSubject('Foo');
$builder->setTextBody('Bar');
$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->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');
$mailgun->post("domain/messages", $builder->getMessage(), $builder->getFiles());
$mailgun->post('domain/messages', $builder->getMessage(), $builder->getFiles());
}
}

View File

@ -1,9 +1,16 @@
<?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;
/**
* 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>
*/
@ -12,20 +19,20 @@ class SendMessageTest extends \PHPUnit_Framework_TestCase
public function testSimpleExample()
{
// Create a Closure that validates the $files parameter to RestClient::send()
$fileValidator = function($files) {
$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);
$fileValidator = function ($files) {
$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);
};
// Create the mocked mailgun client. We use $this->assertEquals on $method, $uri and $body parameters.
$mailgun = MockedMailgun::create($this, 'POST', 'domain/messages', [], $fileValidator);
$mailgun->sendMessage('domain', array(
$mailgun->sendMessage('domain', [
'from' => 'bob@example.com',
'to' => 'alice@example.com',
'subject' => 'Foo',
'text' => 'Bar'));
'text' => 'Bar', ]);
}
}

View File

@ -1,5 +1,12 @@
<?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;
use Mailgun\Tests\Mock\Mailgun;

View File

@ -1,5 +1,12 @@
<?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;
use Mailgun\Mailgun;

View File

@ -1,5 +1,12 @@
<?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;
abstract class MailgunTestCase extends \PHPUnit_Framework_TestCase

View File

@ -1,5 +1,12 @@
<?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;
use Mailgun\Tests\Mock\Mailgun;

View File

@ -1,35 +1,43 @@
<?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;
use Mailgun\Tests\Mock\Mailgun;
use Mailgun\Connection\RestClient;
use Mailgun\Tests\Mock\Mailgun;
class mockRestClient extends RestClient
{
public function send($method, $uri, $body = null, $files = [], array $headers = [])
{
$result = new \stdClass();
class mockRestClient extends RestClient{
public function send($method, $uri, $body = null, $files = [], array $headers = [])
{
$result = new \stdClass;
$result->method = $method;
$result->uri = $uri;
$result->body = $body;
$result->files = $files;
$result->headers = $headers;
$result->method = $method;
$result->uri = $uri;
$result->body = $body;
$result->files = $files;
$result->headers = $headers;
return $result;
}
return $result;
}
}
class mockMailgun extends Mailgun{
public function __construct(
class mockMailgun extends Mailgun
{
public function __construct(
$apiKey = null,
HttpClient $httpClient = null,
$apiEndpoint = 'api.mailgun.net'
) {
$this->apiKey = $apiKey;
$this->restClient = new mockRestClient($apiKey, $apiEndpoint, $httpClient);
}
$this->apiKey = $apiKey;
$this->restClient = new mockRestClient($apiKey, $apiEndpoint, $httpClient);
}
}
class ComplexMessageTest extends \Mailgun\Tests\MailgunTestCase
@ -44,25 +52,24 @@ class ComplexMessageTest extends \Mailgun\Tests\MailgunTestCase
public function testSendComplexMessage()
{
$message = [
'to' => 'test@test.mailgun.org',
'to' => 'test@test.mailgun.org',
'from' => 'sender@test.mailgun.org',
'subject' => 'This is my test subject',
'text' => 'Testing!'
'text' => 'Testing!',
];
$files = [
'inline' => [
[
'remoteName'=> 'mailgun_icon1.png',
'filePath' => 'tests/TestAssets/mailgun_icon1.png'
'remoteName' => 'mailgun_icon1.png',
'filePath' => 'tests/TestAssets/mailgun_icon1.png',
],
[
'remoteName'=> 'mailgun_icon2.png',
'filePath' => 'tests/TestAssets/mailgun_icon2.png'
]
]
'remoteName' => 'mailgun_icon2.png',
'filePath' => 'tests/TestAssets/mailgun_icon2.png',
],
],
];
$result = $this->client->sendMessage('test.mailgun.org', $message, $files);
@ -74,31 +81,31 @@ class ComplexMessageTest extends \Mailgun\Tests\MailgunTestCase
// Start a counter, make sure all files are asserted
$testCount = 0;
foreach($result->files as $file){
if ($file['name'] == 'to'){
$this->assertEquals($file['contents'], 'test@test.mailgun.org');
$testCount++;
}
if ($file['name'] == 'from'){
$this->assertEquals($file['contents'], 'sender@test.mailgun.org');
$testCount++;
}
if ($file['name'] == 'subject'){
$this->assertEquals($file['contents'], 'This is my test subject');
$testCount++;
}
if ($file['name'] == 'text'){
$this->assertEquals($file['contents'], 'Testing!');
$testCount++;
}
if ($file['name'] == 'inline[0]'){
$this->assertEquals($file['filename'], 'mailgun_icon1.png');
$testCount++;
}
if ($file['name'] == 'inline[1]'){
$this->assertEquals($file['filename'], 'mailgun_icon2.png');
$testCount++;
}
foreach ($result->files as $file) {
if ($file['name'] == 'to') {
$this->assertEquals($file['contents'], 'test@test.mailgun.org');
$testCount++;
}
if ($file['name'] == 'from') {
$this->assertEquals($file['contents'], 'sender@test.mailgun.org');
$testCount++;
}
if ($file['name'] == 'subject') {
$this->assertEquals($file['contents'], 'This is my test subject');
$testCount++;
}
if ($file['name'] == 'text') {
$this->assertEquals($file['contents'], 'Testing!');
$testCount++;
}
if ($file['name'] == 'inline[0]') {
$this->assertEquals($file['filename'], 'mailgun_icon1.png');
$testCount++;
}
if ($file['name'] == 'inline[1]') {
$this->assertEquals($file['filename'], 'mailgun_icon2.png');
$testCount++;
}
}
// Make sure all "files" are asserted
@ -106,6 +113,5 @@ class ComplexMessageTest extends \Mailgun\Tests\MailgunTestCase
$this->assertEquals([], $result->body);
$this->assertEquals([], $result->headers);
}
}

View File

@ -1,5 +1,12 @@
<?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;
use Mailgun\Tests\Mock\Mailgun;

View File

@ -1,5 +1,12 @@
<?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;
use Mailgun\Tests\Mock\Mailgun;

View File

@ -1,5 +1,12 @@
<?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;
use Mailgun\Connection\Exceptions\GenericHTTPError;

View File

@ -1,5 +1,12 @@
<?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;
use Mailgun\Mailgun as Base;