Skip to content

Commit 1d6fad1

Browse files
committed
MA-946 #time 1h reviewed and updated function docs and other comments
1 parent 9e9b7ac commit 1d6fad1

File tree

4 files changed

+62
-13
lines changed

4 files changed

+62
-13
lines changed

RoboFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ public function test () {
1414

1515
return $res();
1616
}
17-
}
17+
}

lib/MessageSystems/Transmission.php

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,16 @@
77
* @desc SDK interface for managing transmissions
88
*/
99
class Transmission {
10+
/**
11+
* @desc singleton holder to create a guzzle http client
12+
* @var \GuzzleHttp\Client
13+
*/
1014
private static $request;
1115

16+
/**
17+
* @desc Mapping for values passed into the send method to the values needed for the Transmission API
18+
* @var array
19+
*/
1220
private static $parameterMappings = [
1321
'campaign'=>'campaign_id',
1422
'metadata'=>'metadata',
@@ -30,6 +38,10 @@ class Transmission {
3038
'useDraftTemplate'=>'use_draft_template'
3139
];
3240

41+
/**
42+
* @desc Sets up default structure and default values for the model that is acceptable by the API
43+
* @var array
44+
*/
3345
private static $structure = [
3446
'return_path'=>"default@sparkpostmail.com",
3547
'content'=>[
@@ -49,6 +61,10 @@ class Transmission {
4961
*/
5062
private function __construct() {}
5163

64+
/**
65+
* @desc Creates and returns a guzzle http client.
66+
* @return \GuzzleHttp\Client
67+
*/
5268
private static function getHttpClient() {
5369
if(!isset(self::$request)) {
5470
self::$request = new Client();
@@ -86,8 +102,25 @@ private static function getBaseUrl($config) {
86102
* @desc Method for issuing POST request to the Transmissions API
87103
*
88104
* This method assumes that all the appropriate fields have
89-
* been populated by the user through configuration or calling
90-
* helper methods
105+
* been populated by the user through configuration. Acceptable
106+
* configuration values are:
107+
* 'campaign': string,
108+
* 'metadata': array,
109+
* 'substitutionData': array,
110+
* 'description': string,
111+
* 'replyTo': string,
112+
* 'subject': string,
113+
* 'from': string,
114+
* 'html': string,
115+
* 'text': string,
116+
* 'rfc822Part': string,
117+
* 'headers': array,
118+
* 'recipients': array,
119+
* 'recipientList': string,
120+
* 'template': string,
121+
* 'openTracking': boolean,
122+
* 'clickTracking': boolean,
123+
* 'useDraftTemplate': boolean
91124
*
92125
* @return array API repsonse represented as key-value pairs
93126
*/

test/unit/SparkPostTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase {
77

88
/**
99
* @desc Ensures that the configuration class is not instantiable.
10+
* @covers SparkPost::__construct
1011
*/
1112
public function testConstructorCannotBeCalled() {
1213
$class = new \ReflectionClass('\MessageSystems\SparkPost');
@@ -16,6 +17,7 @@ public function testConstructorCannotBeCalled() {
1617
/**
1718
* @desc Tests that an exception is thrown when a library tries to recieve the config and it has not yet been set.
1819
* Since its a singleton this test must come before any setConfig tests.
20+
* @covers SparkPost::getConfig
1921
* @expectedException Exception
2022
* @expectedExceptionMessage No configuration has been provided
2123
*/
@@ -25,6 +27,7 @@ public function testGetConfigEmptyException() {
2527

2628
/**
2729
* @desc Tests that the api key is set when setting the config
30+
* @covers SparkPost::setConfig
2831
* @expectedException Exception
2932
* @expectedExceptionMessage You must provide an API key
3033
*/
@@ -34,6 +37,7 @@ public function testSetConfigAPIKeyNotSetException() {
3437

3538
/**
3639
* @desc Tests that the api key is set when setting the config and that its not empty
40+
* @covers SparkPost::setConfig
3741
* @expectedException Exception
3842
* @expectedExceptionMessage You must provide an API key
3943
*/
@@ -43,6 +47,7 @@ public function testSetConfigAPIKeyEmptyException() {
4347

4448
/**
4549
* @desc Tests overridable values are set while invalid values are ignored
50+
* @covers SparkPost::setConfig
4651
*/
4752
public function testSetConfigMultipleValuesAndGetConfig() {
4853
SparkPost::setConfig(['key'=>'lala', 'version'=>'v8', 'port'=>1024, 'someOtherValue'=>'fakeValue']);

test/unit/TransmissionTest.php

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@
88
use GuzzleHttp\Stream\Stream;
99

1010

11-
/**
12-
*
13-
*
14-
*/
1511
class TransmissionTest extends \PHPUnit_Framework_TestCase {
1612

1713
private $client = null;
1814

15+
/**
16+
* Allows access to private methods in the Transmission class
17+
*
18+
* This is needed to mock the GuzzleHttp\Client responses
19+
*
20+
* @param string $name
21+
* @return ReflectionMethod
22+
*/
1923
private static function getMethod($name) {
2024
$class = new \ReflectionClass('\MessageSystems\Transmission');
2125
$method = $class->getMethod($name);
@@ -35,14 +39,16 @@ public function setUp() {
3539

3640
/**
3741
* @desc Ensures that the configuration class is not instantiable.
42+
* @covers Transmission::__construct
3843
*/
3944
public function testConstructorCannotBeCalled() {
4045
$class = new \ReflectionClass('\MessageSystems\Transmission');
4146
$this->assertFalse($class->isInstantiable());
4247
}
4348

4449
/**
45-
*
50+
* @desc tests happy path
51+
* @covers Transmission::all
4652
*/
4753
public function testAllWithGoodResponse() {
4854
$mock = new Mock([new Response(200, [], Stream::factory('{"results":[{"test":"This is a test"}, {"test":"two"}]}'))]);
@@ -52,7 +58,8 @@ public function testAllWithGoodResponse() {
5258
}
5359

5460
/**
55-
*
61+
* @desc tests happy path
62+
* @covers Transmission::find
5663
*/
5764
public function testFindWithGoodResponse() {
5865
$mock = new Mock([new Response(200, [], Stream::factory('{"results":[{"test":"This is a test"}]}'))]);
@@ -62,7 +69,8 @@ public function testFindWithGoodResponse() {
6269
}
6370

6471
/**
65-
*
72+
* @desc tests 404 bad response
73+
* @covers Transmission::find
6674
*/
6775
public function testFindWith404Response() {
6876
$mock = new Mock([new Response(404, [])]);
@@ -77,7 +85,8 @@ public function testFindWith404Response() {
7785
}
7886

7987
/**
80-
*
88+
* @desc tests unknown bad response
89+
* @covers Transmission::find
8190
*/
8291
public function testFindWithOtherBadResponse() {
8392
$mock = new Mock([new Response(400, [])]);
@@ -92,7 +101,8 @@ public function testFindWithOtherBadResponse() {
92101
}
93102

94103
/**
95-
*
104+
* @desc tests happy path
105+
* @covers Transmission::send
96106
*/
97107
public function testSuccessfulSend() {
98108
$body = ["result"=>["transmission_id"=> "11668787484950529"], "status"=>["message"=> "ok","code"=> "1000"]];
@@ -103,7 +113,8 @@ public function testSuccessfulSend() {
103113
}
104114

105115
/**
106-
*
116+
* @desc tests bad response
117+
* @covers Transmission::send
107118
*/
108119
public function testSendForRequestException() {
109120
$body = ['errors'=>['This is a fake error']];

0 commit comments

Comments
 (0)