mailgun-php/tests/Api/MessageTest.php
Tobias Nyholm d4ab1b0a87 Support mime messages (#341)
* Support mime messages

* cs

* Removed pointless integration tests

* typo

* Create new endpoint for message.mime

* cs

* Added docs

* Doc fixes

* Refactor
2017-04-14 10:31:13 +02:00

72 lines
2.1 KiB
PHP

<?php
/*
* Copyright (C) 2013-2016 Mailgun
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace Mailgun\Tests\Api;
use GuzzleHttp\Psr7\Response;
use Mailgun\Api\Message;
/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
class MessageTest extends TestCase
{
public function testSendMime()
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('httpPostRaw')
->with('/v3/foo/messages.mime',
$this->callback(function ($multipartBody) {
$parameters = ['o:Foo' => 'bar', 'to' => 'mailbox@myapp.com'];
// Verify all parameters
foreach ($parameters as $name => $content) {
$found = false;
foreach ($multipartBody as $body) {
if ($body['name'] === $name && $body['content'] === $content) {
$found = true;
}
}
if (!$found) {
return false;
}
}
$found = false;
foreach ($multipartBody as $body) {
if ($body['name'] === 'message') {
// Make sure message exists.
$found = true;
// Make sure content is what we expect
if (!is_resource($body['content'])) {
return false;
}
}
}
if (!$found) {
return false;
}
return true;
}))
->willReturn(new Response());
$api->sendMime('foo', ['mailbox@myapp.com'], 'mime message', ['o:Foo' => 'bar']);
}
/**
* {@inheritdoc}
*/
protected function getApiClass()
{
return Message::class;
}
}