diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..89de354 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/src/Mailgun/Connection/Exceptions/GenericHTTPError.php b/src/Mailgun/Connection/Exceptions/GenericHTTPError.php index 20ebd96..870aedc 100644 --- a/src/Mailgun/Connection/Exceptions/GenericHTTPError.php +++ b/src/Mailgun/Connection/Exceptions/GenericHTTPError.php @@ -1,5 +1,12 @@ $fieldName, diff --git a/src/Mailgun/Constants/Api.php b/src/Mailgun/Constants/Api.php index a3ffdfb..afcfe02 100644 --- a/src/Mailgun/Constants/Api.php +++ b/src/Mailgun/Constants/Api.php @@ -1,5 +1,12 @@ */ 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()); } } diff --git a/tests/Functional/MockedMailgun.php b/tests/Functional/MockedMailgun.php index 1310218..67e29a8 100644 --- a/tests/Functional/MockedMailgun.php +++ b/tests/Functional/MockedMailgun.php @@ -1,5 +1,12 @@ */ 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()); } } diff --git a/tests/Functional/SendMessageTest.php b/tests/Functional/SendMessageTest.php index 4966920..b50354b 100644 --- a/tests/Functional/SendMessageTest.php +++ b/tests/Functional/SendMessageTest.php @@ -1,9 +1,16 @@ */ @@ -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', ]); } } diff --git a/tests/Lists/OptInHandlerTest.php b/tests/Lists/OptInHandlerTest.php index 9abd973..f15fdc9 100644 --- a/tests/Lists/OptInHandlerTest.php +++ b/tests/Lists/OptInHandlerTest.php @@ -1,5 +1,12 @@ 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); - } } diff --git a/tests/Messages/MessageBuilderTest.php b/tests/Messages/MessageBuilderTest.php index d32bf78..5e39cad 100644 --- a/tests/Messages/MessageBuilderTest.php +++ b/tests/Messages/MessageBuilderTest.php @@ -1,5 +1,12 @@