Added test for Message API

This commit is contained in:
Nyholm 2018-08-05 11:33:47 +02:00 committed by David Garcia
parent 15bd5ae156
commit d6e48c6bc2
2 changed files with 54 additions and 0 deletions

View File

@ -11,12 +11,40 @@ namespace Mailgun\Tests\Api;
use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\Response;
use Mailgun\Api\Message; use Mailgun\Api\Message;
use Mailgun\Model\Message\SendResponse;
use Mailgun\Model\Message\ShowResponse;
/** /**
* @author Tobias Nyholm <tobias.nyholm@gmail.com> * @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/ */
class MessageTest extends TestCase class MessageTest extends TestCase
{ {
public function testSend()
{
$this->setRequestMethod('POST');
$this->setRequestUri('/v3/example.com/messages');
$this->setHydrateClass(SendResponse::class);
$this->setRequestBody([
'from' => 'bob@example.com',
'to' => 'sally@example.com',
'subject' => 'Test file path attachments',
'text' => 'Test',
'attachment' => 'resource',
]);
$api = $this->getApiInstance();
$api->send('example.com', [
'from' => 'bob@example.com',
'to' => 'sally@example.com',
'subject' => 'Test file path attachments',
'text' => 'Test',
'attachment' => [
['filePath'=>__DIR__.'/../TestAssets/mailgun_icon1.png', 'filename'=>'mailgun_icon1.png'],
]
]);
}
public function testSendMime() public function testSendMime()
{ {
$api = $this->getApiMock(); $api = $this->getApiMock();
@ -61,6 +89,29 @@ class MessageTest extends TestCase
$api->sendMime('foo', ['mailbox@myapp.com'], 'mime message', ['o:Foo' => 'bar']); $api->sendMime('foo', ['mailbox@myapp.com'], 'mime message', ['o:Foo' => 'bar']);
} }
public function testShow()
{
$this->setRequestMethod('GET');
$this->setRequestUri('url');
$this->setHydrateClass(ShowResponse::class);
$api = $this->getApiInstance();
$api->show('url');
}
public function testShowRaw()
{
$this->setRequestMethod('GET');
$this->setRequestUri('url');
$this->setRequestHeaders([
'Accept' => 'message/rfc2822'
]);
$this->setHydrateClass(ShowResponse::class);
$api = $this->getApiInstance();
$api->show('url', true);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View File

@ -177,6 +177,9 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
// Check every item in body. // Check every item in body.
foreach ($body as $item) { foreach ($body as $item) {
if ($this->requestBody[$item['name']] === 'resource' && is_resource($item['content'])) {
continue;
}
if ($this->requestBody[$item['name']] !== $item['content']) { if ($this->requestBody[$item['name']] !== $item['content']) {
return false; return false;
} }