summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornornholdj <nornholdj@gmail.com>2014-11-03 15:37:21 -0500
committernornholdj <nornholdj@gmail.com>2014-11-03 15:37:21 -0500
commit1d6fad1db52c968f7cb8f6a93d3c84ae1f2b2dd8 (patch)
treedb74b901de1e6aeed20263d69cd70e2d4506059b
parent9e9b7ac550ab663b393e757483bd78858d96686d (diff)
downloadphp-sparkpost-1d6fad1db52c968f7cb8f6a93d3c84ae1f2b2dd8.zip
php-sparkpost-1d6fad1db52c968f7cb8f6a93d3c84ae1f2b2dd8.tar.gz
php-sparkpost-1d6fad1db52c968f7cb8f6a93d3c84ae1f2b2dd8.tar.bz2
MA-946 #time 1h reviewed and updated function docs and other comments
-rw-r--r--RoboFile.php2
-rw-r--r--lib/MessageSystems/Transmission.php37
-rw-r--r--test/unit/SparkPostTest.php5
-rw-r--r--test/unit/TransmissionTest.php31
4 files changed, 62 insertions, 13 deletions
diff --git a/RoboFile.php b/RoboFile.php
index 571da64..9245e1b 100644
--- a/RoboFile.php
+++ b/RoboFile.php
@@ -14,4 +14,4 @@ class RoboFile extends \Robo\Tasks
return $res();
}
-} \ No newline at end of file
+}
diff --git a/lib/MessageSystems/Transmission.php b/lib/MessageSystems/Transmission.php
index 71b54a0..e820cff 100644
--- a/lib/MessageSystems/Transmission.php
+++ b/lib/MessageSystems/Transmission.php
@@ -7,8 +7,16 @@ use GuzzleHttp\Exception\RequestException;
* @desc SDK interface for managing transmissions
*/
class Transmission {
+ /**
+ * @desc singleton holder to create a guzzle http client
+ * @var \GuzzleHttp\Client
+ */
private static $request;
+ /**
+ * @desc Mapping for values passed into the send method to the values needed for the Transmission API
+ * @var array
+ */
private static $parameterMappings = [
'campaign'=>'campaign_id',
'metadata'=>'metadata',
@@ -30,6 +38,10 @@ class Transmission {
'useDraftTemplate'=>'use_draft_template'
];
+ /**
+ * @desc Sets up default structure and default values for the model that is acceptable by the API
+ * @var array
+ */
private static $structure = [
'return_path'=>"default@sparkpostmail.com",
'content'=>[
@@ -49,6 +61,10 @@ class Transmission {
*/
private function __construct() {}
+ /**
+ * @desc Creates and returns a guzzle http client.
+ * @return \GuzzleHttp\Client
+ */
private static function getHttpClient() {
if(!isset(self::$request)) {
self::$request = new Client();
@@ -86,8 +102,25 @@ class Transmission {
* @desc Method for issuing POST request to the Transmissions API
*
* This method assumes that all the appropriate fields have
- * been populated by the user through configuration or calling
- * helper methods
+ * been populated by the user through configuration. Acceptable
+ * configuration values are:
+ * 'campaign': string,
+ * 'metadata': array,
+ * 'substitutionData': array,
+ * 'description': string,
+ * 'replyTo': string,
+ * 'subject': string,
+ * 'from': string,
+ * 'html': string,
+ * 'text': string,
+ * 'rfc822Part': string,
+ * 'headers': array,
+ * 'recipients': array,
+ * 'recipientList': string,
+ * 'template': string,
+ * 'openTracking': boolean,
+ * 'clickTracking': boolean,
+ * 'useDraftTemplate': boolean
*
* @return array API repsonse represented as key-value pairs
*/
diff --git a/test/unit/SparkPostTest.php b/test/unit/SparkPostTest.php
index 218cb6e..b019a15 100644
--- a/test/unit/SparkPostTest.php
+++ b/test/unit/SparkPostTest.php
@@ -7,6 +7,7 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase {
/**
* @desc Ensures that the configuration class is not instantiable.
+ * @covers SparkPost::__construct
*/
public function testConstructorCannotBeCalled() {
$class = new \ReflectionClass('\MessageSystems\SparkPost');
@@ -16,6 +17,7 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase {
/**
* @desc Tests that an exception is thrown when a library tries to recieve the config and it has not yet been set.
* Since its a singleton this test must come before any setConfig tests.
+ * @covers SparkPost::getConfig
* @expectedException Exception
* @expectedExceptionMessage No configuration has been provided
*/
@@ -25,6 +27,7 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase {
/**
* @desc Tests that the api key is set when setting the config
+ * @covers SparkPost::setConfig
* @expectedException Exception
* @expectedExceptionMessage You must provide an API key
*/
@@ -34,6 +37,7 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase {
/**
* @desc Tests that the api key is set when setting the config and that its not empty
+ * @covers SparkPost::setConfig
* @expectedException Exception
* @expectedExceptionMessage You must provide an API key
*/
@@ -43,6 +47,7 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase {
/**
* @desc Tests overridable values are set while invalid values are ignored
+ * @covers SparkPost::setConfig
*/
public function testSetConfigMultipleValuesAndGetConfig() {
SparkPost::setConfig(['key'=>'lala', 'version'=>'v8', 'port'=>1024, 'someOtherValue'=>'fakeValue']);
diff --git a/test/unit/TransmissionTest.php b/test/unit/TransmissionTest.php
index 8da2645..0e71ddf 100644
--- a/test/unit/TransmissionTest.php
+++ b/test/unit/TransmissionTest.php
@@ -8,14 +8,18 @@ use GuzzleHttp\Message\Response;
use GuzzleHttp\Stream\Stream;
-/**
- *
- *
- */
class TransmissionTest extends \PHPUnit_Framework_TestCase {
private $client = null;
+ /**
+ * Allows access to private methods in the Transmission class
+ *
+ * This is needed to mock the GuzzleHttp\Client responses
+ *
+ * @param string $name
+ * @return ReflectionMethod
+ */
private static function getMethod($name) {
$class = new \ReflectionClass('\MessageSystems\Transmission');
$method = $class->getMethod($name);
@@ -35,6 +39,7 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase {
/**
* @desc Ensures that the configuration class is not instantiable.
+ * @covers Transmission::__construct
*/
public function testConstructorCannotBeCalled() {
$class = new \ReflectionClass('\MessageSystems\Transmission');
@@ -42,7 +47,8 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase {
}
/**
- *
+ * @desc tests happy path
+ * @covers Transmission::all
*/
public function testAllWithGoodResponse() {
$mock = new Mock([new Response(200, [], Stream::factory('{"results":[{"test":"This is a test"}, {"test":"two"}]}'))]);
@@ -52,7 +58,8 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase {
}
/**
- *
+ * @desc tests happy path
+ * @covers Transmission::find
*/
public function testFindWithGoodResponse() {
$mock = new Mock([new Response(200, [], Stream::factory('{"results":[{"test":"This is a test"}]}'))]);
@@ -62,7 +69,8 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase {
}
/**
- *
+ * @desc tests 404 bad response
+ * @covers Transmission::find
*/
public function testFindWith404Response() {
$mock = new Mock([new Response(404, [])]);
@@ -77,7 +85,8 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase {
}
/**
- *
+ * @desc tests unknown bad response
+ * @covers Transmission::find
*/
public function testFindWithOtherBadResponse() {
$mock = new Mock([new Response(400, [])]);
@@ -92,7 +101,8 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase {
}
/**
- *
+ * @desc tests happy path
+ * @covers Transmission::send
*/
public function testSuccessfulSend() {
$body = ["result"=>["transmission_id"=> "11668787484950529"], "status"=>["message"=> "ok","code"=> "1000"]];
@@ -103,7 +113,8 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase {
}
/**
- *
+ * @desc tests bad response
+ * @covers Transmission::send
*/
public function testSendForRequestException() {
$body = ['errors'=>['This is a fake error']];