summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--composer.json4
-rw-r--r--composer.lock380
-rw-r--r--lib/SendGridCompatibility/Email.php9
-rw-r--r--lib/SparkPost/SparkPost.php7
-rw-r--r--lib/SparkPost/Transmission.php40
-rw-r--r--test/unit/SendGridCompatibiility/EmailTest.php10
-rw-r--r--test/unit/SendGridCompatibiility/SendGridTest.php3
-rw-r--r--test/unit/TransmissionTest.php71
8 files changed, 153 insertions, 371 deletions
diff --git a/composer.json b/composer.json
index 9c2f17f..3a6a6a0 100644
--- a/composer.json
+++ b/composer.json
@@ -10,11 +10,11 @@
"minimum-stability": "stable",
"require": {
"php": ">=5.3.0",
- "guzzlehttp/guzzle": "5.0.1"
+ "guzzlehttp/guzzle": "3.8.1"
},
"require-dev": {
"phpunit/phpunit": "4.3.*",
- "codegyre/robo": "0.4.6"
+ "codegyre/robo": "0.3.6"
},
"autoload": {
"psr-4": {
diff --git a/composer.lock b/composer.lock
index c9bd5ff..58c0391 100644
--- a/composer.lock
+++ b/composer.lock
@@ -3,40 +3,70 @@
"This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
],
- "hash": "f50d7f6f0ceb190ba8f8489f4cffeabe",
+ "hash": "78307ddeb6a908b40d62d636e90a4ee2",
"packages": [
{
"name": "guzzlehttp/guzzle",
- "version": "5.0.1",
+ "version": "v3.8.1",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
- "reference": "9e806208d9b418a58ec86c49078aa94385e64bbd"
+ "reference": "4de0618a01b34aa1c8c33a3f13f396dcd3882eba"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/guzzle/guzzle/zipball/9e806208d9b418a58ec86c49078aa94385e64bbd",
- "reference": "9e806208d9b418a58ec86c49078aa94385e64bbd",
+ "url": "https://api.github.com/repos/guzzle/guzzle/zipball/4de0618a01b34aa1c8c33a3f13f396dcd3882eba",
+ "reference": "4de0618a01b34aa1c8c33a3f13f396dcd3882eba",
"shasum": ""
},
"require": {
- "guzzlehttp/ringphp": "~1.0",
- "php": ">=5.4.0"
+ "ext-curl": "*",
+ "php": ">=5.3.3",
+ "symfony/event-dispatcher": ">=2.1"
+ },
+ "replace": {
+ "guzzle/batch": "self.version",
+ "guzzle/cache": "self.version",
+ "guzzle/common": "self.version",
+ "guzzle/http": "self.version",
+ "guzzle/inflection": "self.version",
+ "guzzle/iterator": "self.version",
+ "guzzle/log": "self.version",
+ "guzzle/parser": "self.version",
+ "guzzle/plugin": "self.version",
+ "guzzle/plugin-async": "self.version",
+ "guzzle/plugin-backoff": "self.version",
+ "guzzle/plugin-cache": "self.version",
+ "guzzle/plugin-cookie": "self.version",
+ "guzzle/plugin-curlauth": "self.version",
+ "guzzle/plugin-error-response": "self.version",
+ "guzzle/plugin-history": "self.version",
+ "guzzle/plugin-log": "self.version",
+ "guzzle/plugin-md5": "self.version",
+ "guzzle/plugin-mock": "self.version",
+ "guzzle/plugin-oauth": "self.version",
+ "guzzle/service": "self.version",
+ "guzzle/stream": "self.version"
},
"require-dev": {
- "ext-curl": "*",
- "phpunit/phpunit": "~4.0",
- "psr/log": "~1.0"
+ "doctrine/cache": "*",
+ "monolog/monolog": "1.*",
+ "phpunit/phpunit": "3.7.*",
+ "psr/log": "1.0.*",
+ "symfony/class-loader": "*",
+ "zendframework/zend-cache": "<2.3",
+ "zendframework/zend-log": "<2.3"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-ring": "5.0-dev"
+ "dev-master": "3.8-dev"
}
},
"autoload": {
- "psr-4": {
- "GuzzleHttp\\": "src/"
+ "psr-0": {
+ "Guzzle": "src/",
+ "Guzzle\\Tests": "tests/"
}
},
"notification-url": "https://packagist.org/downloads/",
@@ -48,6 +78,10 @@
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
+ },
+ {
+ "name": "Guzzle Community",
+ "homepage": "https://github.com/guzzle/guzzle/contributors"
}
],
"description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients",
@@ -61,87 +95,45 @@
"rest",
"web service"
],
- "time": "2014-10-16 18:00:41"
+ "time": "2014-01-28 22:29:15"
},
{
- "name": "guzzlehttp/ringphp",
- "version": "1.0.3",
+ "name": "symfony/event-dispatcher",
+ "version": "v2.5.6",
+ "target-dir": "Symfony/Component/EventDispatcher",
"source": {
"type": "git",
- "url": "https://github.com/guzzle/RingPHP.git",
- "reference": "e7c28f96c5ac12ab0e63412cfc15989756fcb964"
+ "url": "https://github.com/symfony/EventDispatcher.git",
+ "reference": "804eb28dbbfba9ffdab21fe2066744906cea2212"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/guzzle/RingPHP/zipball/e7c28f96c5ac12ab0e63412cfc15989756fcb964",
- "reference": "e7c28f96c5ac12ab0e63412cfc15989756fcb964",
+ "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/804eb28dbbfba9ffdab21fe2066744906cea2212",
+ "reference": "804eb28dbbfba9ffdab21fe2066744906cea2212",
"shasum": ""
},
"require": {
- "guzzlehttp/streams": "~3.0",
- "php": ">=5.4.0",
- "react/promise": "~2.0"
+ "php": ">=5.3.3"
},
"require-dev": {
- "ext-curl": "*",
- "phpunit/phpunit": "~4.0"
+ "psr/log": "~1.0",
+ "symfony/config": "~2.0",
+ "symfony/dependency-injection": "~2.0,<2.6.0",
+ "symfony/stopwatch": "~2.2"
},
"suggest": {
- "ext-curl": "Guzzle will use specific adapters if cURL is present"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "1.0-dev"
- }
- },
- "autoload": {
- "psr-4": {
- "GuzzleHttp\\Ring\\": "src/"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Michael Dowling",
- "email": "mtdowling@gmail.com",
- "homepage": "https://github.com/mtdowling"
- }
- ],
- "time": "2014-11-04 07:01:14"
- },
- {
- "name": "guzzlehttp/streams",
- "version": "3.0.0",
- "source": {
- "type": "git",
- "url": "https://github.com/guzzle/streams.git",
- "reference": "47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/guzzle/streams/zipball/47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5",
- "reference": "47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5",
- "shasum": ""
- },
- "require": {
- "php": ">=5.4.0"
- },
- "require-dev": {
- "phpunit/phpunit": "~4.0"
+ "symfony/dependency-injection": "",
+ "symfony/http-kernel": ""
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "3.0-dev"
+ "dev-master": "2.5-dev"
}
},
"autoload": {
- "psr-4": {
- "GuzzleHttp\\Stream\\": "src/"
+ "psr-0": {
+ "Symfony\\Component\\EventDispatcher\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
@@ -150,91 +142,40 @@
],
"authors": [
{
- "name": "Michael Dowling",
- "email": "mtdowling@gmail.com",
- "homepage": "https://github.com/mtdowling"
- }
- ],
- "description": "Provides a simple abstraction over streams of data",
- "homepage": "http://guzzlephp.org/",
- "keywords": [
- "Guzzle",
- "stream"
- ],
- "time": "2014-10-12 19:18:40"
- },
- {
- "name": "react/promise",
- "version": "v2.1.0",
- "source": {
- "type": "git",
- "url": "https://github.com/reactphp/promise.git",
- "reference": "937b04f1b0ee8f6d180e75a0830aac778ca4bcd6"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/reactphp/promise/zipball/937b04f1b0ee8f6d180e75a0830aac778ca4bcd6",
- "reference": "937b04f1b0ee8f6d180e75a0830aac778ca4bcd6",
- "shasum": ""
- },
- "require": {
- "php": ">=5.4.0"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "2.0-dev"
- }
- },
- "autoload": {
- "psr-4": {
- "React\\Promise\\": "src/"
+ "name": "Symfony Community",
+ "homepage": "http://symfony.com/contributors"
},
- "files": [
- "src/functions.php"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
{
- "name": "Jan Sorgalla",
- "email": "jsorgalla@googlemail.com"
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
}
],
- "description": "A lightweight implementation of CommonJS Promises/A for PHP",
- "time": "2014-10-15 20:05:57"
+ "description": "Symfony EventDispatcher Component",
+ "homepage": "http://symfony.com",
+ "time": "2014-10-01 15:43:05"
}
],
"packages-dev": [
{
"name": "codegyre/robo",
- "version": "0.4.6",
+ "version": "0.3.6",
"source": {
"type": "git",
"url": "https://github.com/Codegyre/Robo.git",
- "reference": "ba257924e3ff9bdcb9899225e9f24957c7e4b3f3"
+ "reference": "f34c0a38c3a69e3c362186c0f3f3c9b53853e683"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/Codegyre/Robo/zipball/ba257924e3ff9bdcb9899225e9f24957c7e4b3f3",
- "reference": "ba257924e3ff9bdcb9899225e9f24957c7e4b3f3",
+ "url": "https://api.github.com/repos/Codegyre/Robo/zipball/f34c0a38c3a69e3c362186c0f3f3c9b53853e683",
+ "reference": "f34c0a38c3a69e3c362186c0f3f3c9b53853e683",
"shasum": ""
},
"require": {
"henrikbjorn/lurker": "1.0.*@dev",
- "php": ">=5.4.0",
- "symfony/console": "~2.1",
- "symfony/filesystem": "~2.1",
- "symfony/finder": "~2.1",
- "symfony/process": "~2.1"
+ "symfony/console": "*"
},
"require-dev": {
- "codeception/aspect-mock": "0.4.*",
- "codeception/codeception": "~2.0",
- "codeception/verify": "0.2.*"
+ "symfony/finder": "*"
},
"bin": [
"robo"
@@ -256,7 +197,7 @@
}
],
"description": "Modern task runner",
- "time": "2014-10-17 00:55:05"
+ "time": "2014-02-21 05:16:15"
},
{
"name": "doctrine/instantiator",
@@ -622,16 +563,16 @@
},
{
"name": "phpunit/phpunit",
- "version": "4.3.4",
+ "version": "4.3.5",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
- "reference": "23e4e0310f037aae873cc81b8658dbbb82878f71"
+ "reference": "2dab9d593997db4abcf58d0daf798eb4e9cecfe1"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/23e4e0310f037aae873cc81b8658dbbb82878f71",
- "reference": "23e4e0310f037aae873cc81b8658dbbb82878f71",
+ "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/2dab9d593997db4abcf58d0daf798eb4e9cecfe1",
+ "reference": "2dab9d593997db4abcf58d0daf798eb4e9cecfe1",
"shasum": ""
},
"require": {
@@ -692,7 +633,7 @@
"testing",
"xunit"
],
- "time": "2014-10-22 11:43:12"
+ "time": "2014-11-11 10:11:09"
},
{
"name": "phpunit/phpunit-mock-objects",
@@ -1119,63 +1060,6 @@
"time": "2014-10-05 13:57:04"
},
{
- "name": "symfony/event-dispatcher",
- "version": "v2.5.6",
- "target-dir": "Symfony/Component/EventDispatcher",
- "source": {
- "type": "git",
- "url": "https://github.com/symfony/EventDispatcher.git",
- "reference": "804eb28dbbfba9ffdab21fe2066744906cea2212"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/804eb28dbbfba9ffdab21fe2066744906cea2212",
- "reference": "804eb28dbbfba9ffdab21fe2066744906cea2212",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.3"
- },
- "require-dev": {
- "psr/log": "~1.0",
- "symfony/config": "~2.0",
- "symfony/dependency-injection": "~2.0,<2.6.0",
- "symfony/stopwatch": "~2.2"
- },
- "suggest": {
- "symfony/dependency-injection": "",
- "symfony/http-kernel": ""
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "2.5-dev"
- }
- },
- "autoload": {
- "psr-0": {
- "Symfony\\Component\\EventDispatcher\\": ""
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Symfony Community",
- "homepage": "http://symfony.com/contributors"
- },
- {
- "name": "Fabien Potencier",
- "email": "fabien@symfony.com"
- }
- ],
- "description": "Symfony EventDispatcher Component",
- "homepage": "http://symfony.com",
- "time": "2014-10-01 15:43:05"
- },
- {
"name": "symfony/filesystem",
"version": "v2.5.6",
"target-dir": "Symfony/Component/Filesystem",
@@ -1223,100 +1107,6 @@
"time": "2014-09-22 09:14:18"
},
{
- "name": "symfony/finder",
- "version": "v2.5.6",
- "target-dir": "Symfony/Component/Finder",
- "source": {
- "type": "git",
- "url": "https://github.com/symfony/Finder.git",
- "reference": "cf66df4e783e6aade319b273c9bcf9e42aa9b10f"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/symfony/Finder/zipball/cf66df4e783e6aade319b273c9bcf9e42aa9b10f",
- "reference": "cf66df4e783e6aade319b273c9bcf9e42aa9b10f",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.3"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "2.5-dev"
- }
- },
- "autoload": {
- "psr-0": {
- "Symfony\\Component\\Finder\\": ""
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Symfony Community",
- "homepage": "http://symfony.com/contributors"
- },
- {
- "name": "Fabien Potencier",
- "email": "fabien@symfony.com"
- }
- ],
- "description": "Symfony Finder Component",
- "homepage": "http://symfony.com",
- "time": "2014-10-01 05:50:18"
- },
- {
- "name": "symfony/process",
- "version": "v2.5.6",
- "target-dir": "Symfony/Component/Process",
- "source": {
- "type": "git",
- "url": "https://github.com/symfony/Process.git",
- "reference": "9bbacbb3a7a27b17c0d51e2f126f59e0e588ad3a"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/symfony/Process/zipball/9bbacbb3a7a27b17c0d51e2f126f59e0e588ad3a",
- "reference": "9bbacbb3a7a27b17c0d51e2f126f59e0e588ad3a",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.3"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "2.5-dev"
- }
- },
- "autoload": {
- "psr-0": {
- "Symfony\\Component\\Process\\": ""
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Symfony Community",
- "homepage": "http://symfony.com/contributors"
- },
- {
- "name": "Fabien Potencier",
- "email": "fabien@symfony.com"
- }
- ],
- "description": "Symfony Process Component",
- "homepage": "http://symfony.com",
- "time": "2014-10-01 05:50:18"
- },
- {
"name": "symfony/yaml",
"version": "v2.5.6",
"target-dir": "Symfony/Component/Yaml",
@@ -1368,7 +1158,7 @@
"minimum-stability": "stable",
"stability-flags": [],
"platform": {
- "php": ">=5.6.1"
+ "php": ">=5.3.0"
},
"platform-dev": []
}
diff --git a/lib/SendGridCompatibility/Email.php b/lib/SendGridCompatibility/Email.php
index e11c3ff..0b78c22 100644
--- a/lib/SendGridCompatibility/Email.php
+++ b/lib/SendGridCompatibility/Email.php
@@ -60,18 +60,11 @@ class Email {
}
/**
- * TODO: Does this work?
- *
- *
* @param string $address
* @return \MessageSystems\SendGridCompatibility\Email
*/
public function addBcc($address) {
- if (!isset($this->model['bcc'])) {
- $this->model['bcc'] = array();
- }
- array_push($this->model['bcc'], $address);
- return $this;
+ throw new \Exception('Adding bcc recipients is not yet supported, try adding them as a "to" address');
}
public function setSubject($subject) {
diff --git a/lib/SparkPost/SparkPost.php b/lib/SparkPost/SparkPost.php
index 4228290..5c2a554 100644
--- a/lib/SparkPost/SparkPost.php
+++ b/lib/SparkPost/SparkPost.php
@@ -25,7 +25,12 @@ class SparkPost {
*/
public static function setConfig(array $configMap) {
//check for API key because its required
- if (!isset($configMap['key']) || empty(trim($configMap['key']))){
+ if (isset($configMap['key'])){
+ $key = trim($configMap['key']);
+ if(empty($key)){
+ throw new \Exception('You must provide an API key');
+ }
+ } else {
throw new \Exception('You must provide an API key');
}
self::$config = self::$defaults;
diff --git a/lib/SparkPost/Transmission.php b/lib/SparkPost/Transmission.php
index 8e6667a..0184453 100644
--- a/lib/SparkPost/Transmission.php
+++ b/lib/SparkPost/Transmission.php
@@ -1,7 +1,7 @@
<?php
namespace SparkPost;
-use GuzzleHttp\Client;
-use GuzzleHttp\Exception\RequestException;
+use Guzzle\Http\Client;
+use Guzzle\Http\Exception\RequestException;
/**
* @desc SDK interface for managing transmissions
@@ -99,6 +99,18 @@ class Transmission {
}
/**
+ * Helper function for extracting the response status code out of request thrown exceptions
+ * @param string $exceptionMessage
+ * @return number
+ */
+ private static function getStatusCode ($exceptionMessage) {
+ $messageParts = explode("\n", $exceptionMessage);
+ $codeLine = explode('] ', $messageParts[1]);
+ $code = trim($codeLine[1]);
+ return (int)$code;
+ }
+
+ /**
* @desc Method for issuing POST request to the Transmissions API
*
* This method assumes that all the appropriate fields have
@@ -136,11 +148,7 @@ class Transmission {
//send the request
try {
- $response = $request->post(self::getBaseUrl($hostConfig), array(
- 'json'=>$model,
- "headers"=>array('authorization' => $hostConfig['key']),
- "verify"=>$hostConfig['strictSSL']
- ));
+ $response = $request->post(self::getBaseUrl($hostConfig), array('authorization' => $hostConfig['key']), $model, array("verify"=>$hostConfig['strictSSL']))->send();
return $response->json();
} catch (RequestException $exception) {
$response = $exception->getResponse();
@@ -149,7 +157,6 @@ class Transmission {
} catch (\Exception $exception) {
throw new \Exception('Unable to contact Transmissions API: '. $exception->getMessage());
}
-
}
/**
@@ -175,20 +182,17 @@ class Transmission {
//make request
try {
- $response = $request->get($url, array(
- "headers"=>array('authorization' => $hostConfig['key']),
- "verify"=>$hostConfig['strictSSL']
- ));
+ $response = $request->get($url, array('authorization' => $hostConfig['key']), array("verify"=>$hostConfig['strictSSL']))->send();
return $response->json();
- } catch (RequestException $exception) {
- $response = $exception->getResponse();
- if($response->getStatusCode() === '404') {
+ } catch (\Exception $exception) {
+ $statusCode = self::getStatusCode($exception->getMessage());
+ if($statusCode === 404) {
throw new \Exception("The specified Transmission ID does not exist", 404);
+ }else if ($statusCode !== null){
+ throw new \Exception("Received bad response from Transmission API: ". $statusCode);
} else {
- throw new \Exception("Received bad response from Transmission API: ". $response->getStatusCode());
+ throw new \Exception('Unable to contact Transmissions API: '. $exception->getMessage());
}
- } catch (\Exception $exception) {
- throw new \Exception('Unable to contact Transmissions API: '. $exception->getMessage());
}
}
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'));
}
}