"Refactor Complete!"

This commit is contained in:
Travis Swientek 2013-07-24 16:25:24 -07:00
parent 0c70ab5a22
commit f54649ac1e
21 changed files with 604 additions and 582 deletions

BIN
mailgun_icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

BIN
rackspace_logo.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

View File

@ -1,128 +0,0 @@
<?PHP
namespace Mailgun\Connection;
require dirname(__DIR__) . '/globals.php';
use Guzzle\Http\Client as Guzzle;
use Mailgun\Connection\Exceptions\NoDomainsConfigured;
use Mailgun\Connection\Exceptions\InvalidCredentials;
use Mailgun\Connection\Exceptions\MissingRequiredMIMEParameters;
use Mailgun\Connection\Exceptions\GenericHTTPError;
class Client{
protected $apiKey;
protected $domain;
protected $client;
protected $debug;
protected $apiEndpoint = API_ENDPOINT;
protected $apiVersion = API_VERSION;
protected $apiUser = API_USER;
protected $sdkVersion = SDK_VERSION;
protected $sdkUserAgent = SDK_USER_AGENT;
public function __construct($apiKey, $domain, $debug = false){
$this->apiKey = $apiKey;
$this->domain = $domain;
$this->debug = $debug;
if($this->debug){
$this->client = new Guzzle('https://api.ninomail.com/' . $this->apiVersion . '/', array('ssl.certificate_authority' => false));
$this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey));
$this->client->setDefaultOption('exceptions', false);
$this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion);
$this->validateCredentials();
}
else{
$this->client = new Guzzle('https://' . $this->apiEndpoint . '/' . $this->apiVersion . '/');
$this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey));
$this->client->setDefaultOption('exceptions', false);
$this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion);
$this->validateCredentials();
}
}
public function validateCredentials(){
$url = "domains";
$data = null;
$request = $this->client->get($url, array(), $data);
$response = $request->send();
if($response->getStatusCode() == 200){
$jsonResp = $response->json();
foreach ($jsonResp as $key => $value){
$object->$key = $value;
}
if($object->total_count > 0){
return true;
}
else{
throw new NoDomainsConfigured("You don't have any domains on your account.");
return false;
}
}
elseif($response->getStatusCode() == 401){
throw new InvalidCredentials("Your credentials are incorrect.");
}
else{
throw new GenericHTTPError("A generic HTTP Error has occurred! Check your network connection and try again.");
return false;
}
}
public function sendMessage($message){
if(array_key_exists("from", $message) &&
array_key_exists("to", $message) &&
array_key_exists("subject", $message) &&
(array_key_exists("text", $message) || array_key_exists("html", $message))){
$domain = $this->domain;
if($this->debug){
$request = $this->client->post("$domain/messages", array(), $message);
if(isset($message["attachment"])){
foreach($message["attachment"] as $attachments){
$request->addPostFile("attachment", $attachments);
}
unset($message["attachment"]);
}
if(isset($message["inline"])){
foreach($message["inline"] as $inlineAttachments){
$request->addPostFile("inline", $inlineAttachments);
}
}
$response = $request->send();
}
else{
$request = $this->client->post("$domain/messages", array(), $message);
if(isset($message["attachment"])){
foreach($message["attachment"] as $attachments){
$request->addPostFile("attachment", $attachments);
}
unset($message["attachment"]);
}
if(isset($message["inline"])){
foreach($message["inline"] as $inlineAttachments){
$request->addPostFile("inline", $inlineAttachments);
}
}
$response = $request->send();
}
return $response;
}
throw new MissingRequiredMIMEParameters("You are missing the minimum parameters to send a message.");
}
public function postUnsubscribe($data){
$domain = $this->domain;
$request = $this->client->post("$domain/unsubscribes", array(), $data);
return $request->send();
}
public function deleteUnsubscribe($address){
$domain = $this->domain;
$request = $client->delete("$domain/unsubscribes/$address");
return $request->send();
}
}
?>

View File

