summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/unit/SendGridCompatibiility/EmailTest.php10
-rw-r--r--test/unit/SendGridCompatibiility/SendGridTest.php3
-rw-r--r--test/unit/TransmissionTest.php71
3 files changed, 37 insertions, 47 deletions
diff --git a/test/unit/SendGridCompatibiility/EmailTest.php b/test/unit/SendGridCompatibiility/EmailTest.php
index dbabb77..bc34402 100644
--- a/test/unit/SendGridCompatibiility/EmailTest.php
+++ b/test/unit/SendGridCompatibiility/EmailTest.php
@@ -68,12 +68,12 @@ class SendGridCompatibilityEmailTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals('test@email.com', $this->email->model['replyTo']);
}
-
-
+ /**
+ * @expectedException Exception
+ * @expectedExceptionMessage Adding bcc recipients is not yet supported, try adding them as a "to" address
+ */
public function testAddBcc() {
$this->email->addBcc('test@email.com');
-
- $this->assertEquals(array('test@email.com'), $this->email->model['bcc']);
}
public function testSetSubject() {
@@ -140,7 +140,7 @@ class SendGridCompatibilityEmailTest extends \PHPUnit_Framework_TestCase {
* @expectedExceptionMessage Setting Unique Arguments is not yet supported
*/
public function testSetUniqueArgs() {
- $this->email->setUniqueArgs(['blah', 'andBlah']);
+ $this->email->setUniqueArgs(array('blah', 'andBlah'));
}
diff --git a/test/unit/SendGridCompatibiility/SendGridTest.php b/test/unit/SendGridCompatibiility/SendGridTest.php
deleted file mode 100644
index 15c5adc..0000000
--- a/test/unit/SendGridCompatibiility/SendGridTest.php
+++ /dev/null
@@ -1,3 +0,0 @@
-<?php
-
-?> \ No newline at end of file
diff --git a/test/unit/TransmissionTest.php b/test/unit/TransmissionTest.php
index 2945bc6..cf4eda5 100644
--- a/test/unit/TransmissionTest.php
+++ b/test/unit/TransmissionTest.php
@@ -3,9 +3,8 @@ namespace SparkPost\Test;
use SparkPost\Transmission;
use SparkPost\SparkPost;
-use GuzzleHttp\Subscriber\Mock;
-use GuzzleHttp\Message\Response;
-use GuzzleHttp\Stream\Stream;
+use Guzzle\Plugin\Mock\MockPlugin;
+use Guzzle\Http\Message\Response;
class TransmissionTest extends \PHPUnit_Framework_TestCase {
@@ -49,50 +48,45 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase {
* @desc tests happy path
*/
public function testAllWithGoodResponse() {
- $mock = new Mock(array(new Response(200, array(), Stream::factory('{"results":[{"test":"This is a test"}, {"test":"two"}]}'))));
- $this->client->getEmitter()->attach($mock);
+ $mock = new MockPlugin();
+ $mock->addResponse(new Response(200, array(), '{"results":[{"test":"This is a test"}, {"test":"two"}]}'));
+ $this->client->addSubscriber($mock);
$this->assertEquals(array("results"=>array(array('test'=>'This is a test'), array('test'=>'two'))), Transmission::all());
- $this->client->getEmitter()->detach($mock);
}
/**
* @desc tests happy path
*/
public function testFindWithGoodResponse() {
- $mock = new Mock(array(new Response(200, array(), Stream::factory('{"results":[{"test":"This is a test"}]}'))));
- $this->client->getEmitter()->attach($mock);
+ $mock = new MockPlugin();
+ $mock->addResponse(new Response(200, array(), '{"results":[{"test":"This is a test"}]}'));
+ $this->client->addSubscriber($mock);
+
$this->assertEquals(array("results"=>array(array('test'=>'This is a test'))), Transmission::find('someId'));
- $this->client->getEmitter()->detach($mock);
}
/**
* @desc tests 404 bad response
+ * @expectedException Exception
+ * @expectedExceptionMessage The specified Transmission ID does not exist
*/
public function testFindWith404Response() {
- $mock = new Mock(array(new Response(404, array())));
- $this->client->getEmitter()->attach($mock);
- try {
- Transmission::find('someId');
- } catch (\Exception $e) {
- $this->assertEquals('The specified Transmission ID does not exist', $e->getMessage());
- } finally {
- $this->client->getEmitter()->detach($mock);
- }
+ $mock = new MockPlugin();
+ $mock->addResponse(new Response(404, array()));
+ $this->client->addSubscriber($mock);
+ Transmission::find('someId');
}
/**
* @desc tests unknown bad response
+ * @expectedException Exception
+ * @expectedExceptionMessage Received bad response from Transmission API: 400
*/
public function testFindWithOtherBadResponse() {
- $mock = new Mock(array(new Response(400, array())));
- $this->client->getEmitter()->attach($mock);
- try {
- Transmission::find('someId');
- } catch (\Exception $e) {
- $this->assertEquals('Received bad response from Transmission API: 400', $e->getMessage());
- } finally {
- $this->client->getEmitter()->detach($mock);
- }
+ $mock = new MockPlugin();
+ $mock->addResponse(new Response(400, array()));
+ $this->client->addSubscriber($mock);
+ Transmission::find('someId');
}
/**
@@ -100,26 +94,25 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase {
*/
public function testSuccessfulSend() {
$body = array("result"=>array("transmission_id"=>"11668787484950529"), "status"=>array("message"=> "ok","code"=> "1000"));
- $mock = new Mock(array(new Response(200, array(), Stream::factory(json_encode($body)))));
- $this->client->getEmitter()->attach($mock);
+ $mock = new MockPlugin();
+ $mock->addResponse(new Response(200, array(), json_encode($body)));
+ $this->client->addSubscriber($mock);
+
+
$this->assertEquals($body, Transmission::send(array('text'=>'awesome email')));
- $this->client->getEmitter()->detach($mock);
}
/**
* @desc tests bad response
+ * @expectedException Exception
+ * @expectedExceptionMessage ["This is a fake error"]
*/
public function testSendForRequestException() {
$body = array('errors'=>array('This is a fake error'));
- $mock = new Mock(array(new Response(400, array(), Stream::factory(json_encode($body)))));
- $this->client->getEmitter()->attach($mock);
- try {
- Transmission::send(array('text'=>'awesome email'));
- } catch (\Exception $e) {
- $this->assertEquals('["This is a fake error"]', $e->getMessage());
- } finally {
- $this->client->getEmitter()->detach($mock);
- }
+ $mock = new MockPlugin();
+ $mock->addResponse(new Response(400, array(), json_encode($body)));
+ $this->client->addSubscriber($mock);
+ Transmission::send(array('text'=>'awesome email'));
}
}