diff --git a/composer.json b/composer.json index bc541bc..0c68194 100644 --- a/composer.json +++ b/composer.json @@ -14,10 +14,14 @@ }, "autoload": { "psr-0": { - "Mailgun\\Tests": "tests/", "Mailgun": "src/" } }, + "autoload-dev": { + "psr-4": { + "Mailgun\\Tests\\": "tests/" + } + }, "license": "MIT", "authors": [ { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 33cea16..8707107 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,5 @@ - - tests/Mailgun/Tests + tests diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php deleted file mode 100644 index 95f8179..0000000 --- a/tests/Bootstrap.php +++ /dev/null @@ -1,4 +0,0 @@ - + */ +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'] + ]; + foreach ($fileNames as $idx => $fileName) { + foreach ($files as $file) { + if ($file['name'] === $fileName['name'] && $file['filename'] === $fileName['filename']) { + unset ($fileNames[$idx]); + break; + } + } + } + + $this->assertEmpty($fileNames, 'Filenames could not be found'); + }; + + // Create the mocked mailgun client. We use $this->assertEquals on $method, $uri and $body parameters. + $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->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()); + } +} diff --git a/tests/Mailgun/Tests/Functional/MockedMailgun.php b/tests/Functional/MockedMailgun.php similarity index 100% rename from tests/Mailgun/Tests/Functional/MockedMailgun.php rename to tests/Functional/MockedMailgun.php diff --git a/tests/Mailgun/Tests/Functional/MockedRestClient.php b/tests/Functional/MockedRestClient.php similarity index 100% rename from tests/Mailgun/Tests/Functional/MockedRestClient.php rename to tests/Functional/MockedRestClient.php diff --git a/tests/Mailgun/Tests/Functional/SendMessageTest.php b/tests/Functional/SendMessageTest.php similarity index 99% rename from tests/Mailgun/Tests/Functional/SendMessageTest.php rename to tests/Functional/SendMessageTest.php index 193a2bf..4966920 100644 --- a/tests/Mailgun/Tests/Functional/SendMessageTest.php +++ b/tests/Functional/SendMessageTest.php @@ -27,5 +27,5 @@ class SendMessageTest extends \PHPUnit_Framework_TestCase 'to' => 'alice@example.com', 'subject' => 'Foo', 'text' => 'Bar')); - } + } } diff --git a/tests/Mailgun/Tests/Lists/OptInHandlerTest.php b/tests/Lists/OptInHandlerTest.php similarity index 100% rename from tests/Mailgun/Tests/Lists/OptInHandlerTest.php rename to tests/Lists/OptInHandlerTest.php diff --git a/tests/Mailgun/Tests/TestAssets/mailgun_icon.png b/tests/Mailgun/Tests/TestAssets/mailgun_icon.png deleted file mode 100644 index 604f673..0000000 Binary files a/tests/Mailgun/Tests/TestAssets/mailgun_icon.png and /dev/null differ diff --git a/tests/Mailgun/Tests/TestAssets/rackspace_logo.jpg b/tests/Mailgun/Tests/TestAssets/rackspace_logo.jpg deleted file mode 100644 index 46360a0..0000000 Binary files a/tests/Mailgun/Tests/TestAssets/rackspace_logo.jpg and /dev/null differ diff --git a/tests/Mailgun/Tests/MailgunTest.php b/tests/MailgunTest.php similarity index 97% rename from tests/Mailgun/Tests/MailgunTest.php rename to tests/MailgunTest.php index 204d2f5..5c7e305 100644 --- a/tests/Mailgun/Tests/MailgunTest.php +++ b/tests/MailgunTest.php @@ -1,6 +1,6 @@ [ [ 'remoteName'=> 'mailgun_icon1.png', - 'filePath' => 'tests/Mailgun/Tests/TestAssets/mailgun_icon1.png' + 'filePath' => 'tests/TestAssets/mailgun_icon1.png' ], [ 'remoteName'=> 'mailgun_icon2.png', - 'filePath' => 'tests/Mailgun/Tests/TestAssets/mailgun_icon2.png' + 'filePath' => 'tests/TestAssets/mailgun_icon2.png' ] ] ]; diff --git a/tests/Mailgun/Tests/Messages/MessageBuilderTest.php b/tests/Messages/MessageBuilderTest.php similarity index 100% rename from tests/Mailgun/Tests/Messages/MessageBuilderTest.php rename to tests/Messages/MessageBuilderTest.php diff --git a/tests/Mailgun/Tests/Messages/StandardMessageTest.php b/tests/Messages/StandardMessageTest.php similarity index 100% rename from tests/Mailgun/Tests/Messages/StandardMessageTest.php rename to tests/Messages/StandardMessageTest.php diff --git a/tests/Mailgun/Tests/Mock/Connection/TestBroker.php b/tests/Mock/Connection/TestBroker.php similarity index 100% rename from tests/Mailgun/Tests/Mock/Connection/TestBroker.php rename to tests/Mock/Connection/TestBroker.php diff --git a/tests/Mailgun/Tests/Mock/Mailgun.php b/tests/Mock/Mailgun.php similarity index 100% rename from tests/Mailgun/Tests/Mock/Mailgun.php rename to tests/Mock/Mailgun.php diff --git a/tests/Mailgun/Tests/TestAssets/mailgun_icon1.png b/tests/TestAssets/mailgun_icon1.png similarity index 100% rename from tests/Mailgun/Tests/TestAssets/mailgun_icon1.png rename to tests/TestAssets/mailgun_icon1.png diff --git a/tests/Mailgun/Tests/TestAssets/mailgun_icon2.png b/tests/TestAssets/mailgun_icon2.png similarity index 100% rename from tests/Mailgun/Tests/TestAssets/mailgun_icon2.png rename to tests/TestAssets/mailgun_icon2.png