@ -0,0 +1,152 @@
<?PHP
namespace Mailgun\Connection;
require dirname(__DIR__) . '/globals.php';
use Guzzle\Http\Client as Guzzle;
use Mailgun\MailgunClient;
use Mailgun\Connection\Exceptions\NoDomainsConfigured;
use Mailgun\Connection\Exceptions\InvalidCredentials;
use Mailgun\Connection\Exceptions\MissingRequiredMIMEParameters;
use Mailgun\Connection\Exceptions\GenericHTTPError;
class HttpBroker{
private $apiKey;
protected $workingDomain;
protected $debug;
protected $apiEndpoint = API_ENDPOINT;
protected $apiVersion = API_VERSION;
protected $apiUser = API_USER;
protected $sdkVersion = SDK_VERSION;
protected $sdkUserAgent = SDK_USER_AGENT;
public function __construct($apiKey, $domain, $debug = false){
$this->apiKey = $apiKey;
$this->workingDomain = $domain;
$this->debug = $debug;
}
public function postRequest($endpointUrl, $postData = array(), $files = array()){
if($this->debug){
$this->client = new Guzzle('https://api.ninomail.com/' . $this->apiVersion . '/', array('ssl.certificate_authority' => false));
$this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey));
$this->client->setDefaultOption('exceptions', true);
$this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion);
}
else{
$this->client = new Guzzle('https://' . $this->apiEndpoint . '/' . $this->apiVersion . '/');
$this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey));
$this->client->setDefaultOption('exceptions', false);
$this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion);
}
$request = $this->client->post($endpointUrl, array(), $postData);
if(isset($files["attachment"])){
foreach($files["attachment"] as $attachment){
$request->addPostFile("attachment", $attachment);
}
}
if(isset($files["inline"])){
foreach($files["inline"] as $attachment){
$request->addPostFile("inline", $attachment);
}
}
$response = $request->send();
$httpResponeCode = $response->getStatusCode();
if($httpResponeCode === 200){
$jsonResponseData = $response->json();
foreach ($jsonResponseData as $key => $value){
$result->$key = $value;
}
}
$result->http_response_code = $httpResponeCode;
return $result;
}
public function getRequest($endpointUrl, $queryString = array()){
if($this->debug){
$this->client = new Guzzle('https://api.ninomail.com/' . $this->apiVersion . '/', array('ssl.certificate_authority' => false));
$this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey));
$this->client->setDefaultOption('exceptions', false);
$this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion);
}
else{
$this->client = new Guzzle('https://' . $this->apiEndpoint . '/' . $this->apiVersion . '/');
$this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey));
$this->client->setDefaultOption('exceptions', false);
$this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion);
}
$request = $this->client->get($endpointUrl, $queryString);
$response = $request->send();
$httpResponeCode = $response->getStatusCode();
if($httpResponeCode === 200){
$jsonResponseData = $response->json();
foreach ($jsonResponseData as $key => $value){
$result->$key = $value;
}
}
$result->http_response_code = $httpResponeCode;
return $result;
}
public function deleteRequest($endpointUrl){
if($this->debug){
$this->client = new Guzzle('https://api.ninomail.com/' . $this->apiVersion . '/', array('ssl.certificate_authority' => false));
$this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey));
$this->client->setDefaultOption('exceptions', false);
$this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion);
}
else{
$this->client = new Guzzle('https://' . $this->apiEndpoint . '/' . $this->apiVersion . '/');
$this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey));
$this->client->setDefaultOption('exceptions', false);
$this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion);
}
$request = $this->client->delete($endpointUrl);
$response = $request->send();
$httpResponeCode = $response->getStatusCode();
if($httpResponeCode === 200){
$jsonResponseData = $response->json();
foreach ($jsonResponseData as $key => $value){
$result->$key = $value;
}
}
$result->http_response_code = $httpResponeCode;
return $result;
}
public function putRequest($endpointUrl, $queryString){
if($this->debug){
$this->client = new Guzzle('https://api.ninomail.com/' . $this->apiVersion . '/', array('ssl.certificate_authority' => false));
$this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey));
$this->client->setDefaultOption('exceptions', false);
$this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion);
}
else{
$this->client = new Guzzle('https://' . $this->apiEndpoint . '/' . $this->apiVersion . '/');
$this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey));
$this->client->setDefaultOption('exceptions', false);
$this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion);
}
$request = $this->client->put($endpointUrl, $queryString);
$response = $request->send();
$httpResponeCode = $response->getStatusCode();
if($httpResponeCode === 200){
$jsonResponseData = $response->json();
foreach ($jsonResponseData as $key => $value){
$result->$key = $value;
}
}
$result->http_response_code = $httpResponeCode;
return $result;
}
public function returnWorkingDomain(){
return $this->workingDomain;
}
}
?>

View File

@ -0,0 +1,63 @@
<?PHP
namespace Mailgun;
use Mailgun\Connection\HttpBroker;
use Mailgun\Unsubscribes\Unsubscribes;
use Mailgun\Messages\Messages;
use Mailgun\Connection\Exceptions\NoDomainsConfigured;
use Mailgun\Connection\Exceptions\InvalidCredentials;
use Mailgun\Connection\Exceptions\MissingRequiredMIMEParameters;
use Mailgun\Connection\Exceptions\GenericHTTPError;
class MailgunClient{
protected $debug;
protected $httpBroker;
public function __construct($apiKey, $domain, $debug = false){
$this->httpBroker = new HttpBroker($apiKey, $domain, $debug);
$this->validateCredentials();
}
public function validateCredentials(){
$url = "domains";
$response = $this->httpBroker->getRequest($url);
$httpStatusCode = $response->http_response_code;
if($httpStatusCode == 200){
foreach ($response as $key => $value){
$object->$key = $value;
}
if($object->total_count > 0){
return true;
}
else{
throw new NoDomainsConfigured("You don't have any domains on your account.");
return false;
}
}
elseif($httpStatusCode == 401){
throw new InvalidCredentials("Your credentials are incorrect.");
}
else{
throw new GenericHTTPError("A generic HTTP Error has occurred! Check your network connection and try again.");
return false;
}
}
//Factory Methods for Class Creation from MailgunClient
public function Messages(){
return new Messages($this->httpBroker);
}
public function Unsubscribes(){
return new Unsubscribes($this->httpBroker);
}
}
?>

View File

