mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2025-02-06 08:19:25 +03:00
Added test for Message API
This commit is contained in:
parent
15bd5ae156
commit
d6e48c6bc2
@ -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}
|
||||||
*/
|
*/
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user