summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authornornholdj <nornholdj@gmail.com>2014-11-14 11:22:53 -0500
committernornholdj <nornholdj@gmail.com>2014-11-14 11:22:53 -0500
commit1124aaa608082609fdc6e451de24cc6781706eef (patch)
tree4a6483fe5ff78d9aa4f9b3f609d889025a84f3b3 /test
parentd3eeaebd1d4d5d6db1428c2b9b3cc35fdf71ef4a (diff)
downloadphp-sparkpost-1124aaa608082609fdc6e451de24cc6781706eef.zip
php-sparkpost-1124aaa608082609fdc6e451de24cc6781706eef.tar.gz
php-sparkpost-1124aaa608082609fdc6e451de24cc6781706eef.tar.bz2
MA-1084 #time 1h Implemented better exception handling and added unit
tests for said exception handling
Diffstat (limited to 'test')
-rw-r--r--test/unit/SendGridCompatibiility/EmailTest.php8
-rw-r--r--test/unit/TransmissionTest.php27
2 files changed, 31 insertions, 4 deletions
diff --git a/test/unit/SendGridCompatibiility/EmailTest.php b/test/unit/SendGridCompatibiility/EmailTest.php
index 26e5108..6679745 100644
--- a/test/unit/SendGridCompatibiility/EmailTest.php
+++ b/test/unit/SendGridCompatibiility/EmailTest.php
@@ -96,11 +96,13 @@ class SendGridCompatibilityEmailTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals($value, $this->email->model['html']);
}
+ /**
+ * @desc test that adding a category throws an exception since we don't support tags at transmission level yet
+ * @expectedException Exception
+ * @expectedExceptionMessage Adding categories is not yet supported
+ */
public function testAddCategory() {
- $value = 'Category A';
$this->email->addCategory($value);
-
- $this->assertEquals(array($value), $this->email->model['tags']);
}
/**
diff --git a/test/unit/TransmissionTest.php b/test/unit/TransmissionTest.php
index cf4eda5..de72f2a 100644
--- a/test/unit/TransmissionTest.php
+++ b/test/unit/TransmissionTest.php
@@ -90,6 +90,18 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase {
}
/**
+ * @desc tests bad response
+ * @expectedException Exception
+ * @expectedExceptionMessageRegExp /Unable to contact Transmissions API:.* /
+ */
+ public function testFindForCatchAllException() {
+ $mock = new MockPlugin();
+ $mock->addResponse(new Response(500));
+ $this->client->addSubscriber($mock);
+ Transmission::find('someId');
+ }
+
+ /**
* @desc tests happy path
*/
public function testSuccessfulSend() {
@@ -107,7 +119,7 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase {
* @expectedException Exception
* @expectedExceptionMessage ["This is a fake error"]
*/
- public function testSendForRequestException() {
+ public function testSendFor400Exception() {
$body = array('errors'=>array('This is a fake error'));
$mock = new MockPlugin();
$mock->addResponse(new Response(400, array(), json_encode($body)));
@@ -115,5 +127,18 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase {
Transmission::send(array('text'=>'awesome email'));
}
+
+ /**
+ * @desc tests bad response
+ * @expectedException Exception
+ * @expectedExceptionMessageRegExp /Unable to contact Transmissions API:.* /
+ */
+ public function testSendForCatchAllException() {
+ $mock = new MockPlugin();
+ $mock->addResponse(new Response(500));
+ $this->client->addSubscriber($mock);
+ Transmission::send(array('text'=>'awesome email'));
+ }
+
}
?> \ No newline at end of file