Added tests and use PSR4

This commit is contained in:
Tobias Nyholm 2016-08-10 17:06:27 +02:00
parent 0a7c96c34a
commit cd001cf5b3
20 changed files with 62 additions and 11 deletions

View File

@ -14,10 +14,14 @@
}, },
"autoload": { "autoload": {
"psr-0": { "psr-0": {
"Mailgun\\Tests": "tests/",
"Mailgun": "src/" "Mailgun": "src/"
} }
}, },
"autoload-dev": {
"psr-4": {
"Mailgun\\Tests\\": "tests/"
}
},
"license": "MIT", "license": "MIT",
"authors": [ "authors": [
{ {

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="tests/Bootstrap.php" <phpunit bootstrap="vendor/autoload.php"
colors="true" colors="true"
processIsolation="false" processIsolation="false"
stopOnFailure="false" stopOnFailure="false"
@ -11,7 +11,7 @@
<testsuites> <testsuites>
<testsuite> <testsuite>
<directory>tests/Mailgun/Tests</directory> <directory>tests</directory>
</testsuite> </testsuite>
</testsuites> </testsuites>

View File

@ -1,4 +0,0 @@
<?php
//Grab the composer Autoloader!
$autoloader = include dirname(__DIR__).'/vendor/autoload.php';

View File

@ -0,0 +1,51 @@
<?php
namespace Mailgun\Tests\Functional;
/**
*
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
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());
}
}

View File

@ -27,5 +27,5 @@ class SendMessageTest extends \PHPUnit_Framework_TestCase
'to' => 'alice@example.com', 'to' => 'alice@example.com',
'subject' => 'Foo', 'subject' => 'Foo',
'text' => 'Bar')); 'text' => 'Bar'));
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

View File

@ -1,6 +1,6 @@
<?PHP <?PHP
namespace Mailgun\Tests\Lists; namespace Mailgun\Tests;
use Mailgun\Mailgun; use Mailgun\Mailgun;

View File

@ -56,11 +56,11 @@ class ComplexMessageTest extends \Mailgun\Tests\MailgunTestCase
'inline' => [ 'inline' => [
[ [
'remoteName'=> 'mailgun_icon1.png', 'remoteName'=> 'mailgun_icon1.png',
'filePath' => 'tests/Mailgun/Tests/TestAssets/mailgun_icon1.png' 'filePath' => 'tests/TestAssets/mailgun_icon1.png'
], ],
[ [
'remoteName'=> 'mailgun_icon2.png', 'remoteName'=> 'mailgun_icon2.png',
'filePath' => 'tests/Mailgun/Tests/TestAssets/mailgun_icon2.png' 'filePath' => 'tests/TestAssets/mailgun_icon2.png'
] ]
] ]
]; ];

View File

Before

Width:  |  Height:  |  Size: 85 KiB

After

Width:  |  Height:  |  Size: 85 KiB

View File

Before

Width:  |  Height:  |  Size: 85 KiB

After

Width:  |  Height:  |  Size: 85 KiB