mailgun-php/tests/Functional/SendMessageTest.php

39 lines
1.3 KiB
PHP
Raw Normal View History

2016-08-05 11:40:49 +03:00
<?php
/*
* Copyright (C) 2013 Mailgun
*
* This software may be modified and distributed under the terms
2016-12-06 21:12:52 +03:00
* of the MIT license. See the LICENSE file for details.
*/
2016-08-05 11:40:49 +03:00
namespace Mailgun\Tests\Functional;
/**
* Simple test to show how to use the MockedMailgun client.
2016-08-05 11:40:49 +03:00
*
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
class SendMessageTest extends \PHPUnit_Framework_TestCase
{
public function testSimpleExample()
{
// Create a Closure that validates the $files parameter to RestClient::send()
$fileValidator = function ($files) {
$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);
2016-08-05 11:40:49 +03:00
};
// Create the mocked mailgun client. We use $this->assertEquals on $method, $uri and $body parameters.
$mailgun = MockedMailgun::createMock($this, 'POST', 'domain/messages', [], $fileValidator);
2016-08-05 11:40:49 +03:00
$mailgun->sendMessage('domain', [
'from' => 'bob@example.com',
'to' => 'alice@example.com',
2016-08-05 11:40:49 +03:00
'subject' => 'Foo',
'text' => 'Bar', ]);
2016-08-10 18:06:27 +03:00
}
2016-08-05 11:40:49 +03:00
}