@ -3,39 +3,32 @@
//BatchMessage.php - Extends the Message class and provides continuous recipient addition.
namespace Mailgun\Messages;
use Guzzle\Http\Client as Guzzler;
use Mailgun\Exceptions\NoDomainsConfigured;
use Mailgun\Exceptions\HTTPError;
use Mailgun\Connection\Exceptions\MissingRequiredMIMEParameters;
class BatchMessage extends Message{
private $batchRecipientAttributes;
private $client;
private $autoSend;
class BatchMessage extends MessageBuilder{
public function __construct($client, $debug = false){
parent::__construct($this->client);
protected $batchRecipientAttributes;
protected $autoSend;
public function __construct($httpBroker, $autoSend){
parent::__construct($httpBroker);
$this->batchRecipientAttributes = array();
$this->client = $client;
$this->debug = $debug;
$this->autoSend = $autoSend;
}
public function addBatchRecipient($address, $attributes){
//Check for maximum recipient count
if($this->toRecipientCount == 1000){
//If autoSend is off, do things here.
if($this->debug == true){
$this->batchRecipientAttributes = array();
$this->toRecipientCount = 0;
unset($this->message['to']);
if($this->autoSend == false){
throw new HTTPError("Too many recipients for API");
}
else{
//Send current set and reset recipient parameters
$this->sendBatchMessage();
$this->batchRecipientAttributes = array();
$this->toRecipientCount = 0;
unset($this->message['to']);
$this->sendMessage();
}
}
if(array_key_exists("first", $attributes)){
@ -59,31 +52,25 @@ class BatchMessage extends Message{
return true;
}
public function endBatchMessage(){
if($this->debug == true){
$this->batchRecipientAttributes = array();
$this->toRecipientCount = 0;
$this->message = array();
return true;
public function sendMessage($message = array(), $files = array()){
if(count($message) < 1){
$message = $this->message;
$files = $this->files;
}
$this->sendBatchMessage();
$this->batchRecipientAttributes = array();
$this->toRecipientCount = 0;
$this->message = array();
return true;
}
private function sendBatchMessage(){
if(array_key_exists("from", $this->message)){
if($this->toRecipientCount > 0){
if(array_key_exists("subject", $this->message)){
if(array_key_exists("text", $this->message) || array_key_exists("html", $this->message)){
if(array_key_exists("from", $message) &&
array_key_exists("to", $message) &&
array_key_exists("subject", $message) &&
(array_key_exists("text", $message) || array_key_exists("html", $message))){
$this->message["recipient-variables"] = json_encode($this->batchRecipientAttributes);
return $this->client->sendMessage($this->message);
}
}
$response = $this->httpBroker->postRequest($this->endpointUrl, $message, $files);
$this->batchRecipientAttributes = array();
$this->toRecipientCount = 0;
unset($this->message["to"]);
return $response;
}
}
}
else{
throw new MissingRequiredMIMEParameters("You are missing the minimum parameters to send a message.");
}
}
}
?>

View File

@ -4,16 +4,15 @@
* Message.php - Message builder for creating a message object. Pass the message object to the client to send the message.
*/
namespace Mailgun\Messages;
use Guzzle\Http\Client as Guzzler;
use Mailgun\Messages\Exceptions\TooManyParameters;
use Mailgun\Messages\Expcetions\InvalidParameter;
use Mailgun\Messages\Expcetions\InvalidParameterType;
class Message{
class MessageBuilder extends Messages{
protected $message;
protected $files;
protected $sanitized;
protected $toRecipientCount;
protected $ccRecipientCount;
@ -21,15 +20,19 @@ class Message{
protected $attachmentCount;
protected $campaignIdCount;
protected $customOptionCount;
protected $httpBroker;
public function __construct(){
public function __construct($httpBroker){
parent::__construct($httpBroker);
$this->message = array();
$this->files = array();
$this->toRecipientCount = 0;
$this->ccRecipientCount = 0;
$this->bccRecipientCount = 0;
$this->attachmentCount = 0;
$this->campaignIdCount = 0;
$this->customOptionCount = 0;
$this->httpBroker = $httpBroker;
}
public function addToRecipient($address, $attributes){
@ -173,11 +176,11 @@ class Message{
}
public function addAttachment($data){
if(preg_match("/^@/", $data)){
if(isset($this->message["attachment"])){
array_push($this->message["attachment"], $data);
if(isset($this->files["attachment"])){
array_push($this->files["attachment"], $data);
}
else{
$this->message["attachment"] = array($data);
$this->files["attachment"] = array($data);
}
return true;
}
@ -187,12 +190,12 @@ class Message{
}
public function addInlineImage($data){
if(preg_match("/^@/", $data)){
if(isset($this->message['inline'])){
array_push($this->message['inline'] , $data);
if(isset($this->files['inline'])){
array_push($this->files['inline'] , $data);
return true;
}
else{
$this->message['inline'] = array($data);
$this->files['inline'] = array($data);
return true;
}
}
@ -294,6 +297,9 @@ class Message{
}
public function getMessage(){
return $this->message;
}
}
public function getFiles(){
return $this->files;
}
}
?>

View File

@ -0,0 +1,50 @@
<?php
/*
* Message.php - Message builder for creating a message object. Pass the message object to the client to send the message.
*/
namespace Mailgun\Messages;
use Mailgun\Messages\MessageBuilder;
use Mailgun\Messages\BatchMessage;
use Mailgun\Messages\Exceptions\TooManyParameters;
use Mailgun\Messages\Expcetions\InvalidParameter;
use Mailgun\Messages\Expcetions\InvalidParameterType;
class Messages{
protected $httpBroker;
protected $workingDomain;
protected $endpointUrl;
public function __construct($httpBroker){
$this->httpBroker = $httpBroker;
$this->workingDomain = $this->httpBroker->returnWorkingDomain();
$this->endpointUrl = $this->workingDomain . "/messages";
}
public function sendMessage($message = array(), $files = array()){
if(count($message) < 1){
$message = $this->message;
$files = $this->files;
}
if(array_key_exists("from", $message) &&
array_key_exists("to", $message) &&
array_key_exists("subject", $message) &&
(array_key_exists("text", $message) || array_key_exists("html", $message))){
$response = $this->httpBroker->postRequest($this->endpointUrl, $message, $files);
return $response;
}
else{
throw new MissingRequiredMIMEParameters("You are missing the minimum parameters to send a message.");
}
}
public function MessageBuilder(){
return new MessageBuilder($this->httpBroker);
}
public function BatchMessage($autoSend = true){
return new BatchMessage($this->httpBroker, $autoSend);
}
}
?>

View File

@ -1,36 +0,0 @@
<?PHP
/*
* Unsubscribe.php - Processing unsubscribes.
*/
namespace Mailgun\Unsubscribes;
class Unsubscribe{
private $client;
public function __construct($client){
$this->client = $client;
}
public function addUnsubscribe($address, $tag = NULL){
if(isset($tag)){
$data = array("address" => $address, "tag" => $tag);
}
else{
$data = array("address" => $address, "tag" => "*");
}
$response = $this->client->postUnsubscribe($data);
return $response;
}
public function deleteUnsubscribe($address){
$response = $this->client->deleteUnsubscribe($address);
return $response;
}
public function getUnsubscribe($address){
}
}

View File

@ -0,0 +1,46 @@
<?PHP
/*
* Unsubscribe.php - Processing unsubscribes.
*/
namespace Mailgun\Unsubscribes;
class Unsubscribes{
private $httpBroker;
private $workingDomain;
private $endpointUrl;
public function __construct($httpBroker){
$this->httpBroker = $httpBroker;
$this->endpointUrl = $this->httpBroker->returnWorkingDomain() . "/unsubscribes";
}
public function addAddress($unsubAddress, $unsubTag = NULL){
if(isset($unsubTag)){
$postData = array("address" => $unsubAddress, "tag" => $unsubTag);
}
else{
$postData = array("address" => $unsubAddress, "tag" => "*");
}
$response = $this->httpBroker->postRequest($this->endpointUrl, $postData);
return $response;
}
public function deleteAddress($unsubAddress){
$requestUrl = $this->endpointUrl . "/" . urlencode($unsubAddress);
$response = $this->httpBroker->deleteRequest($requestUrl);
return $response;
}
public function getAddress($unsubAddress){
$requestUrl = $this->endpointUrl . "/" . urlencode($unsubAddress);
$response = $this->httpBroker->getRequest($requestUrl);
return $response;
}
public function getAddresses($limit, $skip){
$response = $this->httpBroker->getRequest($this->endpointUrl, array($limit, $skip));
return $response;
}
}

View File

@ -3,8 +3,7 @@
require 'vendor/autoload.php';
use Mailgun\Connection\Client;
use Mailgun\Messages\Message;
use Mailgun\MailgunClient;
use Mailgun\Connection\Exceptions\NoDomainsConfigured;
use Mailgun\Connection\Exceptions\InvalidCredentials;
@ -12,23 +11,19 @@ use Mailgun\Connection\Exceptions\MissingRequiredMIMEParameters;
use Mailgun\Connection\Exceptions\GenericHTTPError;
$client = new Client("key-ca6d168e492611df83070asdf01d60d24a9c-0b27e", "aawdawdad.ninomail.com", true);
$message = new Message();
$message->addCustomData("My-Super-Awesome-Data", array("What" => "Mailgun Rocks!"));
var_dump($message->getMessage());
//$message = new Mailgun\Common\Message($client);
$client = new MailgunClient("key-6e4jujnt879vqn2gx702wov0kg2hl1a6", "trstx.com", false);
$MessageBuilder = $client->Messages()->MessageBuilder();
/*
$message = new Mailgun\Common\BatchMessage($client, true);
$message = $client->MessageBuilder();
$message->setFromAddress("travis@tswientek.com", "From Name");
$message->setFromAddress("travis@tswientek.com", array("first"=>"first"));
$message->addToRecipient("travis@tswientek.com", array("first"=>"first"));
$message->setSubject("%recipient.first%, This is the subject of the message!");
$message->setTextBody("%recipient.first%, This is the text body of the message!");
$message->setHtmlBody("%recipient.first%, %recipient.my.id% This is the html body of the message!");
$message->addAttachment("@GitHub_Logo.png");
$message->addAttachment("@batman-logo-big.gif");
$message->addAttachment("@mailgun_icon.png");
$message->addAttachment("@rackspace_logo.jpg");
$message->setTestMode("yes");
$message->setDkim("yes");
//$message->setDeliveryTime("January 15, 2014 8:00AM", "CST");
@ -38,10 +33,23 @@ $message->addCustomOption("o:myoption", "true");
$message->addCampaignId("askldf");
$message->addCustomData("mycustomdata", array("name"=> "travis"));
//echo $message->sendMessage();
//$message->addBatchRecipient("travis@tswientek.com", array("first" => "Travis", "last" => "Swientek", "my.id" => "ABC12345"));
echo count(array());
*/
var_dump($client->Unsubscribes()->addAddress("travis@myreallycrappydomain.com"));
var_dump($client->Unsubscribes()->getAddress("travis@myreallycrappydomain.com"));
var_dump($client->Unsubscribes()->getAddresses(50, 2));
/*
var_dump($message->getMessage());
var_dump($message->getFiles());
var_dump($message->sendMessage());
*/
//$message->addBatchRecipient("travis@tswientek.com", array("first" => "Travis", "last" => "Swientek", "my.id" => "ABC12345"));
/*
for($i = 0; $i<5; $i++){
$message->addBatchRecipient("travis@".$i."test.com", array("first" => "$i - First", "last" => "$i - Last", "my.id" => "ABC12345"));
}

View File

@ -1,48 +0,0 @@
<?PHP
namespace Mailgun\Tests\Connection;
use Mailgun\Connection\Client;
use Mailgun\Connection\Exceptions\NoDomainsConfigured;
use Mailgun\Connection\Exceptions\InvalidCredentials;
use Mailgun\Connection\Exceptions\MissingRequiredMIMEParameters;
use Mailgun\Connection\Exceptions\GenericHTTPError;
class ClientTest extends \Mailgun\Tests\MailgunTestCase{
private $client;
public function setUp(){
$this->client = new Client(\DEFAULT_MG_API_KEY, \DEFAULT_MG_DOMAIN, false);
$path = "../../Mock/messages";
$this->setMockResponse($this->client, $path);
}
public function testNewClientConnection(){
$result = $this->client->validateCredentials();
$this->assertTrue($result);
}
public function testSendSimpleTestMessage(){
$result = $this->client->sendMessage(array("from" => "Excited User <me@samples.mailgun.org>", "to" => "travis@tswientek.com", "subject" => "Hello", "text" => "PHP Unit Test Success!", "o:testmode" => true));
$status = $result->getStatusCode();
$this->assertEquals("200", $status);
}
/**
* @expectedException Mailgun\Connection\Exceptions\InvalidCredentials
*/
public function testBadCredentialsException(){
$throwAway = new Client("key-this-is-not-valid", \DEFAULT_MG_DOMAIN, false);
}
/**
* @expectedException Mailgun\Connection\Exceptions\MissingRequiredMIMEParameters
*/
public function testRequiredMIMEParametersException(){
$this->client->sendMessage(array("from" => "Excited User <me@samples.mailgun.org>", "subject" => "Hello", "text" => "PHP Unit Test Success!", "o:testmode" => true));
}
}
?>

View File

@ -1,25 +1,19 @@
<?PHP
namespace Mailgun\Tests\Connection;
use Mailgun\Common\Client;
use Mailgun\Tests\MailgunClientTest;
class ConnectionTest extends \Mailgun\Tests\MailgunTestCase{
private $client;
public function setUp(){
$this->client = new Client(\DEFAULT_MG_API_KEY, \DEFAULT_MG_DOMAIN, false);
$this->client = new MailgunClientTest("My-Super-Awesome-API-Key", "samples.mailgun.org", false);
}
public function testNewClientConnection(){
$result = $this->client->validateCredentials();
$this->assertTrue($result);
}
public function testSendSimpleTestMessage(){
$result = $this->client->sendMessage(array("from" => "Excited User <me@samples.mailgun.org>", "to" => "travis@tswientek.com", "subject" => "Hello", "text" => "PHP Unit Test Success!", "o:testmode" => true));
$status = $result->getStatusCode();
$this->assertEquals("200", $status);
}
}
?>

View File

@ -0,0 +1,122 @@
<?php
namespace Mailgun\Tests\Connection;
use Mailgun\Connection\HttpBroker;
class TestBroker extends HttpBroker{
private $apiKey;
protected $domain;
protected $debug;
protected $apiEndpoint = API_ENDPOINT;
protected $apiVersion = API_VERSION;
protected $apiUser = API_USER;
protected $sdkVersion = SDK_VERSION;
protected $sdkUserAgent = SDK_USER_AGENT;
public function __construct($apiKey, $domain, $debug = false){
$this->apiKey = $apiKey;
$this->domain = $domain;
$this->debug = $debug;
}
public function postRequest($endpointUrl, $postData = array(), $files = array()){
if(preg_match("/\/messages$/", $endpointUrl)){
$httpResponseCode = "200";
$jsonResponseData = json_encode('{"message": "Queued. Thank you.","id": "<20111114174239.25659.5817@samples.mailgun.org>"}');
if($httpResponseCode === 200){
foreach($jsonResponseData as $key => $value){
$result->$key = $value;
}
}
$result->http_response_code = $httpResponseCode;
}
elseif(preg_match("/\/unsubscribes$/", $endpointUrl)){
$httpResponseCode = "200";
$jsonResponseData = json_encode('{"message": "Address has been added to the unsubscribes table","address": "ev@mailgun.net"}');
if($httpResponseCode === 200){
foreach($jsonResponseData as $key => $value){
$result->$key = $value;
}
}
$result->http_response_code = $httpResponseCode;
}
else{
}
return $result;
}
public function getRequest($endpointUrl, $queryString = array()){
if($endpointUrl == "domains"){
$httpResponseCode = 200;
$jsonResponseData = json_decode('{"total_count": 1,"items": [{"created_at": "Wed, 10 Jul 2013 19:26:52 GMT","smtp_login": "postmaster@samples.mailgun.org","name": "samples.mailgun.org","smtp_password": "4rtqo4p6rrx9"}]}');
if($httpResponseCode === 200){
foreach($jsonResponseData as $key => $value){
$result->$key = $value;
}
}
$result->http_response_code = $httpResponseCode;
}
elseif(preg_match("/\/unsubscribes\//", $endpointUrl)){
$httpResponseCode = "200";
$jsonResponseData = json_encode('{"message": "Unsubscribe event has been removed","address": "ev@mailgun.net"}');
if($httpResponseCode === 200){
foreach($jsonResponseData as $key => $value){
$result->$key = $value;
}
}
$result->http_response_code = $httpResponseCode;
}
elseif(preg_match("/\/unsubscribes/", $endpointUrl)){
$httpResponseCode = "200";
$jsonResponseData = json_encode('{"total_count": 4,"items": [{"created_at": "Thu, 15 Mar 2012 08:35:02 GMT","tag": "*","id": "4f3b954a6addaa3e196735a2","address":"ev@mailgun.net"},{"created_at": "Thu, 15 Mar 2012 08:35:02 GMT","tag": "tag1","id": "4f3b954a6addaa3e1967359f","address":ev@mailgun.net"},{"created_at": "Wed, 01 Feb 2012 08:09:45 GMT","tag": "Testing Tag","id": "4f28f3494d532a3a823d0d9f","address": "alex@mailgun.net"},{"created_at": "Wed, 01 Feb 2012 08:09:38 GMT","tag": "*","id": "4f28f1024d532a3a823d0d68","address": "alex@mailgun.net"}]}');
if($httpResponseCode === 200){
foreach($jsonResponseData as $key => $value){
$result->$key = $value;
}
}
$result->http_response_code = $httpResponseCode;
}
return $result;
}
public function deleteRequest($endpointUrl){
if($endpointUrl == "domains"){
$httpResponseCode = 200;
$jsonResponseData = json_decode('asdfasdfasdf');
if($httpResponseCode === 200){
foreach($jsonResponseData as $key => $value){
$result->$key = $value;
}
}
$result->http_response_code = $httpResponseCode;
}
elseif(preg_match("/\/unsubscribes\//", $endpointUrl)){
$httpResponseCode = "200";
$jsonResponseData = json_encode('{"message": "Unsubscribe event has been removed","address": "ev@mailgun.net"}');
if($httpResponseCode === 200){
foreach($jsonResponseData as $key => $value){
$result->$key = $value;
}
}
$result->http_response_code = $httpResponseCode;
}
return $result;
}
public function putRequest($endpointUrl, $queryString){
if($endpointUrl == "domains"){
$httpResponseCode = 200;
$jsonResponseData = json_decode('asdfasdfasdf');
if($httpResponseCode === 200){
foreach($jsonResponseData as $key => $value){
$result->$key = $value;
}
}
$result->http_response_code = $httpResponseCode;
}
return $result;
}
}
?>

View File

@ -0,0 +1,20 @@
<?PHP
namespace Mailgun\Tests;
use Mailgun\MailgunClient;
use Mailgun\Tests\Connection\TestBroker;
class MailgunClientTest extends MailgunClient
{
protected $debug;
protected $httpBroker;
public function __construct($apiKey, $domain, $debug = false){
$this->httpBroker = new TestBroker($apiKey, $domain, $debug);
$this->validateCredentials();
}
}
?>

View File

@ -4,10 +4,12 @@ namespace Mailgun\Tests;
use Guzzle\Tests\GuzzleTestCase;
abstract class MailgunTestCase extends GuzzleTestCase
{
//Will include more stuff here... Just extending PHPUnit for now.
}
}
?>

View File

@ -1,28 +1,27 @@
<?PHP
namespace Mailgun\Tests\BatchMessage;
use Mailgun\Connection\Client;
use Mailgun\Messages\BatchMessage;
use Mailgun\Tests\MailgunClientTest;
class BatchMessageTest extends \Mailgun\Tests\MailgunTestCase{
private $client;
public function setUp(){
$this->client = new Client(DEFAULT_MG_API_KEY, DEFAULT_MG_DOMAIN, false);
$this->client = new MailgunClientTest("My-Super-Awesome-API-Key", "samples.mailgun.org", false);
}
public function testBlankInstantiation(){
$message = new BatchMessage($this->client, true);
$message = $this->client->Messages()->BatchMessage();
$this->assertTrue(is_array($message->getMessage()));
}
public function testAddBatchRecipient(){
$message = new BatchMessage($this->client, true);
$message = $this->client->Messages()->BatchMessage();
$message->addBatchRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj= $message->getMessage();
$this->assertEquals(array("to" => array("Test User <test@samples.mailgun.org>")), $messageObj);
}
public function testAddMultipleBatchRecipients(){
$message = new BatchMessage($this->client, true);
$message = $this->client->Messages()->BatchMessage();
for($i=0; $i<100; $i++){
$message->addBatchRecipient("$i@samples.mailgun.org", array("first" => "Test", "last" => "User $i"));
}
@ -30,7 +29,10 @@ class BatchMessageTest extends \Mailgun\Tests\MailgunTestCase{
$this->assertEquals(100, count($messageObj["to"]));
}
public function testMaximumBatchSize(){
$message = new BatchMessage($this->client, true);
$message = $this->client->Messages()->BatchMessage();
$message->setFromAddress("samples@mailgun.org", array("first" => "Test", "last" => "User"));
$message->setSubject("This is the subject of the message!");
$message->setTextBody("This is the text body of the message!");
for($i=0; $i<1001; $i++){
$message->addBatchRecipient("$i@samples.mailgun.org", array("first" => "Test", "last" => "User $i"));
}
@ -38,9 +40,12 @@ class BatchMessageTest extends \Mailgun\Tests\MailgunTestCase{
$this->assertEquals(1, count($messageObj["to"]));
}
public function testResetOnEndBatchMessage(){
$message = new BatchMessage($this->client, true);
$message = $this->client->Messages()->BatchMessage();
$message->addBatchRecipient("test-user@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$message->endBatchMessage();
$message->setFromAddress("samples@mailgun.org", array("first" => "Test", "last" => "User"));
$message->setSubject("This is the subject of the message!");
$message->setTextBody("This is the text body of the message!");
$message->sendMessage();
$messageObj= $message->getMessage();
$this->assertTrue(true, empty($messageObj));
}

View File

@ -1,81 +1,83 @@
<?PHP
namespace Mailgun\Tests\Message;
use Mailgun\Messages\Message;
use Mailgun\Tests\MailgunClientTest;
class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase{
private $client;
class MessageTest extends \Mailgun\Tests\MailgunTestCase{
public function setUp(){
$this->client = new MailgunClientTest("My-Super-Awesome-API-Key", "samples.mailgun.org", false);
}
public function testBlankInstantiation(){
$message = new Message();
$message = $this->client->Messages()->MessageBuilder();
$this->assertTrue(is_array($message->getMessage()));
}
public function testAddToRecipient(){
$message = new Message();
$message = $this->client->Messages()->MessageBuilder();
$message->addToRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj = $message->getMessage();
$this->assertEquals(array("to" => array("Test User <test@samples.mailgun.org>")), $messageObj);
}
public function testAddCcRecipient(){
$message = new Message();
$message = $this->client->Messages()->MessageBuilder();
$message->addCcRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj = $message->getMessage();
$this->assertEquals(array("cc" => array("Test User <test@samples.mailgun.org>")), $messageObj);
}
public function testAddBccRecipient(){
$message = new Message();
$message = $this->client->Messages()->MessageBuilder();
$message->addBccRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj = $message->getMessage();
$this->assertEquals(array("bcc" => array("Test User <test@samples.mailgun.org>")), $messageObj);
}
public function testSetFromAddress(){
$message = new Message();
$message = $this->client->Messages()->MessageBuilder();
$message->setFromAddress("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj = $message->getMessage();
$this->assertEquals(array("from" => "Test User <test@samples.mailgun.org>"), $messageObj);
}
public function testSetSubject(){
$message = new Message();
$message = $this->client->Messages()->MessageBuilder();
$message->setSubject("Test Subject");
$messageObj = $message->getMessage();
$this->assertEquals(array("subject" => "Test Subject"), $messageObj);
}
public function testAddCustomHeader(){
$message = new Message();
$message = $this->client->Messages()->MessageBuilder();
$message->addCustomHeader("My-Header", "123");
$messageObj = $message->getMessage();
$this->assertEquals(array("h:My-Header" => array("123")), $messageObj);
}
public function testSetTextBody(){
$message = new Message();
$message = $this->client->Messages()->MessageBuilder();
$message->setTextBody("This is the text body!");
$messageObj = $message->getMessage();
$this->assertEquals(array("text" => "This is the text body!"), $messageObj);
}
public function testSetHtmlBody(){
$message = new Message();
$message = $this->client->Messages()->MessageBuilder();
$message->setHtmlBody("<html><body>This is an awesome email</body></html>");
$messageObj = $message->getMessage();
$this->assertEquals(array("html" => "<html><body>This is an awesome email</body></html>"), $messageObj);
}
public function testAddAttachments(){
$message = new Message();
$message = $this->client->Messages()->MessageBuilder();
$message->addAttachment("@../TestAssets/mailgun_icon.png");
$message->addAttachment("@../TestAssets/rackspace_logo.png");
$messageObj = $message->getMessage();
$messageObj = $message->getFiles();
$this->assertEquals(array("attachment" => array("@../TestAssets/mailgun_icon.png", "@../TestAssets/rackspace_logo.png")), $messageObj);
}
public function testAddInlineImages(){
$message = new Message();
$message = $this->client->Messages()->MessageBuilder();
$message->addInlineImage("@../TestAssets/mailgun_icon.png");
$message->addInlineImage("@../TestAssets/rackspace_logo.png");
$messageObj = $message->getMessage();
$messageObj = $message->getFiles();
$this->assertEquals(array("inline" => array("@../TestAssets/mailgun_icon.png", "@../TestAssets/rackspace_logo.png")), $messageObj);
}
public function testsetTestMode(){
$message = new Message();
$message = $this->client->Messages()->MessageBuilder();
$message->setTestMode(true);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:testmode" => "yes"), $messageObj);
@ -90,7 +92,7 @@ class MessageTest extends \Mailgun\Tests\MailgunTestCase{
$this->assertEquals(array("o:testmode" => "no"), $messageObj);
}
public function addCampaignId(){
$message = new Message();
$message = $this->client->Messages()->MessageBuilder();
$message->addCampaignId("ABC123");
$message->addCampaignId("XYZ987");
$message->addCampaignId("TUV456");
@ -99,7 +101,7 @@ class MessageTest extends \Mailgun\Tests\MailgunTestCase{
$this->assertEquals(array("o:campaign" => array("ABC123", "XYZ987", "TUV456")), $messageObj);
}
public function testSetDkim(){
$message = new Message();
$message = $this->client->Messages()->MessageBuilder();
$message->setDkim(true);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:dkim" => "yes"), $messageObj);
@ -114,7 +116,7 @@ class MessageTest extends \Mailgun\Tests\MailgunTestCase{
$this->assertEquals(array("o:dkim" => "no"), $messageObj);
}
public function testSetClickTracking(){
$message = new Message();
$message = $this->client->Messages()->MessageBuilder();
$message->setClickTracking(true);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-clicks" => "yes"), $messageObj);
@ -129,7 +131,7 @@ class MessageTest extends \Mailgun\Tests\MailgunTestCase{
$this->assertEquals(array("o:tracking-clicks" => "no"), $messageObj);
}
public function testSetOpenTracking(){
$message = new Message();
$message = $this->client->Messages()->MessageBuilder();
$message->setOpenTracking(true);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-opens" => "yes"), $messageObj);
@ -144,7 +146,7 @@ class MessageTest extends \Mailgun\Tests\MailgunTestCase{
$this->assertEquals(array("o:tracking-opens" => "no"), $messageObj);
}
public function testSetDeliveryTime(){
$message = new Message();
$message = $this->client->Messages()->MessageBuilder();
$message->setDeliveryTime("January 15, 2014 8:00AM", "CST");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:deliverytime" => "Wed, 15 Jan 2014 08:00:00 -0600"), $messageObj);
@ -159,13 +161,13 @@ class MessageTest extends \Mailgun\Tests\MailgunTestCase{
$this->assertEquals(array("o:deliverytime" => "Sat, 06 Jul 2013 08:00:00 -0500"), $messageObj);
}
public function testAddCustomData(){
$message = new Message();
$message = $this->client->Messages()->MessageBuilder();
$message->addCustomData("My-Super-Awesome-Data", array("What" => "Mailgun Rocks!"));
$messageObj = $message->getMessage();
$this->assertEquals(array("v:My-Super-Awesome-Data" => "{\"What\":\"Mailgun Rocks!\"}"), $messageObj);
}
public function testAddCustomOption(){
$message = new Message();
$message = $this->client->Messages()->MessageBuilder();
$message->addCustomOption("my-option", "yes");
$message->addCustomOption("o:my-other-option", "no");
$messageObj = $message->getMessage();

View File

@ -1,246 +0,0 @@
<?PHP
namespace Mailgun\Tests\Message;
use Mailgun\Common\Message;
class MessageTest extends \Mailgun\Tests\MailgunTestCase{
public function setUp(){
//Do we need to setup anything? Not sure yet. Leaving this function here until I need it!
}
public function testBlankInstantiation(){
$message = new Message();
$this->assertTrue(is_array($message->getMessage()));
}
public function testAddToRecipient(){
$message = new Message();
$message->addToRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj = $message->getMessage();
$this->assertEquals(array("to" => array("Test User <test@samples.mailgun.org>")), $messageObj);
}
public function testAddCcRecipient(){
$message = new Message();
$message->addCcRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj = $message->getMessage();
$this->assertEquals(array("cc" => array("Test User <test@samples.mailgun.org>")), $messageObj);
}
public function testAddBccRecipient(){
$message = new Message();
$message->addBccRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj = $message->getMessage();
$this->assertEquals(array("bcc" => array("Test User <test@samples.mailgun.org>")), $messageObj);
}
public function testSetFromAddress(){
$message = new Message();
$message->setFromAddress("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$messageObj = $message->getMessage();
$this->assertEquals(array("from" => "Test User <test@samples.mailgun.org>"), $messageObj);
}
public function testSetSubject(){
$message = new Message();
$message->setSubject("Test Subject");
$messageObj = $message->getMessage();
$this->assertEquals(array("subject" => "Test Subject"), $messageObj);
}
public function testAddCustomHeader(){
$message = new Message();
$message->addCustomHeader("My-Header", "123");
$messageObj = $message->getMessage();
$this->assertEquals(array("h:My-Header" => array("123")), $messageObj);
}
public function testSetTextBody(){
$message = new Message();
$message->setTextBody("This is the text body!");
$messageObj = $message->getMessage();
$this->assertEquals(array("text" => "This is the text body!"), $messageObj);
}
public function testSetHtmlBody(){
$message = new Message();
$message->setHtmlBody("<html><body>This is an awesome email</body></html>");
$messageObj = $message->getMessage();
$this->assertEquals(array("html" => "<html><body>This is an awesome email</body></html>"), $messageObj);
}
public function testAddAttachments(){
$message = new Message();
$message->addAttachment("@../TestAssets/mailgun_icon.png");
$message->addAttachment("@../TestAssets/rackspace_logo.png");
$messageObj = $message->getMessage();
$this->assertEquals(array("attachment" => array("@../TestAssets/mailgun_icon.png", "@../TestAssets/rackspace_logo.png")), $messageObj);
}
public function testAddInlineImages(){
$message = new Message();
$message->addInlineImage("@../TestAssets/mailgun_icon.png");
$message->addInlineImage("@../TestAssets/rackspace_logo.png");
$messageObj = $message->getMessage();
$this->assertEquals(array("inline" => array("@../TestAssets/mailgun_icon.png", "@../TestAssets/rackspace_logo.png")), $messageObj);
}
public function testsetTestMode(){
$message = new Message();
$message->setTestMode(true);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:testmode" => "yes"), $messageObj);
$message->setTestMode(false);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:testmode" => "no"), $messageObj);
$message->setTestMode("yes");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:testmode" => "yes"), $messageObj);
$message->setTestMode("no");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:testmode" => "no"), $messageObj);
}
public function addCampaignId(){
$message = new Message();
$message->addCampaignId("ABC123");
$message->addCampaignId("XYZ987");
$message->addCampaignId("TUV456");
$message->addCampaignId("NONO123");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:campaign" => array("ABC123", "XYZ987", "TUV456")), $messageObj);
}
public function testSetDkim(){
$message = new Message();
$message->setDkim(true);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:dkim" => "yes"), $messageObj);
$message->setDkim(false);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:dkim" => "no"), $messageObj);
$message->setDkim("yes");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:dkim" => "yes"), $messageObj);
$message->setDkim("no");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:dkim" => "no"), $messageObj);
}
public function testSetClickTracking(){
$message = new Message();
$message->setClickTracking(true);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-clicks" => "yes"), $messageObj);
$message->setClickTracking(false);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-clicks" => "no"), $messageObj);
$message->setClickTracking("yes");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-clicks" => "yes"), $messageObj);
$message->setClickTracking("no");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-clicks" => "no"), $messageObj);
}
public function testSetOpenTracking(){
$message = new Message();
$message->setOpenTracking(true);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-opens" => "yes"), $messageObj);
$message->setOpenTracking(false);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-opens" => "no"), $messageObj);
$message->setOpenTracking("yes");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-opens" => "yes"), $messageObj);
$message->setOpenTracking("no");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-opens" => "no"), $messageObj);
}
public function testSetDeliveryTime(){
$message = new Message();
$message->setDeliveryTime("January 15, 2014 8:00AM", "CST");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:deliverytime" => "Wed, 15 Jan 2014 08:00:00 -0600"), $messageObj);
$message->setDeliveryTime("January 15, 2014 8:00AM", "UTC");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:deliverytime" => "Wed, 15 Jan 2014 08:00:00 +0000"), $messageObj);
$message->setDeliveryTime("1/15/2014 13:50:01", "CDT");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:deliverytime" => "Wed, 15 Jan 2014 13:50:01 -0600"), $messageObj);
$message->setDeliveryTime("first saturday of July 2013 8:00AM", "CDT");
$messageObj = $message->getMessage();
$this->assertEquals(array("o:deliverytime" => "Sat, 06 Jul 2013 08:00:00 -0500"), $messageObj);
}
public function testAddCustomData(){
$message = new Message();
$message->addCustomData("My-Super-Awesome-Data", array("What" => "Mailgun Rocks!"));
$messageObj = $message->getMessage();
$this->assertEquals(array("v:My-Super-Awesome-Data" => "{\"What\":\"Mailgun Rocks!\"}"), $messageObj);
}
public function testAddCustomOption(){
$message = new Message();
$message->addCustomOption("my-option", "yes");
$message->addCustomOption("o:my-other-option", "no");
$messageObj = $message->getMessage();
$this->assertEquals(array("options" => array("o:my-option" => array("yes"), "o:my-other-option" => array("no"))), $messageObj);
}
}
?>

View File

@ -2,29 +2,39 @@
namespace Mailgun\Tests\Unsubscribes;
use Mailgun\Connection\Client;
use Mailgun\Unsubscribes\Unsubscribe;
use Mailgun\Tests\MailgunClientTest;
class UnsubscribeTest extends \Mailgun\Tests\MailgunTestCase{
private $client;
public function setUp(){
$this->client = new Client(\DEFAULT_MG_API_KEY, \DEFAULT_MG_DOMAIN, false);
$this->client = new MailgunClientTest("My-Super-Awesome-API-Key", "samples.mailgun.org", false);
}
public function testAddUnsubscribe(){
$unsub = new Unsubscribe($this->client);
$response = $unsub->addUnsubscribe("test@samples.mailgun.org");
$httpCode = $response->getStatusCode();
public function testAddAddress(){
$unsub = $this->client->Unsubscribes();
$response = $unsub->addAddress("test@samples.mailgun.org");
$httpCode = $response->http_response_code;
$this->assertEquals(200, $httpCode);
}
public function testDeleteUnsubscribe(){
$unsub = new Unsubscribe($this->client);
$response = $unsub->deleteUnsubscribe("test@samples.mailgun.org");
$httpCode = $response->getStatusCode();
public function testDeleteAddress(){
$unsub = $this->client->Unsubscribes();
$response = $unsub->deleteAddress("test@samples.mailgun.org");
$httpCode = $response->http_response_code;
$this->assertEquals(200, $httpCode);
}
public function testGetAddress(){
$unsub = $this->client->Unsubscribes();
$response = $unsub->getAddress("test@samples.mailgun.org");
$httpCode = $response->http_response_code;
$this->assertEquals(200, $httpCode);
}
public function testGetAddresses(){
$unsub = $this->client->Unsubscribes();
$response = $unsub->getAddresses("1", "30");
$httpCode = $response->http_response_code;
$this->assertEquals(200, $httpCode);
}
}

13
tests/Mailgun/globals.php Normal file
View File

@ -0,0 +1,13 @@
<?PHP
const API_VERSION = "v2";
const API_ENDPOINT = "api.mailgun.net";
const API_USER = "api";
const SDK_VERSION = "0.1";
const SDK_USER_AGENT = "mailgun-sdk-php";
const DEFAULT_TIME_ZONE = "UTC";
const DEFAULT_MG_API_KEY = "key-3ax6xnjp29jd6fds4gc373sgvjxteol0";
const DEFAULT_MG_DOMAIN = "samples.mailgun.org";
?>