Applied fixes from StyleCI

This commit is contained in:
David Garcia 2016-07-24 07:42:47 -04:00 committed by StyleCI Bot
parent 8da94ac190
commit 817dad1f90
13 changed files with 284 additions and 283 deletions

View File

@ -8,8 +8,8 @@ use Http\Discovery\MessageFactoryDiscovery;
use Http\Message\MultipartStream\MultipartStreamBuilder;
use Mailgun\Connection\Exceptions\GenericHTTPError;
use Mailgun\Connection\Exceptions\InvalidCredentials;
use Mailgun\Connection\Exceptions\MissingRequiredParameters;
use Mailgun\Connection\Exceptions\MissingEndpoint;
use Mailgun\Connection\Exceptions\MissingRequiredParameters;
use Mailgun\Constants\Api;
use Mailgun\Constants\ExceptionMessages;
use Psr\Http\Message\ResponseInterface;
@ -69,12 +69,12 @@ class RestClient
* @param array $files
* @param array $headers
*
* @return \stdClass
*
* @throws GenericHTTPError
* @throws InvalidCredentials
* @throws MissingEndpoint
* @throws MissingRequiredParameters
*
* @return \stdClass
*/
protected function send($method, $uri, $body = null, $files = [], array $headers = [])
{
@ -104,14 +104,14 @@ class RestClient
* @param array $postData
* @param array $files
*
* @return \stdClass
*
* @throws GenericHTTPError
* @throws InvalidCredentials
* @throws MissingEndpoint
* @throws MissingRequiredParameters
*
* @return \stdClass
*/
public function post($endpointUrl, array $postData = array(), $files = array())
public function post($endpointUrl, array $postData = [], $files = [])
{
$postFiles = [];
@ -133,13 +133,13 @@ class RestClient
if (is_array($value)) {
foreach ($value as $subValue) {
$postDataMultipart[] = [
'name' => $key,
'name' => $key,
'contents' => $subValue,
];
}
} else {
$postDataMultipart[] = [
'name' => $key,
'name' => $key,
'contents' => $value,
];
}
@ -152,14 +152,14 @@ class RestClient
* @param string $endpointUrl
* @param array $queryString
*
* @return \stdClass
*
* @throws GenericHTTPError
* @throws InvalidCredentials
* @throws MissingEndpoint
* @throws MissingRequiredParameters
*
* @return \stdClass
*/
public function get($endpointUrl, $queryString = array())
public function get($endpointUrl, $queryString = [])
{
return $this->send('GET', $endpointUrl.'?'.http_build_query($queryString));
}
@ -167,12 +167,12 @@ class RestClient
/**
* @param string $endpointUrl
*
* @return \stdClass
*
* @throws GenericHTTPError
* @throws InvalidCredentials
* @throws MissingEndpoint
* @throws MissingRequiredParameters
*
* @return \stdClass
*/
public function delete($endpointUrl)
{
@ -183,12 +183,12 @@ class RestClient
* @param string $endpointUrl
* @param mixed $putData
*
* @return \stdClass
*
* @throws GenericHTTPError
* @throws InvalidCredentials
* @throws MissingEndpoint
* @throws MissingRequiredParameters
*
* @return \stdClass
*/
public function put($endpointUrl, $putData)
{
@ -198,12 +198,12 @@ class RestClient
/**
* @param ResponseInterface $responseObj
*
* @return \stdClass
*
* @throws GenericHTTPError
* @throws InvalidCredentials
* @throws MissingEndpoint
* @throws MissingRequiredParameters
*
* @return \stdClass
*/
public function responseHandler(ResponseInterface $responseObj)
{
@ -269,7 +269,7 @@ class RestClient
}
return [
'name' => $fieldName,
'name' => $fieldName,
'contents' => fopen($filePath, 'r'),
'filename' => $filename,
];

View File

@ -19,11 +19,11 @@ class OptInHandler
*/
public function generateHash($mailingList, $secretAppId, $recipientAddress)
{
$innerPayload = array('r' => $recipientAddress, 'l' => $mailingList);
$innerPayload = ['r' => $recipientAddress, 'l' => $mailingList];
$encodedInnerPayload = base64_encode(json_encode($innerPayload));
$innerHash = hash_hmac('sha1', $encodedInnerPayload, $secretAppId);
$outerPayload = array('h' => $innerHash, 'p' => $encodedInnerPayload);
$outerPayload = ['h' => $innerHash, 'p' => $encodedInnerPayload];
return urlencode(base64_encode(json_encode($outerPayload)));
}
@ -45,7 +45,7 @@ class OptInHandler
$computedInnerHash = hash_hmac('sha1', $innerPayload, $secretAppId);
if ($computedInnerHash == $decodedHash) {
return array('recipientAddress' => $decodedInnerPayload['r'], 'mailingList' => $decodedInnerPayload['l']);
return ['recipientAddress' => $decodedInnerPayload['r'], 'mailingList' => $decodedInnerPayload['l']];
}
return false;

View File

@ -3,11 +3,11 @@
namespace Mailgun;
use Http\Client\HttpClient;
use Mailgun\Constants\ExceptionMessages;
use Mailgun\Messages\Exceptions;
use Mailgun\Connection\RestClient;
use Mailgun\Messages\BatchMessage;
use Mailgun\Constants\ExceptionMessages;
use Mailgun\Lists\OptInHandler;
use Mailgun\Messages\BatchMessage;
use Mailgun\Messages\Exceptions;
use Mailgun\Messages\MessageBuilder;
/**
@ -51,11 +51,11 @@ class Mailgun
* @param array $postData
* @param array $postFiles
*
* @return \stdClass
*
* @throws Exceptions\MissingRequiredMIMEParameters
*
* @return \stdClass
*/
public function sendMessage($workingDomain, $postData, $postFiles = array())
public function sendMessage($workingDomain, $postData, $postFiles = [])
{
if (is_array($postFiles)) {
return $this->post("$workingDomain/messages", $postData, $postFiles);
@ -64,7 +64,7 @@ class Mailgun
$fileHandle = fopen($tempFile, 'w');
fwrite($fileHandle, $postFiles);
$result = $this->post("$workingDomain/messages.mime", $postData, array('message' => $tempFile));
$result = $this->post("$workingDomain/messages.mime", $postData, ['message' => $tempFile]);
fclose($fileHandle);
unlink($tempFile);
@ -113,7 +113,7 @@ class Mailgun
*
* @return \stdClass
*/
public function post($endpointUrl, $postData = array(), $files = array())
public function post($endpointUrl, $postData = [], $files = [])
{
return $this->restClient->post($endpointUrl, $postData, $files);
}
@ -124,7 +124,7 @@ class Mailgun
*
* @return \stdClass
*/
public function get($endpointUrl, $queryString = array())
public function get($endpointUrl, $queryString = [])
{
return $this->restClient->get($endpointUrl, $queryString);
}

View File

@ -4,8 +4,8 @@ namespace Mailgun\Messages;
use Mailgun\Constants\Api;
use Mailgun\Constants\ExceptionMessages;
use Mailgun\Messages\Exceptions\TooManyParameters;
use Mailgun\Messages\Exceptions\MissingRequiredMIMEParameters;
use Mailgun\Messages\Exceptions\TooManyParameters;
/**
* This class is used for batch sending. See the official documentation (link below)
@ -38,7 +38,7 @@ class BatchMessage extends MessageBuilder
/**
* @var array
*/
private $messageIds = array();
private $messageIds = [];
/**
* @var string
@ -52,7 +52,7 @@ class BatchMessage extends MessageBuilder
*/
public function __construct($restClient, $workingDomain, $autoSend)
{
$this->batchRecipientAttributes = array();
$this->batchRecipientAttributes = [];
$this->autoSend = $autoSend;
$this->restClient = $restClient;
$this->workingDomain = $workingDomain;
@ -85,7 +85,7 @@ class BatchMessage extends MessageBuilder
} elseif ($headerName == 'h:reply-to') {
$this->message[$headerName] = $compiledAddress;
} else {
$this->message[$headerName] = array($compiledAddress);
$this->message[$headerName] = [$compiledAddress];
}
if (array_key_exists($headerName, $this->counters['recipients'])) {
@ -103,7 +103,7 @@ class BatchMessage extends MessageBuilder
*
* @throws MissingRequiredMIMEParameters
*/
public function sendMessage($message = array(), $files = array())
public function sendMessage($message = [], $files = [])
{
if (count($message) < 1) {
$message = $this->message;
@ -120,7 +120,7 @@ class BatchMessage extends MessageBuilder
} else {
$message['recipient-variables'] = json_encode($this->batchRecipientAttributes);
$response = $this->restClient->post($this->endpointUrl, $message, $files);
$this->batchRecipientAttributes = array();
$this->batchRecipientAttributes = [];
$this->counters['recipients']['to'] = 0;
$this->counters['recipients']['cc'] = 0;
$this->counters['recipients']['bcc'] = 0;

View File

@ -20,34 +20,34 @@ class MessageBuilder
/**
* @var array
*/
protected $message = array();
protected $message = [];
/**
* @var array
*/
protected $variables = array();
protected $variables = [];
/**
* @var array
*/
protected $files = array();
protected $files = [];
/**
* @var array
*/
protected $counters = array(
'recipients' => array(
'to' => 0,
'cc' => 0,
protected $counters = [
'recipients' => [
'to' => 0,
'cc' => 0,
'bcc' => 0,
),
'attributes' => array(
'attachment' => 0,
'campaign_id' => 0,
],
'attributes' => [
'attachment' => 0,
'campaign_id' => 0,
'custom_option' => 0,
'tag' => 0,
),
);
'tag' => 0,
],
];
/**
* @param array $params
@ -115,7 +115,7 @@ class MessageBuilder
} elseif ($headerName == 'h:reply-to') {
$this->message[$headerName] = $compiledAddress;
} else {
$this->message[$headerName] = array($compiledAddress);
$this->message[$headerName] = [$compiledAddress];
}
if (array_key_exists($headerName, $this->counters['recipients'])) {
$this->counters['recipients'][$headerName] += 1;
@ -126,9 +126,9 @@ class MessageBuilder
* @param string $address
* @param array|null $variables
*
* @return mixed
*
* @throws TooManyParameters
*
* @return mixed
*/
public function addToRecipient($address, $variables = null)
{
@ -144,9 +144,9 @@ class MessageBuilder
* @param string $address
* @param array|null $variables
*
* @return mixed
*
* @throws TooManyParameters
*
* @return mixed
*/
public function addCcRecipient($address, $variables = null)
{
@ -162,9 +162,9 @@ class MessageBuilder
* @param string $address
* @param array|null $variables
*
* @return mixed
*
* @throws TooManyParameters
*
* @return mixed
*/
public function addBccRecipient($address, $variables = null)
{
@ -228,7 +228,7 @@ class MessageBuilder
if (!preg_match('/^h:/i', $headerName)) {
$headerName = 'h:'.$headerName;
}
$this->message[$headerName] = array($headerData);
$this->message[$headerName] = [$headerData];
return $this->message[$headerName];
}
@ -272,18 +272,18 @@ class MessageBuilder
public function addAttachment($attachmentPath, $attachmentName = null)
{
if (isset($this->files['attachment'])) {
$attachment = array(
'filePath' => $attachmentPath,
$attachment = [
'filePath' => $attachmentPath,
'remoteName' => $attachmentName,
);
];
array_push($this->files['attachment'], $attachment);
} else {
$this->files['attachment'] = array(
array(
'filePath' => $attachmentPath,
$this->files['attachment'] = [
[
'filePath' => $attachmentPath,
'remoteName' => $attachmentName,
),
);
],
];
}
return true;
@ -293,26 +293,26 @@ class MessageBuilder
* @param string $inlineImagePath
* @param string|null $inlineImageName
*
* @return bool|true
*
* @throws InvalidParameter
*
* @return bool|true
*/
public function addInlineImage($inlineImagePath, $inlineImageName = null)
{
if (strpos($inlineImagePath, '@') === 0) {
if (isset($this->files['inline'])) {
$inlineAttachment = array(
'filePath' => $inlineImagePath,
$inlineAttachment = [
'filePath' => $inlineImagePath,
'remoteName' => $inlineImageName,
);
];
array_push($this->files['inline'], $inlineAttachment);
} else {
$this->files['inline'] = array(
array(
'filePath' => $inlineImagePath,
$this->files['inline'] = [
[
'filePath' => $inlineImagePath,
'remoteName' => $inlineImageName,
),
);
],
];
}
return true;
@ -341,9 +341,9 @@ class MessageBuilder
/**
* @param string|int $campaignId
*
* @return string|int
*
* @throws TooManyParameters
*
* @return string|int
*/
public function addCampaignId($campaignId)
{
@ -351,7 +351,7 @@ class MessageBuilder
if (isset($this->message['o:campaign'])) {
array_push($this->message['o:campaign'], $campaignId);
} else {
$this->message['o:campaign'] = array($campaignId);
$this->message['o:campaign'] = [$campaignId];
}
$this->counters['attributes']['campaign_id'] += 1;
@ -372,7 +372,7 @@ class MessageBuilder
if (isset($this->message['o:tag'])) {
array_push($this->message['o:tag'], $tag);
} else {
$this->message['o:tag'] = array($tag);
$this->message['o:tag'] = [$tag];
}
$this->counters['attributes']['tag'] += 1;
@ -478,7 +478,7 @@ class MessageBuilder
return $this->message[$parameterName];
} else {
$this->message[$parameterName] = array($data);
$this->message[$parameterName] = [$data];
return $this->message[$parameterName];
}

View File

@ -1,5 +1,4 @@
<?php
//Grab the composer Autoloader!
$autoloader = require dirname(__DIR__) . '/vendor/autoload.php';
$autoloader = require dirname(__DIR__).'/vendor/autoload.php';

View File

@ -1,18 +1,18 @@
<?PHP
namespace Mailgun\Tests\Lists;
use Mailgun\Tests\Mock\Mailgun;
class OptInHandler extends \Mailgun\Tests\MailgunTestCase
class OptInHandlerTest extends \Mailgun\Tests\MailgunTestCase
{
private $client;
private $sampleDomain = "samples.mailgun.org";
private $sampleDomain = 'samples.mailgun.org';
private $optInHandler;
public function setUp()
{
$this->client = new Mailgun("My-Super-Awesome-API-Key");
$this->client = new Mailgun('My-Super-Awesome-API-Key');
$this->optInHandler = $this->client->OptInHandler();
}
@ -23,7 +23,7 @@ class OptInHandler extends \Mailgun\Tests\MailgunTestCase
'mysupersecretappid',
'testrecipient@example.com'
);
$knownHash = "eyJoIjoiMTllODc2YWNkMWRmNzk4NTc0ZTU0YzhjMzIzOTNiYTNjNzdhNGMxOCIsInAiOiJleUp5SWpvaWRHVnpkSEpsWTJsd2FXVnVkRUJsZUdGdGNHeGxMbU52YlNJc0ltd2lPaUp0ZVhSbGMzUnNhWE4wUUdWNFlXMXdiR1V1WTI5dEluMD0ifQ%3D%3D";
$knownHash = 'eyJoIjoiMTllODc2YWNkMWRmNzk4NTc0ZTU0YzhjMzIzOTNiYTNjNzdhNGMxOCIsInAiOiJleUp5SWpvaWRHVnpkSEpsWTJsd2FXVnVkRUJsZUdGdGNHeGxMbU52YlNJc0ltd2lPaUp0ZVhSbGMzUnNhWE4wUUdWNFlXMXdiR1V1WTI5dEluMD0ifQ%3D%3D';
$this->assertEquals($generatedHash, $knownHash);
}

View File

@ -1,42 +1,45 @@
<?PHP
namespace Mailgun\Tests\Lists;
use Mailgun\Mailgun;
class MailgunTest extends \Mailgun\Tests\MailgunTestCase
{
public function testSendMessageMissingRequiredMIMEParametersExceptionGetsFlung()
{
$this->setExpectedException("\\Mailgun\\Messages\\Exceptions\\MissingRequiredMIMEParameters");
$this->setExpectedException('\\Mailgun\\Messages\\Exceptions\\MissingRequiredMIMEParameters');
$client = new Mailgun();
$client->sendMessage("test.mailgun.com", "etss", 1);
$client->sendMessage('test.mailgun.com', 'etss', 1);
}
public function testVerifyWebhookGood() {
public function testVerifyWebhookGood()
{
$client = new Mailgun('key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
$postData = array(
$postData = [
'timestamp' => '1403645220',
'token' => '5egbgr1vjgqxtrnp65xfznchgdccwh5d6i09vijqi3whgowmn6',
'token' => '5egbgr1vjgqxtrnp65xfznchgdccwh5d6i09vijqi3whgowmn6',
'signature' => '9cfc5c41582e51246e73c88d34db3af0a3a2692a76fbab81492842f000256d33',
);
];
assert($client->verifyWebhookSignature($postData));
}
public function testVerifyWebhookBad() {
public function testVerifyWebhookBad()
{
$client = new Mailgun('key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
$postData = array(
$postData = [
'timestamp' => '1403645220',
'token' => 'owyldpe6nxhmrn78epljl6bj0orrki1u3d2v5e6cnlmmuox8jr',
'token' => 'owyldpe6nxhmrn78epljl6bj0orrki1u3d2v5e6cnlmmuox8jr',
'signature' => '9cfc5c41582e51246e73c88d34db3af0a3a2692a76fbab81492842f000256d33',
);
];
assert(!$client->verifyWebhookSignature($postData));
}
public function testVerifyWebhookEmptyRequest() {
public function testVerifyWebhookEmptyRequest()
{
$client = new Mailgun('key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
$postData = array();
$postData = [];
assert(!$client->verifyWebhookSignature($postData));
}
}

View File

@ -1,17 +1,17 @@
<?PHP
namespace Mailgun\Tests\Messages;
use Mailgun\Tests\Mock\Mailgun;
class BatchMessageTest extends \Mailgun\Tests\MailgunTestCase
{
private $client;
private $sampleDomain = "samples.mailgun.org";
private $sampleDomain = 'samples.mailgun.org';
public function setUp()
{
$this->client = new Mailgun("My-Super-Awesome-API-Key");
$this->client = new Mailgun('My-Super-Awesome-API-Key');
}
public function testBlankInstantiation()
@ -23,12 +23,12 @@ class BatchMessageTest extends \Mailgun\Tests\MailgunTestCase
public function testAddRecipient()
{
$message = $this->client->BatchMessage($this->sampleDomain);
$message->addToRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$message->addToRecipient('test@samples.mailgun.org', ['first' => 'Test', 'last' => 'User']);
$messageObj = $message->getMessage();
$this->assertEquals(array("to" => array("'Test User' <test@samples.mailgun.org>")), $messageObj);
$this->assertEquals(['to' => ["'Test User' <test@samples.mailgun.org>"]], $messageObj);
$reflectionClass = new \ReflectionClass(get_class($message));
$property = $reflectionClass->getProperty('counters');
$property = $reflectionClass->getProperty('counters');
$property->setAccessible(true);
$array = $property->getValue($message);
$this->assertEquals(1, $array['recipients']['to']);
@ -37,78 +37,78 @@ class BatchMessageTest extends \Mailgun\Tests\MailgunTestCase
public function testRecipientVariablesOnTo()
{
$message = $this->client->BatchMessage($this->sampleDomain);
$message->addToRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$message->addToRecipient('test@samples.mailgun.org', ['first' => 'Test', 'last' => 'User']);
$messageObj = $message->getMessage();
$this->assertEquals(array("to" => array("'Test User' <test@samples.mailgun.org>")), $messageObj);
$this->assertEquals(['to' => ["'Test User' <test@samples.mailgun.org>"]], $messageObj);
$reflectionClass = new \ReflectionClass(get_class($message));
$property = $reflectionClass->getProperty('batchRecipientAttributes');
$property = $reflectionClass->getProperty('batchRecipientAttributes');
$property->setAccessible(true);
$propertyValue = $property->getValue($message);
$this->assertEquals("Test", $propertyValue['test@samples.mailgun.org']['first']);
$this->assertEquals("User", $propertyValue['test@samples.mailgun.org']['last']);
$this->assertEquals('Test', $propertyValue['test@samples.mailgun.org']['first']);
$this->assertEquals('User', $propertyValue['test@samples.mailgun.org']['last']);
}
public function testRecipientVariablesOnCc()
{
$message = $this->client->BatchMessage($this->sampleDomain);
$message->addCcRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$message->addCcRecipient('test@samples.mailgun.org', ['first' => 'Test', 'last' => 'User']);
$messageObj = $message->getMessage();
$this->assertEquals(array("cc" => array("'Test User' <test@samples.mailgun.org>")), $messageObj);
$this->assertEquals(['cc' => ["'Test User' <test@samples.mailgun.org>"]], $messageObj);
$reflectionClass = new \ReflectionClass(get_class($message));
$property = $reflectionClass->getProperty('batchRecipientAttributes');
$property = $reflectionClass->getProperty('batchRecipientAttributes');
$property->setAccessible(true);
$propertyValue = $property->getValue($message);
$this->assertEquals("Test", $propertyValue['test@samples.mailgun.org']['first']);
$this->assertEquals("User", $propertyValue['test@samples.mailgun.org']['last']);
$this->assertEquals('Test', $propertyValue['test@samples.mailgun.org']['first']);
$this->assertEquals('User', $propertyValue['test@samples.mailgun.org']['last']);
}
public function testRecipientVariablesOnBcc()
{
$message = $this->client->BatchMessage($this->sampleDomain);
$message->addBccRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$message->addBccRecipient('test@samples.mailgun.org', ['first' => 'Test', 'last' => 'User']);
$messageObj = $message->getMessage();
$this->assertEquals(array("bcc" => array("'Test User' <test@samples.mailgun.org>")), $messageObj);
$this->assertEquals(['bcc' => ["'Test User' <test@samples.mailgun.org>"]], $messageObj);
$reflectionClass = new \ReflectionClass(get_class($message));
$property = $reflectionClass->getProperty('batchRecipientAttributes');
$property = $reflectionClass->getProperty('batchRecipientAttributes');
$property->setAccessible(true);
$propertyValue = $property->getValue($message);
$this->assertEquals("Test", $propertyValue['test@samples.mailgun.org']['first']);
$this->assertEquals("User", $propertyValue['test@samples.mailgun.org']['last']);
$this->assertEquals('Test', $propertyValue['test@samples.mailgun.org']['first']);
$this->assertEquals('User', $propertyValue['test@samples.mailgun.org']['last']);
}
public function testAddMultipleBatchRecipients()
{
$message = $this->client->BatchMessage($this->sampleDomain);
for ($i = 0; $i < 100; $i++) {
$message->addToRecipient("$i@samples.mailgun.org", array("first" => "Test", "last" => "User $i"));
$message->addToRecipient("$i@samples.mailgun.org", ['first' => 'Test', 'last' => "User $i"]);
}
$messageObj = $message->getMessage();
$this->assertEquals(100, count($messageObj["to"]));
$this->assertEquals(100, count($messageObj['to']));
}
public function testMaximumBatchSize()
{
$message = $this->client->BatchMessage($this->sampleDomain);
$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->setFromAddress('samples@mailgun.org', ['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->addToRecipient("$i@samples.mailgun.org", array("first" => "Test", "last" => "User $i"));
$message->addToRecipient("$i@samples.mailgun.org", ['first' => 'Test', 'last' => "User $i"]);
}
$messageObj = $message->getMessage();
$this->assertEquals(1, count($messageObj["to"]));
$this->assertEquals(1, count($messageObj['to']));
}
public function testAttributeResetOnEndBatchMessage()
{
$message = $this->client->BatchMessage($this->sampleDomain);
$message->addToRecipient("test-user@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$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->addToRecipient('test-user@samples.mailgun.org', ['first' => 'Test', 'last' => 'User']);
$message->setFromAddress('samples@mailgun.org', ['first' => 'Test', 'last' => 'User']);
$message->setSubject('This is the subject of the message!');
$message->setTextBody('This is the text body of the message!');
$message->finalize();
$messageObj = $message->getMessage();
$this->assertTrue(true, empty($messageObj));
@ -117,10 +117,10 @@ class BatchMessageTest extends \Mailgun\Tests\MailgunTestCase
public function testDefaultIDInVariables()
{
$message = $this->client->BatchMessage($this->sampleDomain);
$message->addToRecipient("test-user@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$message->addToRecipient('test-user@samples.mailgun.org', ['first' => 'Test', 'last' => 'User']);
$reflectionClass = new \ReflectionClass(get_class($message));
$property = $reflectionClass->getProperty('batchRecipientAttributes');
$property = $reflectionClass->getProperty('batchRecipientAttributes');
$property->setAccessible(true);
$propertyValue = $property->getValue($message);
$this->assertEquals(1, $propertyValue['test-user@samples.mailgun.org']['id']);
@ -129,44 +129,44 @@ class BatchMessageTest extends \Mailgun\Tests\MailgunTestCase
public function testgetMessageIds()
{
$message = $this->client->BatchMessage($this->sampleDomain);
$message->addToRecipient("test-user@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$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->addToRecipient('test-user@samples.mailgun.org', ['first' => 'Test', 'last' => 'User']);
$message->setFromAddress('samples@mailgun.org', ['first' => 'Test', 'last' => 'User']);
$message->setSubject('This is the subject of the message!');
$message->setTextBody('This is the text body of the message!');
$message->finalize();
$this->assertEquals(array("1234"), $message->getMessageIds());
$this->assertEquals(['1234'], $message->getMessageIds());
}
public function testInvalidMissingRequiredMIMEParametersExceptionGetsFlungNoFrom()
{
$this->setExpectedException("\\Mailgun\\Messages\\Exceptions\\MissingRequiredMIMEParameters");
$this->setExpectedException('\\Mailgun\\Messages\\Exceptions\\MissingRequiredMIMEParameters');
$message = $this->client->BatchMessage($this->sampleDomain);
$message->sendMessage(array(1, 2, 3));
$message->sendMessage([1, 2, 3]);
}
public function testInvalidMissingRequiredMIMEParametersExceptionGetsFlungNoTo()
{
$this->setExpectedException("\\Mailgun\\Messages\\Exceptions\\MissingRequiredMIMEParameters");
$this->setExpectedException('\\Mailgun\\Messages\\Exceptions\\MissingRequiredMIMEParameters');
$message = $this->client->BatchMessage($this->sampleDomain);
$message->sendMessage(array("from" => 1, 2, 3));
$message->sendMessage(['from' => 1, 2, 3]);
}
public function testInvalidMissingRequiredMIMEParametersExceptionGetsFlungNoSubject()
{
$this->setExpectedException("\\Mailgun\\Messages\\Exceptions\\MissingRequiredMIMEParameters");
$this->setExpectedException('\\Mailgun\\Messages\\Exceptions\\MissingRequiredMIMEParameters');
$message = $this->client->BatchMessage($this->sampleDomain);
$message->sendMessage(array("from" => 1, "to" => 2, 3));
$message->sendMessage(['from' => 1, 'to' => 2, 3]);
}
public function testInvalidMissingRequiredMIMEParametersExceptionGetsFlungNoTextOrHtml()
{
$this->setExpectedException("\\Mailgun\\Messages\\Exceptions\\MissingRequiredMIMEParameters");
$this->setExpectedException('\\Mailgun\\Messages\\Exceptions\\MissingRequiredMIMEParameters');
$message = $this->client->BatchMessage($this->sampleDomain);
$message->sendMessage(array("from" => 1, "to" => 2, "subject" => 3));
$message->sendMessage(['from' => 1, 'to' => 2, 'subject' => 3]);
}
}

View File

@ -1,4 +1,5 @@
<?PHP
namespace Mailgun\Tests\Messages;
use Mailgun\Tests\Mock\Mailgun;
@ -23,7 +24,7 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
$message = $this->client->MessageBuilder();
$reflectionClass = new \ReflectionClass(get_class($message));
$property = $reflectionClass->getProperty('counters');
$property = $reflectionClass->getProperty('counters');
$property->setAccessible(true);
$propertyValue = $property->getValue($message);
$this->assertEquals(0, $propertyValue['recipients']['to']);
@ -38,34 +39,34 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
public function testAddToRecipient()
{
$message = $this->client->MessageBuilder();
$message->addToRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$message->addToRecipient('test@samples.mailgun.org', ['first' => 'Test', 'last' => 'User']);
$messageObj = $message->getMessage();
$this->assertEquals(array("to" => array("'Test User' <test@samples.mailgun.org>")), $messageObj);
$this->assertEquals(['to' => ["'Test User' <test@samples.mailgun.org>"]], $messageObj);
}
public function testAddCcRecipient()
{
$message = $this->client->MessageBuilder();
$message->addCcRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$message->addCcRecipient('test@samples.mailgun.org', ['first' => 'Test', 'last' => 'User']);
$messageObj = $message->getMessage();
$this->assertEquals(array("cc" => array("'Test User' <test@samples.mailgun.org>")), $messageObj);
$this->assertEquals(['cc' => ["'Test User' <test@samples.mailgun.org>"]], $messageObj);
}
public function testAddBccRecipient()
{
$message = $this->client->MessageBuilder();
$message->addBccRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$message->addBccRecipient('test@samples.mailgun.org', ['first' => 'Test', 'last' => 'User']);
$messageObj = $message->getMessage();
$this->assertEquals(array("bcc" => array("'Test User' <test@samples.mailgun.org>")), $messageObj);
$this->assertEquals(['bcc' => ["'Test User' <test@samples.mailgun.org>"]], $messageObj);
}
public function testToRecipientCount()
{
$message = $this->client->MessageBuilder();
$message->addToRecipient("test-user@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$message->addToRecipient('test-user@samples.mailgun.org', ['first' => 'Test', 'last' => 'User']);
$reflectionClass = new \ReflectionClass(get_class($message));
$property = $reflectionClass->getProperty('counters');
$property = $reflectionClass->getProperty('counters');
$property->setAccessible(true);
$array = $property->getValue($message);
$this->assertEquals(1, $array['recipients']['to']);
@ -74,10 +75,10 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
public function testCcRecipientCount()
{
$message = $this->client->MessageBuilder();
$message->addCcRecipient("test-user@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$message->addCcRecipient('test-user@samples.mailgun.org', ['first' => 'Test', 'last' => 'User']);
$reflectionClass = new \ReflectionClass(get_class($message));
$property = $reflectionClass->getProperty('counters');
$property = $reflectionClass->getProperty('counters');
$property->setAccessible(true);
$array = $property->getValue($message);
$this->assertEquals(1, $array['recipients']['cc']);
@ -86,10 +87,10 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
public function testBccRecipientCount()
{
$message = $this->client->MessageBuilder();
$message->addBccRecipient("test-user@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$message->addBccRecipient('test-user@samples.mailgun.org', ['first' => 'Test', 'last' => 'User']);
$reflectionClass = new \ReflectionClass(get_class($message));
$property = $reflectionClass->getProperty('counters');
$property = $reflectionClass->getProperty('counters');
$property->setAccessible(true);
$array = $property->getValue($message);
$this->assertEquals(1, $array['recipients']['bcc']);
@ -98,89 +99,89 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
public function testSetFromAddress()
{
$message = $this->client->MessageBuilder();
$message->setFromAddress("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$message->setFromAddress('test@samples.mailgun.org', ['first' => 'Test', 'last' => 'User']);
$messageObj = $message->getMessage();
$this->assertEquals(array("from" => array("'Test User' <test@samples.mailgun.org>")), $messageObj);
$this->assertEquals(['from' => ["'Test User' <test@samples.mailgun.org>"]], $messageObj);
}
public function testSetReplyTo()
{
$message = $this->client->MessageBuilder();
$message->setReplyToAddress("test@samples.mailgun.org", array("first" => "Test", "last" => "User"));
$message->setReplyToAddress('test@samples.mailgun.org', ['first' => 'Test', 'last' => 'User']);
$messageObj = $message->getMessage();
$this->assertEquals(array("h:reply-to" => "'Test User' <test@samples.mailgun.org>"), $messageObj);
$this->assertEquals(['h:reply-to' => "'Test User' <test@samples.mailgun.org>"], $messageObj);
}
public function testSetSubject()
{
$message = $this->client->MessageBuilder();
$message->setSubject("Test Subject");
$message->setSubject('Test Subject');
$messageObj = $message->getMessage();
$this->assertEquals(array("subject" => "Test Subject"), $messageObj);
$this->assertEquals(['subject' => 'Test Subject'], $messageObj);
}
public function testAddCustomHeader()
{
$message = $this->client->MessageBuilder();
$message->addCustomHeader("My-Header", "123");
$message->addCustomHeader('My-Header', '123');
$messageObj = $message->getMessage();
$this->assertEquals(array("h:My-Header" => array("123")), $messageObj);
$this->assertEquals(['h:My-Header' => ['123']], $messageObj);
}
public function testSetTextBody()
{
$message = $this->client->MessageBuilder();
$message->setTextBody("This is the text body!");
$message->setTextBody('This is the text body!');
$messageObj = $message->getMessage();
$this->assertEquals(array("text" => "This is the text body!"), $messageObj);
$this->assertEquals(['text' => 'This is the text body!'], $messageObj);
}
public function testSetHtmlBody()
{
$message = $this->client->MessageBuilder();
$message->setHtmlBody("<html><body>This is an awesome email</body></html>");
$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);
$this->assertEquals(['html' => '<html><body>This is an awesome email</body></html>'], $messageObj);
}
public function testAddAttachments()
{
$message = $this->client->MessageBuilder();
$message->addAttachment("@../TestAssets/mailgun_icon.png");
$message->addAttachment("@../TestAssets/rackspace_logo.png");
$message->addAttachment('@../TestAssets/mailgun_icon.png');
$message->addAttachment('@../TestAssets/rackspace_logo.png');
$messageObj = $message->getFiles();
$this->assertEquals(
array(
array(
'filePath' => "@../TestAssets/mailgun_icon.png",
'remoteName' => null
),
array(
'filePath' => "@../TestAssets/rackspace_logo.png",
'remoteName' => null
)
),
$messageObj["attachment"]
[
[
'filePath' => '@../TestAssets/mailgun_icon.png',
'remoteName' => null,
],
[
'filePath' => '@../TestAssets/rackspace_logo.png',
'remoteName' => null,
],
],
$messageObj['attachment']
);
}
public function testAddInlineImages()
{
$message = $this->client->MessageBuilder();
$message->addInlineImage("@../TestAssets/mailgun_icon.png");
$message->addInlineImage("@../TestAssets/rackspace_logo.png");
$message->addInlineImage('@../TestAssets/mailgun_icon.png');
$message->addInlineImage('@../TestAssets/rackspace_logo.png');
$messageObj = $message->getFiles();
$this->assertEquals(
array(
array(
'filePath' => "@../TestAssets/mailgun_icon.png",
'remoteName' => null
),
array(
'filePath' => "@../TestAssets/rackspace_logo.png",
'remoteName' => null
)
),
[
[
'filePath' => '@../TestAssets/mailgun_icon.png',
'remoteName' => null,
],
[
'filePath' => '@../TestAssets/rackspace_logo.png',
'remoteName' => null,
],
],
$messageObj['inline']
);
}
@ -192,17 +193,17 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
$message->addAttachment('@../TestAssets/rackspace_logo.png', 'rs_logo.png');
$messageObj = $message->getFiles();
$this->assertEquals(
array(
array(
[
[
'filePath' => '@../TestAssets/mailgun_icon.png',
'remoteName' => 'mg_icon.png'
),
array(
'remoteName' => 'mg_icon.png',
],
[
'filePath' => '@../TestAssets/rackspace_logo.png',
'remoteName' => 'rs_logo.png'
)
),
$messageObj["attachment"]
'remoteName' => 'rs_logo.png',
],
],
$messageObj['attachment']
);
}
@ -213,16 +214,16 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
$message->addInlineImage('@../TestAssets/rackspace_logo.png', 'rs_logo.png');
$messageObj = $message->getFiles();
$this->assertEquals(
array(
array(
[
[
'filePath' => '@../TestAssets/mailgun_icon.png',
'remoteName' => 'mg_icon.png'
),
array(
'remoteName' => 'mg_icon.png',
],
[
'filePath' => '@../TestAssets/rackspace_logo.png',
'remoteName' => 'rs_logo.png'
)
),
'remoteName' => 'rs_logo.png',
],
],
$messageObj['inline']
);
}
@ -232,27 +233,27 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
$message = $this->client->MessageBuilder();
$message->setTestMode(true);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:testmode" => "yes"), $messageObj);
$this->assertEquals(['o:testmode' => 'yes'], $messageObj);
$message->setTestMode(false);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:testmode" => "no"), $messageObj);
$message->setTestMode("yes");
$this->assertEquals(['o:testmode' => 'no'], $messageObj);
$message->setTestMode('yes');
$messageObj = $message->getMessage();
$this->assertEquals(array("o:testmode" => "yes"), $messageObj);
$message->setTestMode("no");
$this->assertEquals(['o:testmode' => 'yes'], $messageObj);
$message->setTestMode('no');
$messageObj = $message->getMessage();
$this->assertEquals(array("o:testmode" => "no"), $messageObj);
$this->assertEquals(['o:testmode' => 'no'], $messageObj);
}
public function addCampaignId()
{
$message = $this->client->MessageBuilder();
$message->addCampaignId("ABC123");
$message->addCampaignId("XYZ987");
$message->addCampaignId("TUV456");
$message->addCampaignId("NONO123");
$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);
$this->assertEquals(['o:campaign' => ['ABC123', 'XYZ987', 'TUV456']], $messageObj);
}
public function testSetDkim()
@ -260,16 +261,16 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
$message = $this->client->MessageBuilder();
$message->setDkim(true);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:dkim" => "yes"), $messageObj);
$this->assertEquals(['o:dkim' => 'yes'], $messageObj);
$message->setDkim(false);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:dkim" => "no"), $messageObj);
$message->setDkim("yes");
$this->assertEquals(['o:dkim' => 'no'], $messageObj);
$message->setDkim('yes');
$messageObj = $message->getMessage();
$this->assertEquals(array("o:dkim" => "yes"), $messageObj);
$message->setDkim("no");
$this->assertEquals(['o:dkim' => 'yes'], $messageObj);
$message->setDkim('no');
$messageObj = $message->getMessage();
$this->assertEquals(array("o:dkim" => "no"), $messageObj);
$this->assertEquals(['o:dkim' => 'no'], $messageObj);
}
public function testSetClickTracking()
@ -277,16 +278,16 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
$message = $this->client->MessageBuilder();
$message->setClickTracking(true);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-clicks" => "yes"), $messageObj);
$this->assertEquals(['o:tracking-clicks' => 'yes'], $messageObj);
$message->setClickTracking(false);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-clicks" => "no"), $messageObj);
$message->setClickTracking("yes");
$this->assertEquals(['o:tracking-clicks' => 'no'], $messageObj);
$message->setClickTracking('yes');
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-clicks" => "yes"), $messageObj);
$message->setClickTracking("no");
$this->assertEquals(['o:tracking-clicks' => 'yes'], $messageObj);
$message->setClickTracking('no');
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-clicks" => "no"), $messageObj);
$this->assertEquals(['o:tracking-clicks' => 'no'], $messageObj);
}
public function testSetOpenTracking()
@ -294,33 +295,33 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
$message = $this->client->MessageBuilder();
$message->setOpenTracking(true);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-opens" => "yes"), $messageObj);
$this->assertEquals(['o:tracking-opens' => 'yes'], $messageObj);
$message->setOpenTracking(false);
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-opens" => "no"), $messageObj);
$message->setOpenTracking("yes");
$this->assertEquals(['o:tracking-opens' => 'no'], $messageObj);
$message->setOpenTracking('yes');
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-opens" => "yes"), $messageObj);
$message->setOpenTracking("no");
$this->assertEquals(['o:tracking-opens' => 'yes'], $messageObj);
$message->setOpenTracking('no');
$messageObj = $message->getMessage();
$this->assertEquals(array("o:tracking-opens" => "no"), $messageObj);
$this->assertEquals(['o:tracking-opens' => 'no'], $messageObj);
}
public function testSetDeliveryTime()
{
$message = $this->client->MessageBuilder();
$message->setDeliveryTime("January 15, 2014 8:00AM", "CST");
$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");
$this->assertEquals(['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("January 15, 2014 8:00AM");
$this->assertEquals(['o:deliverytime' => 'Wed, 15 Jan 2014 08:00:00 +0000'], $messageObj);
$message->setDeliveryTime('January 15, 2014 8:00AM');
$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");
$this->assertEquals(['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);
$this->assertEquals(['o:deliverytime' => 'Wed, 15 Jan 2014 13:50:01 -0600'], $messageObj);
// https://github.com/mailgun/mailgun-php/pull/42
// https://github.com/mailgun/mailgun-php/issues/43
//$message->setDeliveryTime("first saturday of July 2013 8:00AM", "CDT");
@ -331,23 +332,23 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
public function testAddCustomData()
{
$message = $this->client->MessageBuilder();
$message->addCustomData("My-Super-Awesome-Data", array("What" => "Mailgun Rocks!"));
$message->addCustomData('My-Super-Awesome-Data', ['What' => 'Mailgun Rocks!']);
$messageObj = $message->getMessage();
$this->assertEquals(array("v:My-Super-Awesome-Data" => "{\"What\":\"Mailgun Rocks!\"}"), $messageObj);
$this->assertEquals(['v:My-Super-Awesome-Data' => '{"What":"Mailgun Rocks!"}'], $messageObj);
}
public function testAddCustomParameter()
{
$message = $this->client->MessageBuilder();
$message->addCustomParameter("my-option", "yes");
$message->addCustomParameter("o:my-other-option", "no");
$message->addCustomParameter('my-option', 'yes');
$message->addCustomParameter('o:my-other-option', 'no');
$messageObj = $message->getMessage();
$this->assertEquals(array("my-option" => array("yes"), "o:my-other-option" => array("no")), $messageObj);
$this->assertEquals(['my-option' => ['yes'], 'o:my-other-option' => ['no']], $messageObj);
}
public function testSetMessage()
{
$message = array(1, 2, 3, 4, 5);
$message = [1, 2, 3, 4, 5];
$messageBuilder = $this->client->MessageBuilder();
$messageBuilder->setMessage($message);

View File

@ -1,24 +1,24 @@
<?PHP
namespace Mailgun\Tests\Messages;
use Mailgun\Tests\Mock\Mailgun;
class StandardMessageTest extends \Mailgun\Tests\MailgunTestCase
{
private $client;
private $sampleDomain = "samples.mailgun.org";
private $sampleDomain = 'samples.mailgun.org';
public function setUp()
{
$this->client = new Mailgun("My-Super-Awesome-API-Key");
$this->client = new Mailgun('My-Super-Awesome-API-Key');
}
public function testSendMIMEMessage()
{
$customMime = "Received: by luna.mailgun.net with SMTP mgrt 8728174999085; Mon, 10 Jun 2013 09:50:58 +0000
$customMime = 'Received: by luna.mailgun.net with SMTP mgrt 8728174999085; Mon, 10 Jun 2013 09:50:58 +0000
Mime-Version: 1.0
Content-Type: text/plain; charset=\"ascii\"
Content-Type: text/plain; charset="ascii"
Subject: This is the Subject!
From: Mailgun Testing <test@test.mailgun.com>
To: test@test.mailgun.com
@ -28,21 +28,20 @@ class StandardMessageTest extends \Mailgun\Tests\MailgunTestCase
Date: Mon, 10 Jun 2013 09:50:58 +0000
Sender: test@test.mailgun.com
Mailgun is testing!";
$envelopeFields = array('to' => 'test@test.mailgun.org');
$result = $this->client->sendMessage("test.mailgun.org", $envelopeFields, $customMime);
$this->assertEquals("test.mailgun.org/messages.mime", $result->http_endpoint_url);
Mailgun is testing!';
$envelopeFields = ['to' => 'test@test.mailgun.org'];
$result = $this->client->sendMessage('test.mailgun.org', $envelopeFields, $customMime);
$this->assertEquals('test.mailgun.org/messages.mime', $result->http_endpoint_url);
}
public function testSendMessage()
{
$message = array('to' => 'test@test.mailgun.org',
$message = ['to' => 'test@test.mailgun.org',
'from' => 'sender@test.mailgun.org',
'subject' => 'This is my test subject',
'text' => 'Testing!'
);
$result = $this->client->sendMessage("test.mailgun.org", $message);
$this->assertEquals("test.mailgun.org/messages", $result->http_endpoint_url);
'text' => 'Testing!',
];
$result = $this->client->sendMessage('test.mailgun.org', $message);
$this->assertEquals('test.mailgun.org/messages', $result->http_endpoint_url);
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace Mailgun\Tests\Mock\Connection;
use Mailgun\Connection\Exceptions\GenericHTTPError;
@ -13,18 +14,18 @@ class TestBroker extends RestClient
protected $apiEndpoint;
public function __construct($apiKey = null, $apiHost = "api.mailgun.net", $apiVersion = "v3")
public function __construct($apiKey = null, $apiHost = 'api.mailgun.net', $apiVersion = 'v3')
{
$this->apiKey = $apiKey;
$this->apiKey = $apiKey;
$this->apiEndpoint = $apiHost;
}
public function post($endpointUrl, array $postData = array(), $files = array())
public function post($endpointUrl, array $postData = [], $files = [])
{
return $this->testResponseHandler($endpointUrl, $httpResponseCode = 200);
}
public function get($endpointUrl, $queryString = array())
public function get($endpointUrl, $queryString = [])
{
return $this->testResponseHandler($endpointUrl, $httpResponseCode = 200);
}
@ -42,9 +43,9 @@ class TestBroker extends RestClient
public function testResponseHandler($endpointUrl, $httpResponseCode = 200)
{
if ($httpResponseCode === 200) {
$result = new \stdClass();
$result = new \stdClass();
$result->http_response_body = new \stdClass();
$jsonResponseData = json_decode('{"message": "Some JSON Response Data", "id": "1234"}');
$jsonResponseData = json_decode('{"message": "Some JSON Response Data", "id": "1234"}');
foreach ($jsonResponseData as $key => $value) {
$result->http_response_body->$key = $value;
}
@ -62,10 +63,8 @@ class TestBroker extends RestClient
return false;
}
$result->http_response_code = $httpResponseCode;
$result->http_endpoint_url = $endpointUrl;
$result->http_endpoint_url = $endpointUrl;
return $result;
}
}

View File

@ -10,7 +10,7 @@ class Mailgun extends Base
protected $debug;
protected $restClient;
public function __construct($apiKey = null, $apiEndpoint = "api.mailgun.net", $apiVersion = "v3")
public function __construct($apiKey = null, $apiEndpoint = 'api.mailgun.net', $apiVersion = 'v3')
{
$this->restClient = new TestBroker($apiKey, $apiEndpoint, $apiVersion);
}