added mailgun librarie
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
<?PHP
|
||||
namespace Mailgun\Tests\Connection;
|
||||
|
||||
use Mailgun\Tests\Mock\Mailgun;
|
||||
|
||||
class ConnectionTest extends \Mailgun\Tests\MailgunTestCase
|
||||
{
|
||||
|
||||
private $client;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
public function testNewClientInstantiation()
|
||||
{
|
||||
$this->client = new Mailgun("My-Super-Awesome-API-Key", "samples.mailgun.org", false);
|
||||
}
|
||||
}
|
@@ -16,21 +16,21 @@ class MailgunTest extends \Mailgun\Tests\MailgunTestCase
|
||||
|
||||
public function testVerifyWebhookGood() {
|
||||
$client = new Mailgun('key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
|
||||
$postData = array(
|
||||
$postData = [
|
||||
'timestamp' => '1403645220',
|
||||
'token' => '5egbgr1vjgqxtrnp65xfznchgdccwh5d6i09vijqi3whgowmn6',
|
||||
'signature' => '9cfc5c41582e51246e73c88d34db3af0a3a2692a76fbab81492842f000256d33',
|
||||
);
|
||||
];
|
||||
assert($client->verifyWebhookSignature($postData));
|
||||
}
|
||||
|
||||
public function testVerifyWebhookBad() {
|
||||
$client = new Mailgun('key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
|
||||
$postData = array(
|
||||
$postData = [
|
||||
'timestamp' => '1403645220',
|
||||
'token' => 'owyldpe6nxhmrn78epljl6bj0orrki1u3d2v5e6cnlmmuox8jr',
|
||||
'signature' => '9cfc5c41582e51246e73c88d34db3af0a3a2692a76fbab81492842f000256d33',
|
||||
);
|
||||
];
|
||||
assert(!$client->verifyWebhookSignature($postData));
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Mailgun\Tests;
|
||||
|
||||
abstract class MailgunTestCase extends \PHPUnit_Framework_TestCase
|
||||
use Guzzle\Tests\GuzzleTestCase;
|
||||
|
||||
abstract class MailgunTestCase extends GuzzleTestCase
|
||||
{
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->client = new Mailgun();
|
||||
$this->client = new Mailgun("My-Super-Awesome-API-Key", "samples.mailgun.org", false);
|
||||
}
|
||||
|
||||
public function testBlankInstantiation()
|
||||
|
@@ -1,11 +1,7 @@
|
||||
<?php
|
||||
namespace Mailgun\Tests\Mock\Connection;
|
||||
|
||||
use Mailgun\Connection\Exceptions\GenericHTTPError;
|
||||
use Mailgun\Connection\Exceptions\InvalidCredentials;
|
||||
use Mailgun\Connection\Exceptions\MissingEndpoint;
|
||||
use Mailgun\Connection\RestClient;
|
||||
use Mailgun\Messages\Exceptions\MissingRequiredMIMEParameters;
|
||||
|
||||
class TestBroker extends RestClient
|
||||
{
|
||||
@@ -13,33 +9,33 @@ class TestBroker extends RestClient
|
||||
|
||||
protected $apiEndpoint;
|
||||
|
||||
public function __construct($apiKey = null, $apiHost = "api.mailgun.net", $apiVersion = "v3")
|
||||
public function __construct($apiKey = null, $apiEndpoint = "api.mailgun.net", $apiVersion = "v2")
|
||||
{
|
||||
$this->apiKey = $apiKey;
|
||||
$this->apiEndpoint = $apiHost;
|
||||
$this->apiEndpoint = $apiEndpoint;
|
||||
}
|
||||
|
||||
public function post($endpointUrl, $postData = array(), $files = array())
|
||||
{
|
||||
return $this->testResponseHandler($endpointUrl, $httpResponseCode = 200);
|
||||
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
|
||||
}
|
||||
|
||||
public function get($endpointUrl, $queryString = array())
|
||||
{
|
||||
return $this->testResponseHandler($endpointUrl, $httpResponseCode = 200);
|
||||
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
|
||||
}
|
||||
|
||||
public function delete($endpointUrl)
|
||||
{
|
||||
return $this->testResponseHandler($endpointUrl, $httpResponseCode = 200);
|
||||
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
|
||||
}
|
||||
|
||||
public function put($endpointUrl, $queryString)
|
||||
{
|
||||
return $this->testResponseHandler($endpointUrl, $httpResponseCode = 200);
|
||||
return $this->responseHandler($endpointUrl, $httpResponseCode = 200);
|
||||
}
|
||||
|
||||
public function testResponseHandler($endpointUrl, $httpResponseCode = 200)
|
||||
public function responseHandler($endpointUrl, $httpResponseCode = 200)
|
||||
{
|
||||
if ($httpResponseCode === 200) {
|
||||
$result = new \stdClass();
|
||||
@@ -48,13 +44,13 @@ class TestBroker extends RestClient
|
||||
foreach ($jsonResponseData as $key => $value) {
|
||||
$result->http_response_body->$key = $value;
|
||||
}
|
||||
} elseif ($httpResponseCode == 400) {
|
||||
} elseif ($httpStatusCode == 400) {
|
||||
throw new MissingRequiredMIMEParameters(EXCEPTION_MISSING_REQUIRED_MIME_PARAMETERS);
|
||||
} elseif ($httpResponseCode == 401) {
|
||||
} elseif ($httpStatusCode == 401) {
|
||||
throw new InvalidCredentials(EXCEPTION_INVALID_CREDENTIALS);
|
||||
} elseif ($httpResponseCode == 401) {
|
||||
} elseif ($httpStatusCode == 401) {
|
||||
throw new GenericHTTPError(EXCEPTION_INVALID_CREDENTIALS);
|
||||
} elseif ($httpResponseCode == 404) {
|
||||
} elseif ($httpStatusCode == 404) {
|
||||
throw new MissingEndpoint(EXCEPTION_MISSING_ENDPOINT);
|
||||
} else {
|
||||
throw new GenericHTTPError(EXCEPTION_GENERIC_HTTP_ERROR);
|
||||
|
@@ -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 = "v2")
|
||||
{
|
||||
$this->restClient = new TestBroker($apiKey, $apiEndpoint, $apiVersion);
|
||||
}
|
||||
|
Reference in New Issue
Block a user