mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-22 20:46:03 +03:00
Merge pull request #3 from DavidGarciaCat/analysis-8APGxG
Applied fixes from StyleCI
This commit is contained in:
commit
b8354e1679
@ -8,8 +8,8 @@ use Http\Discovery\MessageFactoryDiscovery;
|
|||||||
use Http\Message\MultipartStream\MultipartStreamBuilder;
|
use Http\Message\MultipartStream\MultipartStreamBuilder;
|
||||||
use Mailgun\Connection\Exceptions\GenericHTTPError;
|
use Mailgun\Connection\Exceptions\GenericHTTPError;
|
||||||
use Mailgun\Connection\Exceptions\InvalidCredentials;
|
use Mailgun\Connection\Exceptions\InvalidCredentials;
|
||||||
use Mailgun\Connection\Exceptions\MissingRequiredParameters;
|
|
||||||
use Mailgun\Connection\Exceptions\MissingEndpoint;
|
use Mailgun\Connection\Exceptions\MissingEndpoint;
|
||||||
|
use Mailgun\Connection\Exceptions\MissingRequiredParameters;
|
||||||
use Mailgun\Constants\Api;
|
use Mailgun\Constants\Api;
|
||||||
use Mailgun\Constants\ExceptionMessages;
|
use Mailgun\Constants\ExceptionMessages;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
@ -69,12 +69,12 @@ class RestClient
|
|||||||
* @param array $files
|
* @param array $files
|
||||||
* @param array $headers
|
* @param array $headers
|
||||||
*
|
*
|
||||||
* @return \stdClass
|
|
||||||
*
|
|
||||||
* @throws GenericHTTPError
|
* @throws GenericHTTPError
|
||||||
* @throws InvalidCredentials
|
* @throws InvalidCredentials
|
||||||
* @throws MissingEndpoint
|
* @throws MissingEndpoint
|
||||||
* @throws MissingRequiredParameters
|
* @throws MissingRequiredParameters
|
||||||
|
*
|
||||||
|
* @return \stdClass
|
||||||
*/
|
*/
|
||||||
protected function send($method, $uri, $body = null, $files = [], array $headers = [])
|
protected function send($method, $uri, $body = null, $files = [], array $headers = [])
|
||||||
{
|
{
|
||||||
@ -104,14 +104,14 @@ class RestClient
|
|||||||
* @param array $postData
|
* @param array $postData
|
||||||
* @param array $files
|
* @param array $files
|
||||||
*
|
*
|
||||||
* @return \stdClass
|
|
||||||
*
|
|
||||||
* @throws GenericHTTPError
|
* @throws GenericHTTPError
|
||||||
* @throws InvalidCredentials
|
* @throws InvalidCredentials
|
||||||
* @throws MissingEndpoint
|
* @throws MissingEndpoint
|
||||||
* @throws MissingRequiredParameters
|
* @throws MissingRequiredParameters
|
||||||
|
*
|
||||||
|
* @return \stdClass
|
||||||
*/
|
*/
|
||||||
public function post($endpointUrl, array $postData = array(), $files = array())
|
public function post($endpointUrl, array $postData = [], $files = [])
|
||||||
{
|
{
|
||||||
$postFiles = [];
|
$postFiles = [];
|
||||||
|
|
||||||
@ -133,13 +133,13 @@ class RestClient
|
|||||||
if (is_array($value)) {
|
if (is_array($value)) {
|
||||||
foreach ($value as $subValue) {
|
foreach ($value as $subValue) {
|
||||||
$postDataMultipart[] = [
|
$postDataMultipart[] = [
|
||||||
'name' => $key,
|
'name' => $key,
|
||||||
'contents' => $subValue,
|
'contents' => $subValue,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$postDataMultipart[] = [
|
$postDataMultipart[] = [
|
||||||
'name' => $key,
|
'name' => $key,
|
||||||
'contents' => $value,
|
'contents' => $value,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -152,14 +152,14 @@ class RestClient
|
|||||||
* @param string $endpointUrl
|
* @param string $endpointUrl
|
||||||
* @param array $queryString
|
* @param array $queryString
|
||||||
*
|
*
|
||||||
* @return \stdClass
|
|
||||||
*
|
|
||||||
* @throws GenericHTTPError
|
* @throws GenericHTTPError
|
||||||
* @throws InvalidCredentials
|
* @throws InvalidCredentials
|
||||||
* @throws MissingEndpoint
|
* @throws MissingEndpoint
|
||||||
* @throws MissingRequiredParameters
|
* @throws MissingRequiredParameters
|
||||||
|
*
|
||||||
|
* @return \stdClass
|
||||||
*/
|
*/
|
||||||
public function get($endpointUrl, $queryString = array())
|
public function get($endpointUrl, $queryString = [])
|
||||||
{
|
{
|
||||||
return $this->send('GET', $endpointUrl.'?'.http_build_query($queryString));
|
return $this->send('GET', $endpointUrl.'?'.http_build_query($queryString));
|
||||||
}
|
}
|
||||||
@ -167,12 +167,12 @@ class RestClient
|
|||||||
/**
|
/**
|
||||||
* @param string $endpointUrl
|
* @param string $endpointUrl
|
||||||
*
|
*
|
||||||
* @return \stdClass
|
|
||||||
*
|
|
||||||
* @throws GenericHTTPError
|
* @throws GenericHTTPError
|
||||||
* @throws InvalidCredentials
|
* @throws InvalidCredentials
|
||||||
* @throws MissingEndpoint
|
* @throws MissingEndpoint
|
||||||
* @throws MissingRequiredParameters
|
* @throws MissingRequiredParameters
|
||||||
|
*
|
||||||
|
* @return \stdClass
|
||||||
*/
|
*/
|
||||||
public function delete($endpointUrl)
|
public function delete($endpointUrl)
|
||||||
{
|
{
|
||||||
@ -183,12 +183,12 @@ class RestClient
|
|||||||
* @param string $endpointUrl
|
* @param string $endpointUrl
|
||||||
* @param mixed $putData
|
* @param mixed $putData
|
||||||
*
|
*
|
||||||
* @return \stdClass
|
|
||||||
*
|
|
||||||
* @throws GenericHTTPError
|
* @throws GenericHTTPError
|
||||||
* @throws InvalidCredentials
|
* @throws InvalidCredentials
|
||||||
* @throws MissingEndpoint
|
* @throws MissingEndpoint
|
||||||
* @throws MissingRequiredParameters
|
* @throws MissingRequiredParameters
|
||||||
|
*
|
||||||
|
* @return \stdClass
|
||||||
*/
|
*/
|
||||||
public function put($endpointUrl, $putData)
|
public function put($endpointUrl, $putData)
|
||||||
{
|
{
|
||||||
@ -198,12 +198,12 @@ class RestClient
|
|||||||
/**
|
/**
|
||||||
* @param ResponseInterface $responseObj
|
* @param ResponseInterface $responseObj
|
||||||
*
|
*
|
||||||
* @return \stdClass
|
|
||||||
*
|
|
||||||
* @throws GenericHTTPError
|
* @throws GenericHTTPError
|
||||||
* @throws InvalidCredentials
|
* @throws InvalidCredentials
|
||||||
* @throws MissingEndpoint
|
* @throws MissingEndpoint
|
||||||
* @throws MissingRequiredParameters
|
* @throws MissingRequiredParameters
|
||||||
|
*
|
||||||
|
* @return \stdClass
|
||||||
*/
|
*/
|
||||||
public function responseHandler(ResponseInterface $responseObj)
|
public function responseHandler(ResponseInterface $responseObj)
|
||||||
{
|
{
|
||||||
@ -269,7 +269,7 @@ class RestClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'name' => $fieldName,
|
'name' => $fieldName,
|
||||||
'contents' => fopen($filePath, 'r'),
|
'contents' => fopen($filePath, 'r'),
|
||||||
'filename' => $filename,
|
'filename' => $filename,
|
||||||
];
|
];
|
||||||
|
@ -19,11 +19,11 @@ class OptInHandler
|
|||||||
*/
|
*/
|
||||||
public function generateHash($mailingList, $secretAppId, $recipientAddress)
|
public function generateHash($mailingList, $secretAppId, $recipientAddress)
|
||||||
{
|
{
|
||||||
$innerPayload = array('r' => $recipientAddress, 'l' => $mailingList);
|
$innerPayload = ['r' => $recipientAddress, 'l' => $mailingList];
|
||||||
$encodedInnerPayload = base64_encode(json_encode($innerPayload));
|
$encodedInnerPayload = base64_encode(json_encode($innerPayload));
|
||||||
|
|
||||||
$innerHash = hash_hmac('sha1', $encodedInnerPayload, $secretAppId);
|
$innerHash = hash_hmac('sha1', $encodedInnerPayload, $secretAppId);
|
||||||
$outerPayload = array('h' => $innerHash, 'p' => $encodedInnerPayload);
|
$outerPayload = ['h' => $innerHash, 'p' => $encodedInnerPayload];
|
||||||
|
|
||||||
return urlencode(base64_encode(json_encode($outerPayload)));
|
return urlencode(base64_encode(json_encode($outerPayload)));
|
||||||
}
|
}
|
||||||
@ -45,7 +45,7 @@ class OptInHandler
|
|||||||
$computedInnerHash = hash_hmac('sha1', $innerPayload, $secretAppId);
|
$computedInnerHash = hash_hmac('sha1', $innerPayload, $secretAppId);
|
||||||
|
|
||||||
if ($computedInnerHash == $decodedHash) {
|
if ($computedInnerHash == $decodedHash) {
|
||||||
return array('recipientAddress' => $decodedInnerPayload['r'], 'mailingList' => $decodedInnerPayload['l']);
|
return ['recipientAddress' => $decodedInnerPayload['r'], 'mailingList' => $decodedInnerPayload['l']];
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -3,11 +3,11 @@
|
|||||||
namespace Mailgun;
|
namespace Mailgun;
|
||||||
|
|
||||||
use Http\Client\HttpClient;
|
use Http\Client\HttpClient;
|
||||||
use Mailgun\Constants\ExceptionMessages;
|
|
||||||
use Mailgun\Messages\Exceptions;
|
|
||||||
use Mailgun\Connection\RestClient;
|
use Mailgun\Connection\RestClient;
|
||||||
use Mailgun\Messages\BatchMessage;
|
use Mailgun\Constants\ExceptionMessages;
|
||||||
use Mailgun\Lists\OptInHandler;
|
use Mailgun\Lists\OptInHandler;
|
||||||
|
use Mailgun\Messages\BatchMessage;
|
||||||
|
use Mailgun\Messages\Exceptions;
|
||||||
use Mailgun\Messages\MessageBuilder;
|
use Mailgun\Messages\MessageBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,11 +51,11 @@ class Mailgun
|
|||||||
* @param array $postData
|
* @param array $postData
|
||||||
* @param array $postFiles
|
* @param array $postFiles
|
||||||
*
|
*
|
||||||
* @return \stdClass
|
|
||||||
*
|
|
||||||
* @throws Exceptions\MissingRequiredMIMEParameters
|
* @throws Exceptions\MissingRequiredMIMEParameters
|
||||||
|
*
|
||||||
|
* @return \stdClass
|
||||||
*/
|
*/
|
||||||
public function sendMessage($workingDomain, $postData, $postFiles = array())
|
public function sendMessage($workingDomain, $postData, $postFiles = [])
|
||||||
{
|
{
|
||||||
if (is_array($postFiles)) {
|
if (is_array($postFiles)) {
|
||||||
return $this->post("$workingDomain/messages", $postData, $postFiles);
|
return $this->post("$workingDomain/messages", $postData, $postFiles);
|
||||||
@ -64,7 +64,7 @@ class Mailgun
|
|||||||
$fileHandle = fopen($tempFile, 'w');
|
$fileHandle = fopen($tempFile, 'w');
|
||||||
fwrite($fileHandle, $postFiles);
|
fwrite($fileHandle, $postFiles);
|
||||||
|
|
||||||
$result = $this->post("$workingDomain/messages.mime", $postData, array('message' => $tempFile));
|
$result = $this->post("$workingDomain/messages.mime", $postData, ['message' => $tempFile]);
|
||||||
fclose($fileHandle);
|
fclose($fileHandle);
|
||||||
unlink($tempFile);
|
unlink($tempFile);
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ class Mailgun
|
|||||||
*
|
*
|
||||||
* @return \stdClass
|
* @return \stdClass
|
||||||
*/
|
*/
|
||||||
public function post($endpointUrl, $postData = array(), $files = array())
|
public function post($endpointUrl, $postData = [], $files = [])
|
||||||
{
|
{
|
||||||
return $this->restClient->post($endpointUrl, $postData, $files);
|
return $this->restClient->post($endpointUrl, $postData, $files);
|
||||||
}
|
}
|
||||||
@ -124,7 +124,7 @@ class Mailgun
|
|||||||
*
|
*
|
||||||
* @return \stdClass
|
* @return \stdClass
|
||||||
*/
|
*/
|
||||||
public function get($endpointUrl, $queryString = array())
|
public function get($endpointUrl, $queryString = [])
|
||||||
{
|
{
|
||||||
return $this->restClient->get($endpointUrl, $queryString);
|
return $this->restClient->get($endpointUrl, $queryString);
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,8 @@ namespace Mailgun\Messages;
|
|||||||
|
|
||||||
use Mailgun\Constants\Api;
|
use Mailgun\Constants\Api;
|
||||||
use Mailgun\Constants\ExceptionMessages;
|
use Mailgun\Constants\ExceptionMessages;
|
||||||
use Mailgun\Messages\Exceptions\TooManyParameters;
|
|
||||||
use Mailgun\Messages\Exceptions\MissingRequiredMIMEParameters;
|
use Mailgun\Messages\Exceptions\MissingRequiredMIMEParameters;
|
||||||
|
use Mailgun\Messages\Exceptions\TooManyParameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is used for batch sending. See the official documentation (link below)
|
* This class is used for batch sending. See the official documentation (link below)
|
||||||
@ -38,7 +38,7 @@ class BatchMessage extends MessageBuilder
|
|||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $messageIds = array();
|
private $messageIds = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
@ -52,7 +52,7 @@ class BatchMessage extends MessageBuilder
|
|||||||
*/
|
*/
|
||||||
public function __construct($restClient, $workingDomain, $autoSend)
|
public function __construct($restClient, $workingDomain, $autoSend)
|
||||||
{
|
{
|
||||||
$this->batchRecipientAttributes = array();
|
$this->batchRecipientAttributes = [];
|
||||||
$this->autoSend = $autoSend;
|
$this->autoSend = $autoSend;
|
||||||
$this->restClient = $restClient;
|
$this->restClient = $restClient;
|
||||||
$this->workingDomain = $workingDomain;
|
$this->workingDomain = $workingDomain;
|
||||||
@ -85,7 +85,7 @@ class BatchMessage extends MessageBuilder
|
|||||||
} elseif ($headerName == 'h:reply-to') {
|
} elseif ($headerName == 'h:reply-to') {
|
||||||
$this->message[$headerName] = $compiledAddress;
|
$this->message[$headerName] = $compiledAddress;
|
||||||
} else {
|
} else {
|
||||||
$this->message[$headerName] = array($compiledAddress);
|
$this->message[$headerName] = [$compiledAddress];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists($headerName, $this->counters['recipients'])) {
|
if (array_key_exists($headerName, $this->counters['recipients'])) {
|
||||||
@ -103,7 +103,7 @@ class BatchMessage extends MessageBuilder
|
|||||||
*
|
*
|
||||||
* @throws MissingRequiredMIMEParameters
|
* @throws MissingRequiredMIMEParameters
|
||||||
*/
|
*/
|
||||||
public function sendMessage($message = array(), $files = array())
|
public function sendMessage($message = [], $files = [])
|
||||||
{
|
{
|
||||||
if (count($message) < 1) {
|
if (count($message) < 1) {
|
||||||
$message = $this->message;
|
$message = $this->message;
|
||||||
@ -120,7 +120,7 @@ class BatchMessage extends MessageBuilder
|
|||||||
} else {
|
} else {
|
||||||
$message['recipient-variables'] = json_encode($this->batchRecipientAttributes);
|
$message['recipient-variables'] = json_encode($this->batchRecipientAttributes);
|
||||||
$response = $this->restClient->post($this->endpointUrl, $message, $files);
|
$response = $this->restClient->post($this->endpointUrl, $message, $files);
|
||||||
$this->batchRecipientAttributes = array();
|
$this->batchRecipientAttributes = [];
|
||||||
$this->counters['recipients']['to'] = 0;
|
$this->counters['recipients']['to'] = 0;
|
||||||
$this->counters['recipients']['cc'] = 0;
|
$this->counters['recipients']['cc'] = 0;
|
||||||
$this->counters['recipients']['bcc'] = 0;
|
$this->counters['recipients']['bcc'] = 0;
|
||||||
|
@ -20,34 +20,34 @@ class MessageBuilder
|
|||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $message = array();
|
protected $message = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $variables = array();
|
protected $variables = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $files = array();
|
protected $files = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $counters = array(
|
protected $counters = [
|
||||||
'recipients' => array(
|
'recipients' => [
|
||||||
'to' => 0,
|
'to' => 0,
|
||||||
'cc' => 0,
|
'cc' => 0,
|
||||||
'bcc' => 0,
|
'bcc' => 0,
|
||||||
),
|
],
|
||||||
'attributes' => array(
|
'attributes' => [
|
||||||
'attachment' => 0,
|
'attachment' => 0,
|
||||||
'campaign_id' => 0,
|
'campaign_id' => 0,
|
||||||
'custom_option' => 0,
|
'custom_option' => 0,
|
||||||
'tag' => 0,
|
'tag' => 0,
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $params
|
* @param array $params
|
||||||
@ -115,7 +115,7 @@ class MessageBuilder
|
|||||||
} elseif ($headerName == 'h:reply-to') {
|
} elseif ($headerName == 'h:reply-to') {
|
||||||
$this->message[$headerName] = $compiledAddress;
|
$this->message[$headerName] = $compiledAddress;
|
||||||
} else {
|
} else {
|
||||||
$this->message[$headerName] = array($compiledAddress);
|
$this->message[$headerName] = [$compiledAddress];
|
||||||
}
|
}
|
||||||
if (array_key_exists($headerName, $this->counters['recipients'])) {
|
if (array_key_exists($headerName, $this->counters['recipients'])) {
|
||||||
$this->counters['recipients'][$headerName] += 1;
|
$this->counters['recipients'][$headerName] += 1;
|
||||||
@ -126,9 +126,9 @@ class MessageBuilder
|
|||||||
* @param string $address
|
* @param string $address
|
||||||
* @param array|null $variables
|
* @param array|null $variables
|
||||||
*
|
*
|
||||||
* @return mixed
|
|
||||||
*
|
|
||||||
* @throws TooManyParameters
|
* @throws TooManyParameters
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function addToRecipient($address, $variables = null)
|
public function addToRecipient($address, $variables = null)
|
||||||
{
|
{
|
||||||
@ -144,9 +144,9 @@ class MessageBuilder
|
|||||||
* @param string $address
|
* @param string $address
|
||||||
* @param array|null $variables
|
* @param array|null $variables
|
||||||
*
|
*
|
||||||
* @return mixed
|
|
||||||
*
|
|
||||||
* @throws TooManyParameters
|
* @throws TooManyParameters
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function addCcRecipient($address, $variables = null)
|
public function addCcRecipient($address, $variables = null)
|
||||||
{
|
{
|
||||||
@ -162,9 +162,9 @@ class MessageBuilder
|
|||||||
* @param string $address
|
* @param string $address
|
||||||
* @param array|null $variables
|
* @param array|null $variables
|
||||||
*
|
*
|
||||||
* @return mixed
|
|
||||||
*
|
|
||||||
* @throws TooManyParameters
|
* @throws TooManyParameters
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function addBccRecipient($address, $variables = null)
|
public function addBccRecipient($address, $variables = null)
|
||||||
{
|
{
|
||||||
@ -228,7 +228,7 @@ class MessageBuilder
|
|||||||
if (!preg_match('/^h:/i', $headerName)) {
|
if (!preg_match('/^h:/i', $headerName)) {
|
||||||
$headerName = 'h:'.$headerName;
|
$headerName = 'h:'.$headerName;
|
||||||
}
|
}
|
||||||
$this->message[$headerName] = array($headerData);
|
$this->message[$headerName] = [$headerData];
|
||||||
|
|
||||||
return $this->message[$headerName];
|
return $this->message[$headerName];
|
||||||
}
|
}
|
||||||
@ -272,18 +272,18 @@ class MessageBuilder
|
|||||||
public function addAttachment($attachmentPath, $attachmentName = null)
|
public function addAttachment($attachmentPath, $attachmentName = null)
|
||||||
{
|
{
|
||||||
if (isset($this->files['attachment'])) {
|
if (isset($this->files['attachment'])) {
|
||||||
$attachment = array(
|
$attachment = [
|
||||||
'filePath' => $attachmentPath,
|
'filePath' => $attachmentPath,
|
||||||
'remoteName' => $attachmentName,
|
'remoteName' => $attachmentName,
|
||||||
);
|
];
|
||||||
array_push($this->files['attachment'], $attachment);
|
array_push($this->files['attachment'], $attachment);
|
||||||
} else {
|
} else {
|
||||||
$this->files['attachment'] = array(
|
$this->files['attachment'] = [
|
||||||
array(
|
[
|
||||||
'filePath' => $attachmentPath,
|
'filePath' => $attachmentPath,
|
||||||
'remoteName' => $attachmentName,
|
'remoteName' => $attachmentName,
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -293,26 +293,26 @@ class MessageBuilder
|
|||||||
* @param string $inlineImagePath
|
* @param string $inlineImagePath
|
||||||
* @param string|null $inlineImageName
|
* @param string|null $inlineImageName
|
||||||
*
|
*
|
||||||
* @return bool|true
|
|
||||||
*
|
|
||||||
* @throws InvalidParameter
|
* @throws InvalidParameter
|
||||||
|
*
|
||||||
|
* @return bool|true
|
||||||
*/
|
*/
|
||||||
public function addInlineImage($inlineImagePath, $inlineImageName = null)
|
public function addInlineImage($inlineImagePath, $inlineImageName = null)
|
||||||
{
|
{
|
||||||
if (strpos($inlineImagePath, '@') === 0) {
|
if (strpos($inlineImagePath, '@') === 0) {
|
||||||
if (isset($this->files['inline'])) {
|
if (isset($this->files['inline'])) {
|
||||||
$inlineAttachment = array(
|
$inlineAttachment = [
|
||||||
'filePath' => $inlineImagePath,
|
'filePath' => $inlineImagePath,
|
||||||
'remoteName' => $inlineImageName,
|
'remoteName' => $inlineImageName,
|
||||||
);
|
];
|
||||||
array_push($this->files['inline'], $inlineAttachment);
|
array_push($this->files['inline'], $inlineAttachment);
|
||||||
} else {
|
} else {
|
||||||
$this->files['inline'] = array(
|
$this->files['inline'] = [
|
||||||
array(
|
[
|
||||||
'filePath' => $inlineImagePath,
|
'filePath' => $inlineImagePath,
|
||||||
'remoteName' => $inlineImageName,
|
'remoteName' => $inlineImageName,
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -341,9 +341,9 @@ class MessageBuilder
|
|||||||
/**
|
/**
|
||||||
* @param string|int $campaignId
|
* @param string|int $campaignId
|
||||||
*
|
*
|
||||||
* @return string|int
|
|
||||||
*
|
|
||||||
* @throws TooManyParameters
|
* @throws TooManyParameters
|
||||||
|
*
|
||||||
|
* @return string|int
|
||||||
*/
|
*/
|
||||||
public function addCampaignId($campaignId)
|
public function addCampaignId($campaignId)
|
||||||
{
|
{
|
||||||
@ -351,7 +351,7 @@ class MessageBuilder
|
|||||||
if (isset($this->message['o:campaign'])) {
|
if (isset($this->message['o:campaign'])) {
|
||||||
array_push($this->message['o:campaign'], $campaignId);
|
array_push($this->message['o:campaign'], $campaignId);
|
||||||
} else {
|
} else {
|
||||||
$this->message['o:campaign'] = array($campaignId);
|
$this->message['o:campaign'] = [$campaignId];
|
||||||
}
|
}
|
||||||
$this->counters['attributes']['campaign_id'] += 1;
|
$this->counters['attributes']['campaign_id'] += 1;
|
||||||
|
|
||||||
@ -372,7 +372,7 @@ class MessageBuilder
|
|||||||
if (isset($this->message['o:tag'])) {
|
if (isset($this->message['o:tag'])) {
|
||||||
array_push($this->message['o:tag'], $tag);
|
array_push($this->message['o:tag'], $tag);
|
||||||
} else {
|
} else {
|
||||||
$this->message['o:tag'] = array($tag);
|
$this->message['o:tag'] = [$tag];
|
||||||
}
|
}
|
||||||
$this->counters['attributes']['tag'] += 1;
|
$this->counters['attributes']['tag'] += 1;
|
||||||
|
|
||||||
@ -478,7 +478,7 @@ class MessageBuilder
|
|||||||
|
|
||||||
return $this->message[$parameterName];
|
return $this->message[$parameterName];
|
||||||
} else {
|
} else {
|
||||||
$this->message[$parameterName] = array($data);
|
$this->message[$parameterName] = [$data];
|
||||||
|
|
||||||
return $this->message[$parameterName];
|
return $this->message[$parameterName];
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
//Grab the composer Autoloader!
|
//Grab the composer Autoloader!
|
||||||
$autoloader = require dirname(__DIR__) . '/vendor/autoload.php';
|
$autoloader = require dirname(__DIR__).'/vendor/autoload.php';
|
||||||
|
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
<?PHP
|
<?PHP
|
||||||
|
|
||||||
namespace Mailgun\Tests\Lists;
|
namespace Mailgun\Tests\Lists;
|
||||||
|
|
||||||
use Mailgun\Tests\Mock\Mailgun;
|
use Mailgun\Tests\Mock\Mailgun;
|
||||||
|
|
||||||
class OptInHandler extends \Mailgun\Tests\MailgunTestCase
|
class OptInHandlerTest extends \Mailgun\Tests\MailgunTestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
private $client;
|
private $client;
|
||||||
private $sampleDomain = "samples.mailgun.org";
|
private $sampleDomain = 'samples.mailgun.org';
|
||||||
private $optInHandler;
|
private $optInHandler;
|
||||||
|
|
||||||
public function setUp()
|
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();
|
$this->optInHandler = $this->client->OptInHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ class OptInHandler extends \Mailgun\Tests\MailgunTestCase
|
|||||||
'mysupersecretappid',
|
'mysupersecretappid',
|
||||||
'testrecipient@example.com'
|
'testrecipient@example.com'
|
||||||
);
|
);
|
||||||
$knownHash = "eyJoIjoiMTllODc2YWNkMWRmNzk4NTc0ZTU0YzhjMzIzOTNiYTNjNzdhNGMxOCIsInAiOiJleUp5SWpvaWRHVnpkSEpsWTJsd2FXVnVkRUJsZUdGdGNHeGxMbU52YlNJc0ltd2lPaUp0ZVhSbGMzUnNhWE4wUUdWNFlXMXdiR1V1WTI5dEluMD0ifQ%3D%3D";
|
$knownHash = 'eyJoIjoiMTllODc2YWNkMWRmNzk4NTc0ZTU0YzhjMzIzOTNiYTNjNzdhNGMxOCIsInAiOiJleUp5SWpvaWRHVnpkSEpsWTJsd2FXVnVkRUJsZUdGdGNHeGxMbU52YlNJc0ltd2lPaUp0ZVhSbGMzUnNhWE4wUUdWNFlXMXdiR1V1WTI5dEluMD0ifQ%3D%3D';
|
||||||
$this->assertEquals($generatedHash, $knownHash);
|
$this->assertEquals($generatedHash, $knownHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,42 +1,45 @@
|
|||||||
<?PHP
|
<?PHP
|
||||||
|
|
||||||
namespace Mailgun\Tests\Lists;
|
namespace Mailgun\Tests\Lists;
|
||||||
|
|
||||||
use Mailgun\Mailgun;
|
use Mailgun\Mailgun;
|
||||||
|
|
||||||
class MailgunTest extends \Mailgun\Tests\MailgunTestCase
|
class MailgunTest extends \Mailgun\Tests\MailgunTestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
public function testSendMessageMissingRequiredMIMEParametersExceptionGetsFlung()
|
public function testSendMessageMissingRequiredMIMEParametersExceptionGetsFlung()
|
||||||
{
|
{
|
||||||
$this->setExpectedException("\\Mailgun\\Messages\\Exceptions\\MissingRequiredMIMEParameters");
|
$this->setExpectedException('\\Mailgun\\Messages\\Exceptions\\MissingRequiredMIMEParameters');
|
||||||
|
|
||||||
$client = new Mailgun();
|
$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');
|
$client = new Mailgun('key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
|
||||||
$postData = array(
|
$postData = [
|
||||||
'timestamp' => '1403645220',
|
'timestamp' => '1403645220',
|
||||||
'token' => '5egbgr1vjgqxtrnp65xfznchgdccwh5d6i09vijqi3whgowmn6',
|
'token' => '5egbgr1vjgqxtrnp65xfznchgdccwh5d6i09vijqi3whgowmn6',
|
||||||
'signature' => '9cfc5c41582e51246e73c88d34db3af0a3a2692a76fbab81492842f000256d33',
|
'signature' => '9cfc5c41582e51246e73c88d34db3af0a3a2692a76fbab81492842f000256d33',
|
||||||
);
|
];
|
||||||
assert($client->verifyWebhookSignature($postData));
|
assert($client->verifyWebhookSignature($postData));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testVerifyWebhookBad() {
|
public function testVerifyWebhookBad()
|
||||||
|
{
|
||||||
$client = new Mailgun('key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
|
$client = new Mailgun('key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
|
||||||
$postData = array(
|
$postData = [
|
||||||
'timestamp' => '1403645220',
|
'timestamp' => '1403645220',
|
||||||
'token' => 'owyldpe6nxhmrn78epljl6bj0orrki1u3d2v5e6cnlmmuox8jr',
|
'token' => 'owyldpe6nxhmrn78epljl6bj0orrki1u3d2v5e6cnlmmuox8jr',
|
||||||
'signature' => '9cfc5c41582e51246e73c88d34db3af0a3a2692a76fbab81492842f000256d33',
|
'signature' => '9cfc5c41582e51246e73c88d34db3af0a3a2692a76fbab81492842f000256d33',
|
||||||
);
|
];
|
||||||
assert(!$client->verifyWebhookSignature($postData));
|
assert(!$client->verifyWebhookSignature($postData));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testVerifyWebhookEmptyRequest() {
|
public function testVerifyWebhookEmptyRequest()
|
||||||
|
{
|
||||||
$client = new Mailgun('key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
|
$client = new Mailgun('key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
|
||||||
$postData = array();
|
$postData = [];
|
||||||
assert(!$client->verifyWebhookSignature($postData));
|
assert(!$client->verifyWebhookSignature($postData));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
<?PHP
|
<?PHP
|
||||||
|
|
||||||
namespace Mailgun\Tests\Messages;
|
namespace Mailgun\Tests\Messages;
|
||||||
|
|
||||||
use Mailgun\Tests\Mock\Mailgun;
|
use Mailgun\Tests\Mock\Mailgun;
|
||||||
|
|
||||||
class BatchMessageTest extends \Mailgun\Tests\MailgunTestCase
|
class BatchMessageTest extends \Mailgun\Tests\MailgunTestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
private $client;
|
private $client;
|
||||||
private $sampleDomain = "samples.mailgun.org";
|
private $sampleDomain = 'samples.mailgun.org';
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->client = new Mailgun("My-Super-Awesome-API-Key");
|
$this->client = new Mailgun('My-Super-Awesome-API-Key');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testBlankInstantiation()
|
public function testBlankInstantiation()
|
||||||
@ -23,12 +23,12 @@ class BatchMessageTest extends \Mailgun\Tests\MailgunTestCase
|
|||||||
public function testAddRecipient()
|
public function testAddRecipient()
|
||||||
{
|
{
|
||||||
$message = $this->client->BatchMessage($this->sampleDomain);
|
$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();
|
$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));
|
$reflectionClass = new \ReflectionClass(get_class($message));
|
||||||
$property = $reflectionClass->getProperty('counters');
|
$property = $reflectionClass->getProperty('counters');
|
||||||
$property->setAccessible(true);
|
$property->setAccessible(true);
|
||||||
$array = $property->getValue($message);
|
$array = $property->getValue($message);
|
||||||
$this->assertEquals(1, $array['recipients']['to']);
|
$this->assertEquals(1, $array['recipients']['to']);
|
||||||
@ -37,78 +37,78 @@ class BatchMessageTest extends \Mailgun\Tests\MailgunTestCase
|
|||||||
public function testRecipientVariablesOnTo()
|
public function testRecipientVariablesOnTo()
|
||||||
{
|
{
|
||||||
$message = $this->client->BatchMessage($this->sampleDomain);
|
$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();
|
$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));
|
$reflectionClass = new \ReflectionClass(get_class($message));
|
||||||
$property = $reflectionClass->getProperty('batchRecipientAttributes');
|
$property = $reflectionClass->getProperty('batchRecipientAttributes');
|
||||||
$property->setAccessible(true);
|
$property->setAccessible(true);
|
||||||
$propertyValue = $property->getValue($message);
|
$propertyValue = $property->getValue($message);
|
||||||
$this->assertEquals("Test", $propertyValue['test@samples.mailgun.org']['first']);
|
$this->assertEquals('Test', $propertyValue['test@samples.mailgun.org']['first']);
|
||||||
$this->assertEquals("User", $propertyValue['test@samples.mailgun.org']['last']);
|
$this->assertEquals('User', $propertyValue['test@samples.mailgun.org']['last']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRecipientVariablesOnCc()
|
public function testRecipientVariablesOnCc()
|
||||||
{
|
{
|
||||||
$message = $this->client->BatchMessage($this->sampleDomain);
|
$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();
|
$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));
|
$reflectionClass = new \ReflectionClass(get_class($message));
|
||||||
$property = $reflectionClass->getProperty('batchRecipientAttributes');
|
$property = $reflectionClass->getProperty('batchRecipientAttributes');
|
||||||
$property->setAccessible(true);
|
$property->setAccessible(true);
|
||||||
$propertyValue = $property->getValue($message);
|
$propertyValue = $property->getValue($message);
|
||||||
$this->assertEquals("Test", $propertyValue['test@samples.mailgun.org']['first']);
|
$this->assertEquals('Test', $propertyValue['test@samples.mailgun.org']['first']);
|
||||||
$this->assertEquals("User", $propertyValue['test@samples.mailgun.org']['last']);
|
$this->assertEquals('User', $propertyValue['test@samples.mailgun.org']['last']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRecipientVariablesOnBcc()
|
public function testRecipientVariablesOnBcc()
|
||||||
{
|
{
|
||||||
$message = $this->client->BatchMessage($this->sampleDomain);
|
$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();
|
$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));
|
$reflectionClass = new \ReflectionClass(get_class($message));
|
||||||
$property = $reflectionClass->getProperty('batchRecipientAttributes');
|
$property = $reflectionClass->getProperty('batchRecipientAttributes');
|
||||||
$property->setAccessible(true);
|
$property->setAccessible(true);
|
||||||
$propertyValue = $property->getValue($message);
|
$propertyValue = $property->getValue($message);
|
||||||
$this->assertEquals("Test", $propertyValue['test@samples.mailgun.org']['first']);
|
$this->assertEquals('Test', $propertyValue['test@samples.mailgun.org']['first']);
|
||||||
$this->assertEquals("User", $propertyValue['test@samples.mailgun.org']['last']);
|
$this->assertEquals('User', $propertyValue['test@samples.mailgun.org']['last']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAddMultipleBatchRecipients()
|
public function testAddMultipleBatchRecipients()
|
||||||
{
|
{
|
||||||
$message = $this->client->BatchMessage($this->sampleDomain);
|
$message = $this->client->BatchMessage($this->sampleDomain);
|
||||||
for ($i = 0; $i < 100; $i++) {
|
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();
|
$messageObj = $message->getMessage();
|
||||||
$this->assertEquals(100, count($messageObj["to"]));
|
$this->assertEquals(100, count($messageObj['to']));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMaximumBatchSize()
|
public function testMaximumBatchSize()
|
||||||
{
|
{
|
||||||
$message = $this->client->BatchMessage($this->sampleDomain);
|
$message = $this->client->BatchMessage($this->sampleDomain);
|
||||||
$message->setFromAddress("samples@mailgun.org", array("first" => "Test", "last" => "User"));
|
$message->setFromAddress('samples@mailgun.org', ['first' => 'Test', 'last' => 'User']);
|
||||||
$message->setSubject("This is the subject of the message!");
|
$message->setSubject('This is the subject of the message!');
|
||||||
$message->setTextBody("This is the text body of the message!");
|
$message->setTextBody('This is the text body of the message!');
|
||||||
for ($i = 0; $i < 1001; $i++) {
|
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();
|
$messageObj = $message->getMessage();
|
||||||
$this->assertEquals(1, count($messageObj["to"]));
|
$this->assertEquals(1, count($messageObj['to']));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAttributeResetOnEndBatchMessage()
|
public function testAttributeResetOnEndBatchMessage()
|
||||||
{
|
{
|
||||||
$message = $this->client->BatchMessage($this->sampleDomain);
|
$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']);
|
||||||
$message->setFromAddress("samples@mailgun.org", array("first" => "Test", "last" => "User"));
|
$message->setFromAddress('samples@mailgun.org', ['first' => 'Test', 'last' => 'User']);
|
||||||
$message->setSubject("This is the subject of the message!");
|
$message->setSubject('This is the subject of the message!');
|
||||||
$message->setTextBody("This is the text body of the message!");
|
$message->setTextBody('This is the text body of the message!');
|
||||||
$message->finalize();
|
$message->finalize();
|
||||||
$messageObj = $message->getMessage();
|
$messageObj = $message->getMessage();
|
||||||
$this->assertTrue(true, empty($messageObj));
|
$this->assertTrue(true, empty($messageObj));
|
||||||
@ -117,10 +117,10 @@ class BatchMessageTest extends \Mailgun\Tests\MailgunTestCase
|
|||||||
public function testDefaultIDInVariables()
|
public function testDefaultIDInVariables()
|
||||||
{
|
{
|
||||||
$message = $this->client->BatchMessage($this->sampleDomain);
|
$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));
|
$reflectionClass = new \ReflectionClass(get_class($message));
|
||||||
$property = $reflectionClass->getProperty('batchRecipientAttributes');
|
$property = $reflectionClass->getProperty('batchRecipientAttributes');
|
||||||
$property->setAccessible(true);
|
$property->setAccessible(true);
|
||||||
$propertyValue = $property->getValue($message);
|
$propertyValue = $property->getValue($message);
|
||||||
$this->assertEquals(1, $propertyValue['test-user@samples.mailgun.org']['id']);
|
$this->assertEquals(1, $propertyValue['test-user@samples.mailgun.org']['id']);
|
||||||
@ -129,44 +129,44 @@ class BatchMessageTest extends \Mailgun\Tests\MailgunTestCase
|
|||||||
public function testgetMessageIds()
|
public function testgetMessageIds()
|
||||||
{
|
{
|
||||||
$message = $this->client->BatchMessage($this->sampleDomain);
|
$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']);
|
||||||
$message->setFromAddress("samples@mailgun.org", array("first" => "Test", "last" => "User"));
|
$message->setFromAddress('samples@mailgun.org', ['first' => 'Test', 'last' => 'User']);
|
||||||
$message->setSubject("This is the subject of the message!");
|
$message->setSubject('This is the subject of the message!');
|
||||||
$message->setTextBody("This is the text body of the message!");
|
$message->setTextBody('This is the text body of the message!');
|
||||||
$message->finalize();
|
$message->finalize();
|
||||||
|
|
||||||
$this->assertEquals(array("1234"), $message->getMessageIds());
|
$this->assertEquals(['1234'], $message->getMessageIds());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInvalidMissingRequiredMIMEParametersExceptionGetsFlungNoFrom()
|
public function testInvalidMissingRequiredMIMEParametersExceptionGetsFlungNoFrom()
|
||||||
{
|
{
|
||||||
$this->setExpectedException("\\Mailgun\\Messages\\Exceptions\\MissingRequiredMIMEParameters");
|
$this->setExpectedException('\\Mailgun\\Messages\\Exceptions\\MissingRequiredMIMEParameters');
|
||||||
|
|
||||||
$message = $this->client->BatchMessage($this->sampleDomain);
|
$message = $this->client->BatchMessage($this->sampleDomain);
|
||||||
$message->sendMessage(array(1, 2, 3));
|
$message->sendMessage([1, 2, 3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInvalidMissingRequiredMIMEParametersExceptionGetsFlungNoTo()
|
public function testInvalidMissingRequiredMIMEParametersExceptionGetsFlungNoTo()
|
||||||
{
|
{
|
||||||
$this->setExpectedException("\\Mailgun\\Messages\\Exceptions\\MissingRequiredMIMEParameters");
|
$this->setExpectedException('\\Mailgun\\Messages\\Exceptions\\MissingRequiredMIMEParameters');
|
||||||
|
|
||||||
$message = $this->client->BatchMessage($this->sampleDomain);
|
$message = $this->client->BatchMessage($this->sampleDomain);
|
||||||
$message->sendMessage(array("from" => 1, 2, 3));
|
$message->sendMessage(['from' => 1, 2, 3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInvalidMissingRequiredMIMEParametersExceptionGetsFlungNoSubject()
|
public function testInvalidMissingRequiredMIMEParametersExceptionGetsFlungNoSubject()
|
||||||
{
|
{
|
||||||
$this->setExpectedException("\\Mailgun\\Messages\\Exceptions\\MissingRequiredMIMEParameters");
|
$this->setExpectedException('\\Mailgun\\Messages\\Exceptions\\MissingRequiredMIMEParameters');
|
||||||
|
|
||||||
$message = $this->client->BatchMessage($this->sampleDomain);
|
$message = $this->client->BatchMessage($this->sampleDomain);
|
||||||
$message->sendMessage(array("from" => 1, "to" => 2, 3));
|
$message->sendMessage(['from' => 1, 'to' => 2, 3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInvalidMissingRequiredMIMEParametersExceptionGetsFlungNoTextOrHtml()
|
public function testInvalidMissingRequiredMIMEParametersExceptionGetsFlungNoTextOrHtml()
|
||||||
{
|
{
|
||||||
$this->setExpectedException("\\Mailgun\\Messages\\Exceptions\\MissingRequiredMIMEParameters");
|
$this->setExpectedException('\\Mailgun\\Messages\\Exceptions\\MissingRequiredMIMEParameters');
|
||||||
|
|
||||||
$message = $this->client->BatchMessage($this->sampleDomain);
|
$message = $this->client->BatchMessage($this->sampleDomain);
|
||||||
$message->sendMessage(array("from" => 1, "to" => 2, "subject" => 3));
|
$message->sendMessage(['from' => 1, 'to' => 2, 'subject' => 3]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?PHP
|
<?PHP
|
||||||
|
|
||||||
namespace Mailgun\Tests\Messages;
|
namespace Mailgun\Tests\Messages;
|
||||||
|
|
||||||
use Mailgun\Tests\Mock\Mailgun;
|
use Mailgun\Tests\Mock\Mailgun;
|
||||||
@ -23,7 +24,7 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
|
|||||||
$message = $this->client->MessageBuilder();
|
$message = $this->client->MessageBuilder();
|
||||||
|
|
||||||
$reflectionClass = new \ReflectionClass(get_class($message));
|
$reflectionClass = new \ReflectionClass(get_class($message));
|
||||||
$property = $reflectionClass->getProperty('counters');
|
$property = $reflectionClass->getProperty('counters');
|
||||||
$property->setAccessible(true);
|
$property->setAccessible(true);
|
||||||
$propertyValue = $property->getValue($message);
|
$propertyValue = $property->getValue($message);
|
||||||
$this->assertEquals(0, $propertyValue['recipients']['to']);
|
$this->assertEquals(0, $propertyValue['recipients']['to']);
|
||||||
@ -38,34 +39,34 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
|
|||||||
public function testAddToRecipient()
|
public function testAddToRecipient()
|
||||||
{
|
{
|
||||||
$message = $this->client->MessageBuilder();
|
$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();
|
$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()
|
public function testAddCcRecipient()
|
||||||
{
|
{
|
||||||
$message = $this->client->MessageBuilder();
|
$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();
|
$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()
|
public function testAddBccRecipient()
|
||||||
{
|
{
|
||||||
$message = $this->client->MessageBuilder();
|
$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();
|
$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()
|
public function testToRecipientCount()
|
||||||
{
|
{
|
||||||
$message = $this->client->MessageBuilder();
|
$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));
|
$reflectionClass = new \ReflectionClass(get_class($message));
|
||||||
$property = $reflectionClass->getProperty('counters');
|
$property = $reflectionClass->getProperty('counters');
|
||||||
$property->setAccessible(true);
|
$property->setAccessible(true);
|
||||||
$array = $property->getValue($message);
|
$array = $property->getValue($message);
|
||||||
$this->assertEquals(1, $array['recipients']['to']);
|
$this->assertEquals(1, $array['recipients']['to']);
|
||||||
@ -74,10 +75,10 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
|
|||||||
public function testCcRecipientCount()
|
public function testCcRecipientCount()
|
||||||
{
|
{
|
||||||
$message = $this->client->MessageBuilder();
|
$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));
|
$reflectionClass = new \ReflectionClass(get_class($message));
|
||||||
$property = $reflectionClass->getProperty('counters');
|
$property = $reflectionClass->getProperty('counters');
|
||||||
$property->setAccessible(true);
|
$property->setAccessible(true);
|
||||||
$array = $property->getValue($message);
|
$array = $property->getValue($message);
|
||||||
$this->assertEquals(1, $array['recipients']['cc']);
|
$this->assertEquals(1, $array['recipients']['cc']);
|
||||||
@ -86,10 +87,10 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
|
|||||||
public function testBccRecipientCount()
|
public function testBccRecipientCount()
|
||||||
{
|
{
|
||||||
$message = $this->client->MessageBuilder();
|
$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));
|
$reflectionClass = new \ReflectionClass(get_class($message));
|
||||||
$property = $reflectionClass->getProperty('counters');
|
$property = $reflectionClass->getProperty('counters');
|
||||||
$property->setAccessible(true);
|
$property->setAccessible(true);
|
||||||
$array = $property->getValue($message);
|
$array = $property->getValue($message);
|
||||||
$this->assertEquals(1, $array['recipients']['bcc']);
|
$this->assertEquals(1, $array['recipients']['bcc']);
|
||||||
@ -98,89 +99,89 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
|
|||||||
public function testSetFromAddress()
|
public function testSetFromAddress()
|
||||||
{
|
{
|
||||||
$message = $this->client->MessageBuilder();
|
$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();
|
$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()
|
public function testSetReplyTo()
|
||||||
{
|
{
|
||||||
$message = $this->client->MessageBuilder();
|
$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();
|
$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()
|
public function testSetSubject()
|
||||||
{
|
{
|
||||||
$message = $this->client->MessageBuilder();
|
$message = $this->client->MessageBuilder();
|
||||||
$message->setSubject("Test Subject");
|
$message->setSubject('Test Subject');
|
||||||
$messageObj = $message->getMessage();
|
$messageObj = $message->getMessage();
|
||||||
$this->assertEquals(array("subject" => "Test Subject"), $messageObj);
|
$this->assertEquals(['subject' => 'Test Subject'], $messageObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAddCustomHeader()
|
public function testAddCustomHeader()
|
||||||
{
|
{
|
||||||
$message = $this->client->MessageBuilder();
|
$message = $this->client->MessageBuilder();
|
||||||
$message->addCustomHeader("My-Header", "123");
|
$message->addCustomHeader('My-Header', '123');
|
||||||
$messageObj = $message->getMessage();
|
$messageObj = $message->getMessage();
|
||||||
$this->assertEquals(array("h:My-Header" => array("123")), $messageObj);
|
$this->assertEquals(['h:My-Header' => ['123']], $messageObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetTextBody()
|
public function testSetTextBody()
|
||||||
{
|
{
|
||||||
$message = $this->client->MessageBuilder();
|
$message = $this->client->MessageBuilder();
|
||||||
$message->setTextBody("This is the text body!");
|
$message->setTextBody('This is the text body!');
|
||||||
$messageObj = $message->getMessage();
|
$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()
|
public function testSetHtmlBody()
|
||||||
{
|
{
|
||||||
$message = $this->client->MessageBuilder();
|
$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();
|
$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()
|
public function testAddAttachments()
|
||||||
{
|
{
|
||||||
$message = $this->client->MessageBuilder();
|
$message = $this->client->MessageBuilder();
|
||||||
$message->addAttachment("@../TestAssets/mailgun_icon.png");
|
$message->addAttachment('@../TestAssets/mailgun_icon.png');
|
||||||
$message->addAttachment("@../TestAssets/rackspace_logo.png");
|
$message->addAttachment('@../TestAssets/rackspace_logo.png');
|
||||||
$messageObj = $message->getFiles();
|
$messageObj = $message->getFiles();
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array(
|
[
|
||||||
array(
|
[
|
||||||
'filePath' => "@../TestAssets/mailgun_icon.png",
|
'filePath' => '@../TestAssets/mailgun_icon.png',
|
||||||
'remoteName' => null
|
'remoteName' => null,
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'filePath' => "@../TestAssets/rackspace_logo.png",
|
'filePath' => '@../TestAssets/rackspace_logo.png',
|
||||||
'remoteName' => null
|
'remoteName' => null,
|
||||||
)
|
],
|
||||||
),
|
],
|
||||||
$messageObj["attachment"]
|
$messageObj['attachment']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAddInlineImages()
|
public function testAddInlineImages()
|
||||||
{
|
{
|
||||||
$message = $this->client->MessageBuilder();
|
$message = $this->client->MessageBuilder();
|
||||||
$message->addInlineImage("@../TestAssets/mailgun_icon.png");
|
$message->addInlineImage('@../TestAssets/mailgun_icon.png');
|
||||||
$message->addInlineImage("@../TestAssets/rackspace_logo.png");
|
$message->addInlineImage('@../TestAssets/rackspace_logo.png');
|
||||||
$messageObj = $message->getFiles();
|
$messageObj = $message->getFiles();
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array(
|
[
|
||||||
array(
|
[
|
||||||
'filePath' => "@../TestAssets/mailgun_icon.png",
|
'filePath' => '@../TestAssets/mailgun_icon.png',
|
||||||
'remoteName' => null
|
'remoteName' => null,
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'filePath' => "@../TestAssets/rackspace_logo.png",
|
'filePath' => '@../TestAssets/rackspace_logo.png',
|
||||||
'remoteName' => null
|
'remoteName' => null,
|
||||||
)
|
],
|
||||||
),
|
],
|
||||||
$messageObj['inline']
|
$messageObj['inline']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -192,17 +193,17 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
|
|||||||
$message->addAttachment('@../TestAssets/rackspace_logo.png', 'rs_logo.png');
|
$message->addAttachment('@../TestAssets/rackspace_logo.png', 'rs_logo.png');
|
||||||
$messageObj = $message->getFiles();
|
$messageObj = $message->getFiles();
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array(
|
[
|
||||||
array(
|
[
|
||||||
'filePath' => '@../TestAssets/mailgun_icon.png',
|
'filePath' => '@../TestAssets/mailgun_icon.png',
|
||||||
'remoteName' => 'mg_icon.png'
|
'remoteName' => 'mg_icon.png',
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'filePath' => '@../TestAssets/rackspace_logo.png',
|
'filePath' => '@../TestAssets/rackspace_logo.png',
|
||||||
'remoteName' => 'rs_logo.png'
|
'remoteName' => 'rs_logo.png',
|
||||||
)
|
],
|
||||||
),
|
],
|
||||||
$messageObj["attachment"]
|
$messageObj['attachment']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,16 +214,16 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
|
|||||||
$message->addInlineImage('@../TestAssets/rackspace_logo.png', 'rs_logo.png');
|
$message->addInlineImage('@../TestAssets/rackspace_logo.png', 'rs_logo.png');
|
||||||
$messageObj = $message->getFiles();
|
$messageObj = $message->getFiles();
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array(
|
[
|
||||||
array(
|
[
|
||||||
'filePath' => '@../TestAssets/mailgun_icon.png',
|
'filePath' => '@../TestAssets/mailgun_icon.png',
|
||||||
'remoteName' => 'mg_icon.png'
|
'remoteName' => 'mg_icon.png',
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'filePath' => '@../TestAssets/rackspace_logo.png',
|
'filePath' => '@../TestAssets/rackspace_logo.png',
|
||||||
'remoteName' => 'rs_logo.png'
|
'remoteName' => 'rs_logo.png',
|
||||||
)
|
],
|
||||||
),
|
],
|
||||||
$messageObj['inline']
|
$messageObj['inline']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -232,27 +233,27 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
|
|||||||
$message = $this->client->MessageBuilder();
|
$message = $this->client->MessageBuilder();
|
||||||
$message->setTestMode(true);
|
$message->setTestMode(true);
|
||||||
$messageObj = $message->getMessage();
|
$messageObj = $message->getMessage();
|
||||||
$this->assertEquals(array("o:testmode" => "yes"), $messageObj);
|
$this->assertEquals(['o:testmode' => 'yes'], $messageObj);
|
||||||
$message->setTestMode(false);
|
$message->setTestMode(false);
|
||||||
$messageObj = $message->getMessage();
|
$messageObj = $message->getMessage();
|
||||||
$this->assertEquals(array("o:testmode" => "no"), $messageObj);
|
$this->assertEquals(['o:testmode' => 'no'], $messageObj);
|
||||||
$message->setTestMode("yes");
|
$message->setTestMode('yes');
|
||||||
$messageObj = $message->getMessage();
|
$messageObj = $message->getMessage();
|
||||||
$this->assertEquals(array("o:testmode" => "yes"), $messageObj);
|
$this->assertEquals(['o:testmode' => 'yes'], $messageObj);
|
||||||
$message->setTestMode("no");
|
$message->setTestMode('no');
|
||||||
$messageObj = $message->getMessage();
|
$messageObj = $message->getMessage();
|
||||||
$this->assertEquals(array("o:testmode" => "no"), $messageObj);
|
$this->assertEquals(['o:testmode' => 'no'], $messageObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addCampaignId()
|
public function addCampaignId()
|
||||||
{
|
{
|
||||||
$message = $this->client->MessageBuilder();
|
$message = $this->client->MessageBuilder();
|
||||||
$message->addCampaignId("ABC123");
|
$message->addCampaignId('ABC123');
|
||||||
$message->addCampaignId("XYZ987");
|
$message->addCampaignId('XYZ987');
|
||||||
$message->addCampaignId("TUV456");
|
$message->addCampaignId('TUV456');
|
||||||
$message->addCampaignId("NONO123");
|
$message->addCampaignId('NONO123');
|
||||||
$messageObj = $message->getMessage();
|
$messageObj = $message->getMessage();
|
||||||
$this->assertEquals(array("o:campaign" => array("ABC123", "XYZ987", "TUV456")), $messageObj);
|
$this->assertEquals(['o:campaign' => ['ABC123', 'XYZ987', 'TUV456']], $messageObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetDkim()
|
public function testSetDkim()
|
||||||
@ -260,16 +261,16 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
|
|||||||
$message = $this->client->MessageBuilder();
|
$message = $this->client->MessageBuilder();
|
||||||
$message->setDkim(true);
|
$message->setDkim(true);
|
||||||
$messageObj = $message->getMessage();
|
$messageObj = $message->getMessage();
|
||||||
$this->assertEquals(array("o:dkim" => "yes"), $messageObj);
|
$this->assertEquals(['o:dkim' => 'yes'], $messageObj);
|
||||||
$message->setDkim(false);
|
$message->setDkim(false);
|
||||||
$messageObj = $message->getMessage();
|
$messageObj = $message->getMessage();
|
||||||
$this->assertEquals(array("o:dkim" => "no"), $messageObj);
|
$this->assertEquals(['o:dkim' => 'no'], $messageObj);
|
||||||
$message->setDkim("yes");
|
$message->setDkim('yes');
|
||||||
$messageObj = $message->getMessage();
|
$messageObj = $message->getMessage();
|
||||||
$this->assertEquals(array("o:dkim" => "yes"), $messageObj);
|
$this->assertEquals(['o:dkim' => 'yes'], $messageObj);
|
||||||
$message->setDkim("no");
|
$message->setDkim('no');
|
||||||
$messageObj = $message->getMessage();
|
$messageObj = $message->getMessage();
|
||||||
$this->assertEquals(array("o:dkim" => "no"), $messageObj);
|
$this->assertEquals(['o:dkim' => 'no'], $messageObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetClickTracking()
|
public function testSetClickTracking()
|
||||||
@ -277,16 +278,16 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
|
|||||||
$message = $this->client->MessageBuilder();
|
$message = $this->client->MessageBuilder();
|
||||||
$message->setClickTracking(true);
|
$message->setClickTracking(true);
|
||||||
$messageObj = $message->getMessage();
|
$messageObj = $message->getMessage();
|
||||||
$this->assertEquals(array("o:tracking-clicks" => "yes"), $messageObj);
|
$this->assertEquals(['o:tracking-clicks' => 'yes'], $messageObj);
|
||||||
$message->setClickTracking(false);
|
$message->setClickTracking(false);
|
||||||
$messageObj = $message->getMessage();
|
$messageObj = $message->getMessage();
|
||||||
$this->assertEquals(array("o:tracking-clicks" => "no"), $messageObj);
|
$this->assertEquals(['o:tracking-clicks' => 'no'], $messageObj);
|
||||||
$message->setClickTracking("yes");
|
$message->setClickTracking('yes');
|
||||||
$messageObj = $message->getMessage();
|
$messageObj = $message->getMessage();
|
||||||
$this->assertEquals(array("o:tracking-clicks" => "yes"), $messageObj);
|
$this->assertEquals(['o:tracking-clicks' => 'yes'], $messageObj);
|
||||||
$message->setClickTracking("no");
|
$message->setClickTracking('no');
|
||||||
$messageObj = $message->getMessage();
|
$messageObj = $message->getMessage();
|
||||||
$this->assertEquals(array("o:tracking-clicks" => "no"), $messageObj);
|
$this->assertEquals(['o:tracking-clicks' => 'no'], $messageObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetOpenTracking()
|
public function testSetOpenTracking()
|
||||||
@ -294,33 +295,33 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
|
|||||||
$message = $this->client->MessageBuilder();
|
$message = $this->client->MessageBuilder();
|
||||||
$message->setOpenTracking(true);
|
$message->setOpenTracking(true);
|
||||||
$messageObj = $message->getMessage();
|
$messageObj = $message->getMessage();
|
||||||
$this->assertEquals(array("o:tracking-opens" => "yes"), $messageObj);
|
$this->assertEquals(['o:tracking-opens' => 'yes'], $messageObj);
|
||||||
$message->setOpenTracking(false);
|
$message->setOpenTracking(false);
|
||||||
$messageObj = $message->getMessage();
|
$messageObj = $message->getMessage();
|
||||||
$this->assertEquals(array("o:tracking-opens" => "no"), $messageObj);
|
$this->assertEquals(['o:tracking-opens' => 'no'], $messageObj);
|
||||||
$message->setOpenTracking("yes");
|
$message->setOpenTracking('yes');
|
||||||
$messageObj = $message->getMessage();
|
$messageObj = $message->getMessage();
|
||||||
$this->assertEquals(array("o:tracking-opens" => "yes"), $messageObj);
|
$this->assertEquals(['o:tracking-opens' => 'yes'], $messageObj);
|
||||||
$message->setOpenTracking("no");
|
$message->setOpenTracking('no');
|
||||||
$messageObj = $message->getMessage();
|
$messageObj = $message->getMessage();
|
||||||
$this->assertEquals(array("o:tracking-opens" => "no"), $messageObj);
|
$this->assertEquals(['o:tracking-opens' => 'no'], $messageObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetDeliveryTime()
|
public function testSetDeliveryTime()
|
||||||
{
|
{
|
||||||
$message = $this->client->MessageBuilder();
|
$message = $this->client->MessageBuilder();
|
||||||
$message->setDeliveryTime("January 15, 2014 8:00AM", "CST");
|
$message->setDeliveryTime('January 15, 2014 8:00AM', 'CST');
|
||||||
$messageObj = $message->getMessage();
|
$messageObj = $message->getMessage();
|
||||||
$this->assertEquals(array("o:deliverytime" => "Wed, 15 Jan 2014 08:00:00 -0600"), $messageObj);
|
$this->assertEquals(['o:deliverytime' => 'Wed, 15 Jan 2014 08:00:00 -0600'], $messageObj);
|
||||||
$message->setDeliveryTime("January 15, 2014 8:00AM", "UTC");
|
$message->setDeliveryTime('January 15, 2014 8:00AM', 'UTC');
|
||||||
$messageObj = $message->getMessage();
|
$messageObj = $message->getMessage();
|
||||||
$this->assertEquals(array("o:deliverytime" => "Wed, 15 Jan 2014 08:00:00 +0000"), $messageObj);
|
$this->assertEquals(['o:deliverytime' => 'Wed, 15 Jan 2014 08:00:00 +0000'], $messageObj);
|
||||||
$message->setDeliveryTime("January 15, 2014 8:00AM");
|
$message->setDeliveryTime('January 15, 2014 8:00AM');
|
||||||
$messageObj = $message->getMessage();
|
$messageObj = $message->getMessage();
|
||||||
$this->assertEquals(array("o:deliverytime" => "Wed, 15 Jan 2014 08:00:00 +0000"), $messageObj);
|
$this->assertEquals(['o:deliverytime' => 'Wed, 15 Jan 2014 08:00:00 +0000'], $messageObj);
|
||||||
$message->setDeliveryTime("1/15/2014 13:50:01", "CDT");
|
$message->setDeliveryTime('1/15/2014 13:50:01', 'CDT');
|
||||||
$messageObj = $message->getMessage();
|
$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/pull/42
|
||||||
// https://github.com/mailgun/mailgun-php/issues/43
|
// https://github.com/mailgun/mailgun-php/issues/43
|
||||||
//$message->setDeliveryTime("first saturday of July 2013 8:00AM", "CDT");
|
//$message->setDeliveryTime("first saturday of July 2013 8:00AM", "CDT");
|
||||||
@ -331,23 +332,23 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
|
|||||||
public function testAddCustomData()
|
public function testAddCustomData()
|
||||||
{
|
{
|
||||||
$message = $this->client->MessageBuilder();
|
$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();
|
$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()
|
public function testAddCustomParameter()
|
||||||
{
|
{
|
||||||
$message = $this->client->MessageBuilder();
|
$message = $this->client->MessageBuilder();
|
||||||
$message->addCustomParameter("my-option", "yes");
|
$message->addCustomParameter('my-option', 'yes');
|
||||||
$message->addCustomParameter("o:my-other-option", "no");
|
$message->addCustomParameter('o:my-other-option', 'no');
|
||||||
$messageObj = $message->getMessage();
|
$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()
|
public function testSetMessage()
|
||||||
{
|
{
|
||||||
$message = array(1, 2, 3, 4, 5);
|
$message = [1, 2, 3, 4, 5];
|
||||||
$messageBuilder = $this->client->MessageBuilder();
|
$messageBuilder = $this->client->MessageBuilder();
|
||||||
$messageBuilder->setMessage($message);
|
$messageBuilder->setMessage($message);
|
||||||
|
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
<?PHP
|
<?PHP
|
||||||
|
|
||||||
namespace Mailgun\Tests\Messages;
|
namespace Mailgun\Tests\Messages;
|
||||||
|
|
||||||
use Mailgun\Tests\Mock\Mailgun;
|
use Mailgun\Tests\Mock\Mailgun;
|
||||||
|
|
||||||
class StandardMessageTest extends \Mailgun\Tests\MailgunTestCase
|
class StandardMessageTest extends \Mailgun\Tests\MailgunTestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
private $client;
|
private $client;
|
||||||
private $sampleDomain = "samples.mailgun.org";
|
private $sampleDomain = 'samples.mailgun.org';
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->client = new Mailgun("My-Super-Awesome-API-Key");
|
$this->client = new Mailgun('My-Super-Awesome-API-Key');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSendMIMEMessage()
|
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
|
Mime-Version: 1.0
|
||||||
Content-Type: text/plain; charset=\"ascii\"
|
Content-Type: text/plain; charset="ascii"
|
||||||
Subject: This is the Subject!
|
Subject: This is the Subject!
|
||||||
From: Mailgun Testing <test@test.mailgun.com>
|
From: Mailgun Testing <test@test.mailgun.com>
|
||||||
To: 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
|
Date: Mon, 10 Jun 2013 09:50:58 +0000
|
||||||
Sender: test@test.mailgun.com
|
Sender: test@test.mailgun.com
|
||||||
|
|
||||||
Mailgun is testing!";
|
Mailgun is testing!';
|
||||||
$envelopeFields = array('to' => 'test@test.mailgun.org');
|
$envelopeFields = ['to' => 'test@test.mailgun.org'];
|
||||||
$result = $this->client->sendMessage("test.mailgun.org", $envelopeFields, $customMime);
|
$result = $this->client->sendMessage('test.mailgun.org', $envelopeFields, $customMime);
|
||||||
$this->assertEquals("test.mailgun.org/messages.mime", $result->http_endpoint_url);
|
$this->assertEquals('test.mailgun.org/messages.mime', $result->http_endpoint_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSendMessage()
|
public function testSendMessage()
|
||||||
{
|
{
|
||||||
$message = array('to' => 'test@test.mailgun.org',
|
$message = ['to' => 'test@test.mailgun.org',
|
||||||
'from' => 'sender@test.mailgun.org',
|
'from' => 'sender@test.mailgun.org',
|
||||||
'subject' => 'This is my test subject',
|
'subject' => 'This is my test subject',
|
||||||
'text' => 'Testing!'
|
'text' => 'Testing!',
|
||||||
);
|
];
|
||||||
$result = $this->client->sendMessage("test.mailgun.org", $message);
|
$result = $this->client->sendMessage('test.mailgun.org', $message);
|
||||||
$this->assertEquals("test.mailgun.org/messages", $result->http_endpoint_url);
|
$this->assertEquals('test.mailgun.org/messages', $result->http_endpoint_url);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Mailgun\Tests\Mock\Connection;
|
namespace Mailgun\Tests\Mock\Connection;
|
||||||
|
|
||||||
use Mailgun\Connection\Exceptions\GenericHTTPError;
|
use Mailgun\Connection\Exceptions\GenericHTTPError;
|
||||||
@ -13,18 +14,18 @@ class TestBroker extends RestClient
|
|||||||
|
|
||||||
protected $apiEndpoint;
|
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;
|
$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);
|
return $this->testResponseHandler($endpointUrl, $httpResponseCode = 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get($endpointUrl, $queryString = array())
|
public function get($endpointUrl, $queryString = [])
|
||||||
{
|
{
|
||||||
return $this->testResponseHandler($endpointUrl, $httpResponseCode = 200);
|
return $this->testResponseHandler($endpointUrl, $httpResponseCode = 200);
|
||||||
}
|
}
|
||||||
@ -42,9 +43,9 @@ class TestBroker extends RestClient
|
|||||||
public function testResponseHandler($endpointUrl, $httpResponseCode = 200)
|
public function testResponseHandler($endpointUrl, $httpResponseCode = 200)
|
||||||
{
|
{
|
||||||
if ($httpResponseCode === 200) {
|
if ($httpResponseCode === 200) {
|
||||||
$result = new \stdClass();
|
$result = new \stdClass();
|
||||||
$result->http_response_body = 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) {
|
foreach ($jsonResponseData as $key => $value) {
|
||||||
$result->http_response_body->$key = $value;
|
$result->http_response_body->$key = $value;
|
||||||
}
|
}
|
||||||
@ -62,10 +63,8 @@ class TestBroker extends RestClient
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$result->http_response_code = $httpResponseCode;
|
$result->http_response_code = $httpResponseCode;
|
||||||
$result->http_endpoint_url = $endpointUrl;
|
$result->http_endpoint_url = $endpointUrl;
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ class Mailgun extends Base
|
|||||||
protected $debug;
|
protected $debug;
|
||||||
protected $restClient;
|
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);
|
$this->restClient = new TestBroker($apiKey, $apiEndpoint, $apiVersion);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user