summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAvi Goldman <avrahamymgoldman@gmail.com>2016-06-20 12:51:11 -0400
committerAvi Goldman <avrahamymgoldman@gmail.com>2016-06-20 12:51:11 -0400
commit1187a2ccc7209b2fc4deded9e61c5124698df795 (patch)
tree025473f3c29dea39763207ceddd26c4a407763fc
parent0942bed79ca5e8162213405ea16350ae855d9546 (diff)
parent87552cc2766f4ea8c8a2d6ff6c70dd74faecb687 (diff)
downloadphp-sparkpost-1187a2ccc7209b2fc4deded9e61c5124698df795.zip
php-sparkpost-1187a2ccc7209b2fc4deded9e61c5124698df795.tar.gz
php-sparkpost-1187a2ccc7209b2fc4deded9e61c5124698df795.tar.bz2
merged in 2.x
-rw-r--r--AUTHORS.md2
-rw-r--r--CONTRIBUTING.md2
-rw-r--r--README.md267
-rw-r--r--composer.json5
-rw-r--r--composer.lock1034
-rw-r--r--examples/transmission/send_with_bcc.php8
-rw-r--r--examples/transmission/send_with_cc.php12
-rw-r--r--examples/unwrapped/create_transmission.php9
-rw-r--r--lib/SparkPost/SparkPost.php151
-rw-r--r--lib/SparkPost/SparkPostException.php33
-rw-r--r--lib/SparkPost/SparkPostPromise.php86
-rw-r--r--lib/SparkPost/SparkPostResponse.php55
-rw-r--r--test/unit/APIResourceExceptionTest.php43
-rw-r--r--test/unit/APIResourceTest.php196
-rw-r--r--test/unit/MessageEventTest.php74
-rw-r--r--test/unit/SendGridCompatibiility/EmailTest.php178
-rw-r--r--test/unit/SparkPostResponseTest.php136
-rw-r--r--test/unit/SparkPostTest.php263
-rw-r--r--test/unit/TransmissionTest.php114
19 files changed, 864 insertions, 1804 deletions
diff --git a/AUTHORS.md b/AUTHORS.md
index 34f2ee0..29226af 100644
--- a/AUTHORS.md
+++ b/AUTHORS.md
@@ -13,3 +13,5 @@ php-sparkpost is maintained by Message Systems.
* Chris Wilson, [@yepher](https://github.com/yepher)
* Maxim Dzhuliy, [@max-si-m](https://github.com/max-si-m)
* [@chandon](https://github.com/chandon)
+* Avi Goldman, [@avrahamgoldman](https://github.com/avrahamgoldman)
+* Vincent Song, [@vwsong](https://github.com/vwsong)
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 1bc3c40..1bbdaf9 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -26,7 +26,7 @@ Add composer install directory to $PATH `~/.composer/vendor/bin/`
#### Install PHPUnit for Testing
```
-composer global require "phpunit/phpunit=4.3.*"
+composer global require "phpunit/phpunit=4.8.*"
```
We recommend increasing PHP’s memory limit, by default it uses 128MB. We ran into some issues during local development without doing so. You can do this by editing your php.ini file and modifying `memory_limit`. We set ours to `memory_limit = 1024M`.
diff --git a/README.md b/README.md
index 3a8098f..932763c 100644
--- a/README.md
+++ b/README.md
@@ -7,9 +7,7 @@
[![Travis CI](https://travis-ci.org/SparkPost/php-sparkpost.svg?branch=master)](https://travis-ci.org/SparkPost/php-sparkpost)
[![Coverage Status](https://coveralls.io/repos/SparkPost/php-sparkpost/badge.svg?branch=master&service=github)](https://coveralls.io/github/SparkPost/php-sparkpost?branch=master) [![Slack Status](http://slack.sparkpost.com/badge.svg)](http://slack.sparkpost.com)
-The official PHP library for using [the SparkPost REST API](https://developers.sparkpost.com).
-
-**Note: We understand that the ivory-http-adapter we use in this library is deprecated in favor of httplug. We use Ivory internally to make it simple for you to use whatever HTTP library you want. The deprecation won't affect or limit our ongoing support of this PHP library.**
+The official PHP library for using [the SparkPost REST API](https://developers.sparkpost.com/api/).
Before using this library, you must have a valid API Key. To get an API Key, please log in to your SparkPost account and generate one in the Settings page.
@@ -38,107 +36,204 @@ use SparkPost\SparkPost;
Because of dependency collision, we have opted to use a request adapter rather than
requiring a request library. This means that your application will need to pass in
-a request adapter to the constructor of the SparkPost Library. We use the [Ivory HTTP Adapter] (https://github.com/egeloen/ivory-http-adapter) in SparkPost. Please visit their repo
-for a list of supported adapters. If you don't currently use a request library, you will
-need to require one and create an adapter from it and pass it along. The example below uses the
-GuzzleHttp Client Library.
+a request adapter to the constructor of the SparkPost Library. We use the [HTTPlug](https://github.com/php-http/httplug) in SparkPost. Please visit their repo for a list of supported adapters. If you don't currently use a request library, you will
+need to require one and create an adapter from it and pass it along. The example below uses the GuzzleHttp Client Library.
An Adapter can be setup like so:
```php
+<?php
use SparkPost\SparkPost;
use GuzzleHttp\Client;
-use Ivory\HttpAdapter\Guzzle6HttpAdapter;
+use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
-$httpAdapter = new Guzzle6HttpAdapter(new Client());
-$sparky = new SparkPost($httpAdapter, ['key'=>'YOUR API KEY']);
+$httpClient = new GuzzleAdapter(new Client());
+$sparky = new SparkPost($httpClient, ['key'=>'YOUR_API_KEY']);
+?>
```
-## Getting Started: Your First Mailing
-For this example to work as is, [Guzzle 6 will need to be installed](http://docs.guzzlephp.org/en/latest/overview.html#installation). Otherwise another adapter can be used for your specific setup. See "Setting up a Request Adapter" above.
-
+## Initialization
+#### new Sparkpost(httpClient, options)
+* `httpClient`
+ * Required: Yes
+ * HTTP client or adapter supported by HTTPlug
+* `options`
+ * Required: Yes
+ * Type: `String` or `Array`
+ * A valid Sparkpost API key or an array of options
+* `options.key`
+ * Required: Yes
+ * Type: `String`
+ * A valid Sparkpost API key
+* `options.host`
+ * Required: No
+ * Type: `String`
+ * Default: `api.sparkpost.com`
+* `options.protocol`
+ * Required: No
+ * Type: `String`
+ * Default: `https`
+* `options.port`
+ * Required: No
+ * Type: `Number`
+ * Default: 443
+* `options.version`
+ * Required: No
+ * Type: `String`
+ * Default: `v1`
+* `options.timeout`
+ * Required: No
+ * Type: `Number`
+ * Default: `10`
+
+
+## Methods
+### request(method, uri [, payload [, headers]])
+* `method`
+ * Required: Yes
+ * Type: `String`
+ * HTTP method for request
+* `uri`
+ * Required: Yes
+ * Type: `String`
+ * The URI to recieve the request
+* `payload`
+ * Required: No
+ * Type: `Array`
+ * If the method is `GET` the values are encoded into the URL. Otherwise, if the method is `POST`, `PUT`, or `DELETE` the payload is used for the request body.
+* `headers`
+ * Required: No
+ * Type: `Array`
+ * Custom headers to be sent with the request.
+
+### setHttpClient(httpClient)
+* `httpClient`
+ * Required: Yes
+ * HTTP client or adapter supported by HTTPlug
+
+### setOptions(options)
+* `options`
+ * Required: Yes
+ * Type: `Array`
+ * See initialization
+
+
+## Endpoints
+### transmissions
+* **get([transmissionID] [, payload])**
+ * `transmissionID` - see `uri` request options
+ * `payload` - see request options
+* **post(payload)**
+ * `payload` - see request options
+ * `payload.cc`
+ * Required: No
+ * Type: `Array`
+ * Recipients to recieve a carbon copy of the transmission
+ * `payload.bcc`
+ * Required: No
+ * Type: `Array`
+ * Recipients to descreetly recieve a carbon copy of the transmission
+* **delete(transmissionID)**
+ * `transmissionID` - see `uri` request options
+
+## Examples
+
+### Send An Email Using The Transmissions Endpoint
```php
-require 'vendor/autoload.php';
-
+<?php
use SparkPost\SparkPost;
use GuzzleHttp\Client;
-use Ivory\HttpAdapter\Guzzle6HttpAdapter;
+use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
-$httpAdapter = new Guzzle6HttpAdapter(new Client());
-$sparky = new SparkPost($httpAdapter, ['key'=>'YOUR API KEY']);
+$httpClient = new GuzzleAdapter(new Client());
+$sparky = new SparkPost($httpClient, ['key'=>'YOUR_API_KEY']);
-try {
- // Build your email and send it!
- $results = $sparky->transmission->send([
- 'from'=>[
- 'name' => 'From Envelope',
- 'email' => 'from@sparkpostbox.com>'
+$promise = $sparky->transmissions->post([
+ 'content' => [
+ 'from'=> [
+ 'name' => 'Sparkpost Team',
+ 'email' => 'from@sparkpostbox.com'
],
- 'html'=>'<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>',
- 'text'=>'Congratulations, {{name}}!! You just sent your very first mailing!',
- 'substitutionData'=>['name'=>'YOUR FIRST NAME'],
'subject'=>'First Mailing From PHP',
- 'recipients'=>[
- [
- 'address'=>[
- 'name'=>'YOUR FULL NAME',
- 'email'=>'YOUR EMAIL ADDRESS'
- ]
- ]
- ]
- ]);
- echo 'Woohoo! You just sent your first mailing!';
-} catch (\Exception $err) {
- echo 'Whoops! Something went wrong';
- var_dump($err);
+ 'html'=>'<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>',
+ 'text'=>'Congratulations, {{name}}!! You just sent your very first mailing!'
+ ],
+ 'substitution_data'=> ['name'=>'YOUR_FIRST_NAME'],
+ 'recipients'=> [
+ [ 'address' => '<YOUR_EMAIL_ADDRESS>' ]
+ ],
+ 'bcc' => [
+ ['address' => '<ANOTHER_EMAIL_ADDRESS>' ]
+ ]
+]);
+?>
+```
+
+### Send An API Call Using The Base Request Function
+We may not wrap every resource available in the SparkPost Client Library, for example the PHP Client Library does not wrap the Metrics resource. To allow you to use the full power of our API we created the `request` function which allows you to access the unwrapped resources.
+```php
+<?php
+use SparkPost\SparkPost;
+use GuzzleHttp\Client;
+use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
+
+$httpClient = new GuzzleAdapter(new Client());
+$sparky = new SparkPost($httpClient, ['key'=>'YOUR_API_KEY']);
+
+$promise = $sparky->request('GET', 'metrics/ip-pools', [
+ 'from' => '2015-12-01T08:00',
+ 'to' => '2014-12-01T09:00',
+ 'timezone' => 'America/New_York',
+ 'limit' => '5'
+]);
+?>
+```
+
+
+## Handling Responses
+The all API calls return a promise. You can wait for the promise to be fulfilled or you can handle it asynchronously.
+
+##### Wait (Synchronous)
+```php
+<?php
+try {
+ $response = $promise->wait();
+ echo $response->getStatusCode();
+ echo $response->getBody();
+} catch (Exception $e) {
+ echo $e->getCode();
+ echo $e->getMessage();
}
+?>
```
-## Learn More
-* For more detailed examples, check our examples:
- * [Transmissions](https://github.com/SparkPost/php-sparkpost/tree/master/examples/transmission)
-* Read our REST API documentation - <http://www.sparkpost.com/docs/introduction>
-
-## Field Descriptions
-### Transmissions
-| Field Name | Required? | Description | Data Type |
-| ------------ | ----------- | ------------- | ----------- |
-| attachments | no | Field for attaching files - see Attachment Attributes in the [Transmssions API docs](https://developers.sparkpost.com/api/#/reference/transmissions) | Array of Objects |
-| campaign | no | Field for assigning a given transmission to a specific campaign, which is a logical container for similar transmissions | String |
-| customHeaders | no | Field for specifying additional headers to be applied to a given transmission (other than Subject, From, To, and Reply-To) | Object (Simple) |
-| description | no | Field for describing what this transmission is for the user | String |
-| from | yes** | Field for setting the from line of a given transmission | Object |
-| html | yes** | Field for setting the HTML content of a given transmission | String |
-| inlineCss | no | Field for enabling/disabling CSS inlining | Boolean |
-| inlineImages | no | Field for providing inline images - see Inline Image Attributes in the [Transmssions API docs](https://developers.sparkpost.com/api/#/reference/transmissions) | Array of Objects |
-| metadata | no | Field for adding arbitrary key/value pairs which will be included in open/click tracking | Object (Simple) |
-| recipientList | no** | Field for specifying a stored recipient list ID to be used for a given transmission | String |
-| recipients | yes** | Field for specifying who a given transmission should be sent to | Array of Objects |
-| replyTo | no | Field for specifying the email address that should be used when a recipient hits the reply button | String |
-| rfc822 | no** | Field for setting the RFC-822 encoded content of a given transmission | String |
-| subject | yes | Field for setting the subject line of a given transmission | String |
-| substitutionData | no | Field for adding transmission level substitution data, which can be used in a variety of fields and in content | Object (Complex) |
-| template | no** | Field for specifying the Template ID of a stored template to be used when sending a given transmission | String |
-| text | yes** | Field for setting the Plain Text content of a given transmission | String |
-| trackClicks | no | Field for enabling/disabling transmission level click tracking (default: true) | Boolean |
-| trackOpens | no | Field for enabling/disabling transmission level open tracking (default: true) | Boolean |
-| transactional | no | Field for marking email as transactional (default: false) | Boolean |
-| useDraftTemplate | no | Field for allowing the sending of a transmission using a draft of a stored template (default: false) | Boolean |
-
-** - If using inline content then html or text are required. If using RFC-822 Inline Content, then rfc822 is required. If using a stored recipient list, then recipientList is required. If using a stored template, then template is required but from is not as the values from the template will be used.
-
-## Tips and Tricks
-### General
-* You _must_ provide at least an API key when instantiating the SparkPost Library - `[ 'key'=>'184ac5480cfdd2bb2859e4476d2e5b1d2bad079bf' ]`
-* The library's features are namespaced under the various SparkPost API names.
-
-### Transmissions
-* If you specify a stored recipient list and inline recipients in a Transmission, you will receive an error.
-* If you specify HTML and/or Plain Text content and then provide RFC-822 encoded content, you will receive an error.
- * RFC-822 content is not valid with any other content type.
-* If you specify a stored template and also provide inline content via `html` or `text`, you will receive an error.
-* By default, open and click tracking are enabled for a transmission.
-* By default, a transmission will use the published version of a stored template.
+##### Then (Asynchronous)
+```php
+<?php
+$promise->then(
+ // Success callback
+ function ($response) {
+ echo $response->getStatusCode();
+ echo $response->getBody();
+ },
+ // Failure callback
+ function (Exception $e) {
+ echo $e->getCode();
+ echo $e->getMessage();
+ }
+);
+?>
+```
+
+## Handling Exceptions
+The promise will throw an exception if the server returns a status code of `400` or higher.
+
+### Exception
+* **getCode()**
+ * Returns the response status code of `400` or higher
+* **getMessage()**
+ * Returns the body of response as an `Array`
+
### Contributing
-See [contributing](https://github.com/SparkPost/php-sparkpost/blob/master/CONTRIBUTING.md).
+See [contributing](https://github.com/SparkPost/php-sparkpost/blob/master/CONTRIBUTING.md). \ No newline at end of file
diff --git a/composer.json b/composer.json
index 2962dd2..a38b8c4 100644
--- a/composer.json
+++ b/composer.json
@@ -20,9 +20,8 @@
"guzzlehttp/psr7": "1.3.*"
},
"require-dev": {
- "phpunit/phpunit": "4.3.*",
- "guzzlehttp/guzzle": "5.*",
- "php-http/guzzle5-adapter": "*",
+ "guzzlehttp/guzzle": "6.*",
+ "php-http/guzzle6-adapter": "*",
"php-http/message": "*",
"mockery/mockery": "^0.9.4",
"fabpot/php-cs-fixer": "^1.11"
diff --git a/composer.lock b/composer.lock
index a4b401e..9c5d64e 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,39 +4,43 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "hash": "a20653dbdc9cb61db488224520f62aaa",
- "content-hash": "1023d8370cc9af702c5e2d68fd21ca8d",
+ "hash": "7b514c4fd3556635eab6298f14e03c47",
+ "content-hash": "2a019c7c9fe0fa211dd763cb9c1bcd62",
"packages": [
{
"name": "guzzlehttp/guzzle",
- "version": "5.3.0",
+ "version": "6.2.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
- "reference": "f3c8c22471cb55475105c14769644a49c3262b93"
+ "reference": "d094e337976dff9d8e2424e8485872194e768662"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/guzzle/guzzle/zipball/f3c8c22471cb55475105c14769644a49c3262b93",
- "reference": "f3c8c22471cb55475105c14769644a49c3262b93",
+ "url": "https://api.github.com/repos/guzzle/guzzle/zipball/d094e337976dff9d8e2424e8485872194e768662",
+ "reference": "d094e337976dff9d8e2424e8485872194e768662",
"shasum": ""
},
"require": {
- "guzzlehttp/ringphp": "^1.1",
- "php": ">=5.4.0"
+ "guzzlehttp/promises": "~1.0",
+ "guzzlehttp/psr7": "~1.1",
+ "php": ">=5.5.0"
},
"require-dev": {
"ext-curl": "*",
- "phpunit/phpunit": "^4.0",
- "psr/log": "^1.0"
+ "phpunit/phpunit": "~4.0",
+ "psr/log": "~1.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "5.0-dev"
+ "dev-master": "6.2-dev"
}
},
"autoload": {
+ "files": [
+ "src/functions_include.php"
+ ],
"psr-4": {
"GuzzleHttp\\": "src/"
}
@@ -52,7 +56,7 @@
"homepage": "https://github.com/mtdowling"
}
],
- "description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients",
+ "description": "Guzzle is a PHP HTTP client library",
"homepage": "http://guzzlephp.org/",
"keywords": [
"client",
@@ -63,28 +67,24 @@
"rest",
"web service"
],
- "time": "2015-05-20 03:47:55"
+ "time": "2016-03-21 20:02:09"
},
{
- "name": "guzzlehttp/psr7",
- "version": "1.3.0",
+ "name": "guzzlehttp/promises",
+ "version": "1.2.0",
"source": {
"type": "git",
- "url": "https://github.com/guzzle/psr7.git",
- "reference": "31382fef2889136415751badebbd1cb022a4ed72"
+ "url": "https://github.com/guzzle/promises.git",
+ "reference": "c10d860e2a9595f8883527fa0021c7da9e65f579"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/guzzle/psr7/zipball/31382fef2889136415751badebbd1cb022a4ed72",
- "reference": "31382fef2889136415751badebbd1cb022a4ed72",
+ "url": "https://api.github.com/repos/guzzle/promises/zipball/c10d860e2a9595f8883527fa0021c7da9e65f579",
+ "reference": "c10d860e2a9595f8883527fa0021c7da9e65f579",
"shasum": ""
},
"require": {
- "php": ">=5.4.0",
- "psr/http-message": "~1.0"
- },
- "provide": {
- "psr/http-message-implementation": "1.0"
+ "php": ">=5.5.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
@@ -97,7 +97,7 @@
},
"autoload": {
"psr-4": {
- "GuzzleHttp\\Psr7\\": "src/"
+ "GuzzleHttp\\Promise\\": "src/"
},
"files": [
"src/functions_include.php"
@@ -114,82 +114,32 @@
"homepage": "https://github.com/mtdowling"
}
],
- "description": "PSR-7 message implementation",
+ "description": "Guzzle promises library",
"keywords": [
- "http",
- "message",
- "stream",
- "uri"
+ "promise"
],
- "time": "2016-04-13 19:56:01"
+ "time": "2016-05-18 16:56:05"
},
{
- "name": "guzzlehttp/ringphp",
- "version": "1.1.0",
+ "name": "guzzlehttp/psr7",
+ "version": "1.3.0",
"source": {
"type": "git",
- "url": "https://github.com/guzzle/RingPHP.git",
- "reference": "dbbb91d7f6c191e5e405e900e3102ac7f261bc0b"
+ "url": "https://github.com/guzzle/psr7.git",
+ "reference": "31382fef2889136415751badebbd1cb022a4ed72"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/guzzle/RingPHP/zipball/dbbb91d7f6c191e5e405e900e3102ac7f261bc0b",
- "reference": "dbbb91d7f6c191e5e405e900e3102ac7f261bc0b",
+ "url": "https://api.github.com/repos/guzzle/psr7/zipball/31382fef2889136415751badebbd1cb022a4ed72",
+ "reference": "31382fef2889136415751badebbd1cb022a4ed72",
"shasum": ""
},
"require": {
- "guzzlehttp/streams": "~3.0",
"php": ">=5.4.0",
- "react/promise": "~2.0"
- },
- "require-dev": {
- "ext-curl": "*",
- "phpunit/phpunit": "~4.0"
- },
- "suggest": {
- "ext-curl": "Guzzle will use specific adapters if cURL is present"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "1.1-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"
- }
- ],
- "description": "Provides a simple API and specification that abstracts away the details of HTTP into a single PHP function.",
- "time": "2015-05-20 03:37:09"
- },
- {
- "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": ""
+ "psr/http-message": "~1.0"
},
- "require": {
- "php": ">=5.4.0"
+ "provide": {
+ "psr/http-message-implementation": "1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
@@ -197,13 +147,16 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "3.0-dev"
+ "dev-master": "1.0-dev"
}
},
"autoload": {
"psr-4": {
- "GuzzleHttp\\Stream\\": "src/"
- }
+ "GuzzleHttp\\Psr7\\": "src/"
+ },
+ "files": [
+ "src/functions_include.php"
+ ]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -216,118 +169,51 @@
"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": "php-http/discovery",
- "version": "v0.8.0",
- "source": {
- "type": "git",
- "url": "https://github.com/php-http/discovery.git",
- "reference": "fac1240e8a070b3e2f0e38606941de80c849fa53"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/php-http/discovery/zipball/fac1240e8a070b3e2f0e38606941de80c849fa53",
- "reference": "fac1240e8a070b3e2f0e38606941de80c849fa53",
- "shasum": ""
- },
- "require": {
- "php": "^5.4|7.*"
- },
- "require-dev": {
- "henrikbjorn/phpspec-code-coverage": "^1.0",
- "php-http/httplug": "^1.0",
- "php-http/message-factory": "^1.0",
- "phpspec/phpspec": "^2.4",
- "puli/composer-plugin": "1.0.0-beta9"
- },
- "suggest": {
- "php-http/message": "Allow to use Guzzle or Diactoros factories",
- "puli/composer-plugin": "Sets up Puli which is required for Discovery to work. Check http://docs.php-http.org/en/latest/discovery.html for more details."
- },
- "bin": [
- "bin/puli.phar"
- ],
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "0.9-dev"
- }
- },
- "autoload": {
- "psr-4": {
- "Http\\Discovery\\": "src/"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Márk Sági-Kazár",
- "email": "mark.sagikazar@gmail.com"
- }
- ],
- "description": "Finds installed HTTPlug implementations and PSR-7 message factories",
- "homepage": "http://httplug.io",
+ "description": "PSR-7 message implementation",
"keywords": [
- "adapter",
- "client",
- "discovery",
- "factory",
"http",
- "message"
+ "message",
+ "stream",
+ "uri"
],
- "time": "2016-02-11 09:53:37"
+ "time": "2016-04-13 19:56:01"
},
{
- "name": "php-http/guzzle5-adapter",
- "version": "v0.5.0",
+ "name": "php-http/guzzle6-adapter",
+ "version": "v1.1.1",
"source": {
"type": "git",
- "url": "https://github.com/php-http/guzzle5-adapter.git",
- "reference": "4edc424fe9c4c620775ee7fab77fa7ae02584765"
+ "url": "https://github.com/php-http/guzzle6-adapter.git",
+ "reference": "a56941f9dc6110409cfcddc91546ee97039277ab"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/php-http/guzzle5-adapter/zipball/4edc424fe9c4c620775ee7fab77fa7ae02584765",
- "reference": "4edc424fe9c4c620775ee7fab77fa7ae02584765",
+ "url": "https://api.github.com/repos/php-http/guzzle6-adapter/zipball/a56941f9dc6110409cfcddc91546ee97039277ab",
+ "reference": "a56941f9dc6110409cfcddc91546ee97039277ab",
"shasum": ""
},
"require": {
- "guzzlehttp/guzzle": "^5.1",
- "php": ">=5.4",
- "php-http/discovery": "^0.8",
+ "guzzlehttp/guzzle": "^6.0",
+ "php": ">=5.5.0",
"php-http/httplug": "^1.0"
},
"provide": {
+ "php-http/async-client-implementation": "1.0",
"php-http/client-implementation": "1.0"
},
"require-dev": {
"ext-curl": "*",
- "guzzlehttp/psr7": "^1.2",
- "guzzlehttp/ringphp": "^1.1",
- "php-http/adapter-integration-tests": "^0.3",
- "php-http/client-common": "^1.0",
- "puli/composer-plugin": "1.0.0-beta9"
+ "php-http/adapter-integration-tests": "^0.4"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "0.6-dev"
+ "dev-master": "1.2-dev"
}
},
"autoload": {
"psr-4": {
- "Http\\Adapter\\Guzzle5\\": "src/"
+ "Http\\Adapter\\Guzzle6\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
@@ -336,21 +222,21 @@
],
"authors": [
{
- "name": "Eric GELOEN",
- "email": "geloen.eric@gmail.com"
- },
- {
"name": "Márk Sági-Kazár",
"email": "mark.sagikazar@gmail.com"
+ },
+ {
+ "name": "David de Boer",
+ "email": "david@ddeboer.nl"
}
],
- "description": "Guzzle 5 HTTP Adapter",
+ "description": "Guzzle 6 HTTP Adapter",
"homepage": "http://httplug.io",
"keywords": [
"Guzzle",
"http"
],
- "time": "2016-02-23 14:14:55"
+ "time": "2016-05-10 06:13:32"
},
{
"name": "php-http/httplug",
@@ -506,50 +392,6 @@
"response"
],
"time": "2015-05-04 20:22:00"
- },
- {
- "name": "react/promise",
- "version": "v2.4.1",
- "source": {
- "type": "git",
- "url": "https://github.com/reactphp/promise.git",
- "reference": "8025426794f1944de806618671d4fa476dc7626f"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/reactphp/promise/zipball/8025426794f1944de806618671d4fa476dc7626f",
- "reference": "8025426794f1944de806618671d4fa476dc7626f",
- "shasum": ""
- },
- "require": {
- "php": ">=5.4.0"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "2.0-dev"
- }
- },
- "autoload": {
- "psr-4": {
- "React\\Promise\\": "src/"
- },
- "files": [
- "src/functions_include.php"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Jan Sorgalla",
- "email": "jsorgalla@gmail.com"
- }
- ],
- "description": "A lightweight implementation of CommonJS Promises/A for PHP",
- "time": "2016-05-03 17:50:52"
}
],
"packages-dev": [
@@ -603,60 +445,6 @@
"time": "2015-11-08 23:41:30"
},
{
- "name": "doctrine/instantiator",
- "version": "1.0.5",
- "source": {
- "type": "git",
- "url": "https://github.com/doctrine/instantiator.git",
- "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d",
- "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3,<8.0-DEV"
- },
- "require-dev": {
- "athletic/athletic": "~0.1.8",
- "ext-pdo": "*",
- "ext-phar": "*",
- "phpunit/phpunit": "~4.0",
- "squizlabs/php_codesniffer": "~2.0"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "1.0.x-dev"
- }
- },
- "autoload": {
- "psr-4": {
- "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Marco Pivetta",
- "email": "ocramius@gmail.com",
- "homepage": "http://ocramius.github.com/"
- }
- ],
- "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors",
- "homepage": "https://github.com/doctrine/instantiator",
- "keywords": [
- "constructor",
- "instantiate"
- ],
- "time": "2015-06-14 21:17:01"
- },
- {
"name": "fabpot/php-cs-fixer",
"version": "v1.11.4",
"source": {
@@ -938,441 +726,6 @@
"time": "2015-12-19 14:08:53"
},
{
- "name": "phpunit/php-code-coverage",
- "version": "2.2.4",
- "source": {
- "type": "git",
- "url": "https://github.com/sebastianbergmann/php-code-coverage.git",
- "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/eabf68b476ac7d0f73793aada060f1c1a9bf8979",
- "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.3",
- "phpunit/php-file-iterator": "~1.3",
- "phpunit/php-text-template": "~1.2",
- "phpunit/php-token-stream": "~1.3",
- "sebastian/environment": "^1.3.2",
- "sebastian/version": "~1.0"
- },
- "require-dev": {
- "ext-xdebug": ">=2.1.4",
- "phpunit/phpunit": "~4"
- },
- "suggest": {
- "ext-dom": "*",
- "ext-xdebug": ">=2.2.1",
- "ext-xmlwriter": "*"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "2.2.x-dev"
- }
- },
- "autoload": {
- "classmap": [
- "src/"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "BSD-3-Clause"
- ],
- "authors": [
- {
- "name": "Sebastian Bergmann",
- "email": "sb@sebastian-bergmann.de",
- "role": "lead"
- }
- ],
- "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.",
- "homepage": "https://github.com/sebastianbergmann/php-code-coverage",
- "keywords": [
- "coverage",
- "testing",
- "xunit"
- ],
- "time": "2015-10-06 15:47:00"
- },
- {
- "name": "phpunit/php-file-iterator",
- "version": "1.3.4",
- "source": {
- "type": "git",
- "url": "https://github.com/sebastianbergmann/php-file-iterator.git",
- "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/acd690379117b042d1c8af1fafd61bde001bf6bb",
- "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.3"
- },
- "type": "library",
- "autoload": {
- "classmap": [
- "File/"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "include-path": [
- ""
- ],
- "license": [
- "BSD-3-Clause"
- ],
- "authors": [
- {
- "name": "Sebastian Bergmann",
- "email": "sb@sebastian-bergmann.de",
- "role": "lead"
- }
- ],
- "description": "FilterIterator implementation that filters files based on a list of suffixes.",
- "homepage": "https://github.com/sebastianbergmann/php-file-iterator/",
- "keywords": [
- "filesystem",
- "iterator"
- ],
- "time": "2013-10-10 15:34:57"
- },
- {
- "name": "phpunit/php-text-template",
- "version": "1.2.1",
- "source": {
- "type": "git",
- "url": "https://github.com/sebastianbergmann/php-text-template.git",
- "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686",
- "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.3"
- },
- "type": "library",
- "autoload": {
- "classmap": [
- "src/"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "BSD-3-Clause"
- ],
- "authors": [
- {
- "name": "Sebastian Bergmann",
- "email": "sebastian@phpunit.de",
- "role": "lead"
- }
- ],
- "description": "Simple template engine.",
- "homepage": "https://github.com/sebastianbergmann/php-text-template/",
- "keywords": [
- "template"
- ],
- "time": "2015-06-21 13:50:34"
- },
- {
- "name": "phpunit/php-timer",
- "version": "1.0.8",
- "source": {
- "type": "git",
- "url": "https://github.com/sebastianbergmann/php-timer.git",
- "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/38e9124049cf1a164f1e4537caf19c99bf1eb260",
- "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.3"
- },
- "require-dev": {
- "phpunit/phpunit": "~4|~5"
- },
- "type": "library",
- "autoload": {
- "classmap": [
- "src/"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "BSD-3-Clause"
- ],
- "authors": [
- {
- "name": "Sebastian Bergmann",
- "email": "sb@sebastian-bergmann.de",
- "role": "lead"
- }
- ],
- "description": "Utility class for timing",
- "homepage": "https://github.com/sebastianbergmann/php-timer/",
- "keywords": [
- "timer"
- ],
- "time": "2016-05-12 18:03:57"
- },
- {
- "name": "phpunit/php-token-stream",
- "version": "1.4.8",
- "source": {
- "type": "git",
- "url": "https://github.com/sebastianbergmann/php-token-stream.git",
- "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da",
- "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da",
- "shasum": ""
- },
- "require": {
- "ext-tokenizer": "*",
- "php": ">=5.3.3"
- },
- "require-dev": {
- "phpunit/phpunit": "~4.2"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "1.4-dev"
- }
- },
- "autoload": {
- "classmap": [
- "src/"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "BSD-3-Clause"
- ],
- "authors": [
- {
- "name": "Sebastian Bergmann",
- "email": "sebastian@phpunit.de"
- }
- ],
- "description": "Wrapper around PHP's tokenizer extension.",
- "homepage": "https://github.com/sebastianbergmann/php-token-stream/",
- "keywords": [
- "tokenizer"
- ],
- "time": "2015-09-15 10:49:45"
- },
- {
- "name": "phpunit/phpunit",
- "version": "4.3.5",
- "source": {
- "type": "git",
- "url": "https://github.com/sebastianbergmann/phpunit.git",
- "reference": "2dab9d593997db4abcf58d0daf798eb4e9cecfe1"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/2dab9d593997db4abcf58d0daf798eb4e9cecfe1",
- "reference": "2dab9d593997db4abcf58d0daf798eb4e9cecfe1",
- "shasum": ""
- },
- "require": {
- "ext-dom": "*",
- "ext-json": "*",
- "ext-pcre": "*",
- "ext-reflection": "*",
- "ext-spl": "*",
- "php": ">=5.3.3",
- "phpunit/php-code-coverage": "~2.0",
- "phpunit/php-file-iterator": "~1.3.2",
- "phpunit/php-text-template": "~1.2",
- "phpunit/php-timer": "~1.0.2",
- "phpunit/phpunit-mock-objects": "~2.3",
- "sebastian/comparator": "~1.0",
- "sebastian/diff": "~1.1",
- "sebastian/environment": "~1.0",
- "sebastian/exporter": "~1.0",
- "sebastian/version": "~1.0",
- "symfony/yaml": "~2.0"
- },
- "suggest": {
- "phpunit/php-invoker": "~1.1"
- },
- "bin": [
- "phpunit"
- ],
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "4.3.x-dev"
- }
- },
- "autoload": {
- "classmap": [
- "src/"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "include-path": [
- "",
- "../../symfony/yaml/"
- ],
- "license": [
- "BSD-3-Clause"
- ],
- "authors": [
- {
- "name": "Sebastian Bergmann",
- "email": "sebastian@phpunit.de",
- "role": "lead"
- }
- ],
- "description": "The PHP Unit Testing framework.",
- "homepage": "http://www.phpunit.de/",
- "keywords": [
- "phpunit",
- "testing",
- "xunit"
- ],
- "time": "2014-11-11 10:11:09"
- },
- {
- "name": "phpunit/phpunit-mock-objects",
- "version": "2.3.8",
- "source": {
- "type": "git",
- "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git",
- "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/ac8e7a3db35738d56ee9a76e78a4e03d97628983",
- "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983",
- "shasum": ""
- },
- "require": {
- "doctrine/instantiator": "^1.0.2",
- "php": ">=5.3.3",
- "phpunit/php-text-template": "~1.2",
- "sebastian/exporter": "~1.2"
- },
- "require-dev": {
- "phpunit/phpunit": "~4.4"
- },
- "suggest": {
- "ext-soap": "*"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "2.3.x-dev"
- }
- },
- "autoload": {
- "classmap": [
- "src/"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "BSD-3-Clause"
- ],
- "authors": [
- {
- "name": "Sebastian Bergmann",
- "email": "sb@sebastian-bergmann.de",
- "role": "lead"
- }
- ],
- "description": "Mock Object library for PHPUnit",
- "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/",
- "keywords": [
- "mock",
- "xunit"
- ],
- "time": "2015-10-02 06:51:40"
- },
- {
- "name": "sebastian/comparator",
- "version": "1.2.0",
- "source": {
- "type": "git",
- "url": "https://github.com/sebastianbergmann/comparator.git",
- "reference": "937efb279bd37a375bcadf584dec0726f84dbf22"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/937efb279bd37a375bcadf584dec0726f84dbf22",
- "reference": "937efb279bd37a375bcadf584dec0726f84dbf22",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.3",
- "sebastian/diff": "~1.2",
- "sebastian/exporter": "~1.2"
- },
- "require-dev": {
- "phpunit/phpunit": "~4.4"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "1.2.x-dev"
- }
- },
- "autoload": {
- "classmap": [
- "src/"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "BSD-3-Clause"
- ],
- "authors": [
- {
- "name": "Jeff Welch",
- "email": "whatthejeff@gmail.com"
- },
- {
- "name": "Volker Dusch",
- "email": "github@wallbash.com"
- },
- {
- "name": "Bernhard Schussek",
- "email": "bschussek@2bepublished.at"
- },
- {
- "name": "Sebastian Bergmann",
- "email": "sebastian@phpunit.de"
- }
- ],
- "description": "Provides the functionality to compare PHP values for equality",
- "homepage": "http://www.github.com/sebastianbergmann/comparator",
- "keywords": [
- "comparator",
- "compare",
- "equality"
- ],
- "time": "2015-07-26 15:48:44"
- },
- {
"name": "sebastian/diff",
"version": "1.4.1",
"source": {
@@ -1425,210 +778,6 @@
"time": "2015-12-08 07:14:41"
},
{
- "name": "sebastian/environment",
- "version": "1.3.7",
- "source": {
- "type": "git",
- "url": "https://github.com/sebastianbergmann/environment.git",
- "reference": "4e8f0da10ac5802913afc151413bc8c53b6c2716"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/4e8f0da10ac5802913afc151413bc8c53b6c2716",
- "reference": "4e8f0da10ac5802913afc151413bc8c53b6c2716",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.3"
- },
- "require-dev": {
- "phpunit/phpunit": "~4.4"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "1.3.x-dev"
- }
- },
- "autoload": {
- "classmap": [
- "src/"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "BSD-3-Clause"
- ],
- "authors": [
- {
- "name": "Sebastian Bergmann",
- "email": "sebastian@phpunit.de"
- }
- ],
- "description": "Provides functionality to handle HHVM/PHP environments",
- "homepage": "http://www.github.com/sebastianbergmann/environment",
- "keywords": [
- "Xdebug",
- "environment",
- "hhvm"
- ],
- "time": "2016-05-17 03:18:57"
- },
- {
- "name": "sebastian/exporter",
- "version": "1.2.1",
- "source": {
- "type": "git",
- "url": "https://github.com/sebastianbergmann/exporter.git",
- "reference": "7ae5513327cb536431847bcc0c10edba2701064e"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/7ae5513327cb536431847bcc0c10edba2701064e",
- "reference": "7ae5513327cb536431847bcc0c10edba2701064e",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.3",
- "sebastian/recursion-context": "~1.0"
- },
- "require-dev": {
- "phpunit/phpunit": "~4.4"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "1.2.x-dev"
- }
- },
- "autoload": {
- "classmap": [
- "src/"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "BSD-3-Clause"
- ],
- "authors": [
- {
- "name": "Jeff Welch",
- "email": "whatthejeff@gmail.com"
- },
- {
- "name": "Volker Dusch",
- "email": "github@wallbash.com"
- },
- {
- "name": "Bernhard Schussek",
- "email": "bschussek@2bepublished.at"
- },
- {
- "name": "Sebastian Bergmann",
- "email": "sebastian@phpunit.de"
- },
- {
- "name": "Adam Harvey",
- "email": "aharvey@php.net"
- }
- ],
- "description": "Provides the functionality to export PHP variables for visualization",
- "homepage": "http://www.github.com/sebastianbergmann/exporter",
- "keywords": [
- "export",
- "exporter"
- ],
- "time": "2015-06-21 07:55:53"
- },
- {
- "name": "sebastian/recursion-context",
- "version": "1.0.2",
- "source": {
- "type": "git",
- "url": "https://github.com/sebastianbergmann/recursion-context.git",
- "reference": "913401df809e99e4f47b27cdd781f4a258d58791"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/913401df809e99e4f47b27cdd781f4a258d58791",
- "reference": "913401df809e99e4f47b27cdd781f4a258d58791",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.3"
- },
- "require-dev": {
- "phpunit/phpunit": "~4.4"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "1.0.x-dev"
- }
- },
- "autoload": {
- "classmap": [
- "src/"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "BSD-3-Clause"
- ],
- "authors": [
- {
- "name": "Jeff Welch",
- "email": "whatthejeff@gmail.com"
- },
- {
- "name": "Sebastian Bergmann",
- "email": "sebastian@phpunit.de"
- },
- {
- "name": "Adam Harvey",
- "email": "aharvey@php.net"
- }
- ],
- "description": "Provides functionality to recursively process PHP variables",
- "homepage": "http://www.github.com/sebastianbergmann/recursion-context",
- "time": "2015-11-11 19:50:13"
- },
- {
- "name": "sebastian/version",
- "version": "1.0.6",
- "source": {
- "type": "git",
- "url": "https://github.com/sebastianbergmann/version.git",
- "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6",
- "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6",
- "shasum": ""
- },
- "type": "library",
- "autoload": {
- "classmap": [
- "src/"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "BSD-3-Clause"
- ],
- "authors": [
- {
- "name": "Sebastian Bergmann",
- "email": "sebastian@phpunit.de",
- "role": "lead"
- }
- ],
- "description": "Library that helps with managing the version number of Git-hosted PHP projects",
- "homepage": "https://github.com/sebastianbergmann/version",
- "time": "2015-06-21 13:59:46"
- },
- {
"name": "symfony/console",
"version": "v3.1.0",
"source": {
@@ -2002,55 +1151,6 @@
"description": "Symfony Stopwatch Component",
"homepage": "https://symfony.com",
"time": "2016-03-04 07:56:56"
- },
- {
- "name": "symfony/yaml",
- "version": "v2.8.7",
- "source": {
- "type": "git",
- "url": "https://github.com/symfony/yaml.git",
- "reference": "815fabf3f48c7d1df345a69d1ad1a88f59757b34"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/symfony/yaml/zipball/815fabf3f48c7d1df345a69d1ad1a88f59757b34",
- "reference": "815fabf3f48c7d1df345a69d1ad1a88f59757b34",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.9"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "2.8-dev"
- }
- },
- "autoload": {
- "psr-4": {
- "Symfony\\Component\\Yaml\\": ""
- },
- "exclude-from-classmap": [
- "/Tests/"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Fabien Potencier",
- "email": "fabien@symfony.com"
- },
- {
- "name": "Symfony Community",
- "homepage": "https://symfony.com/contributors"
- }
- ],
- "description": "Symfony Yaml Component",
- "homepage": "https://symfony.com",
- "time": "2016-06-06 11:11:27"
}
],
"aliases": [],
@@ -2062,4 +1162,4 @@
"php": ">=5.5.0"
},
"platform-dev": []
-}
+} \ No newline at end of file
diff --git a/examples/transmission/send_with_bcc.php b/examples/transmission/send_with_bcc.php
index ce67862..7479c4a 100644
--- a/examples/transmission/send_with_bcc.php
+++ b/examples/transmission/send_with_bcc.php
@@ -36,8 +36,8 @@ try {
'email' => 'original.recipient@example.com',
],
'substitution_data' => [
- 'recipient_type' => 'Original'
- ]
+ 'recipient_type' => 'Original',
+ ],
],
[
'address' => [
@@ -45,8 +45,8 @@ try {
'header_to' => '"Original Recipient" <original.recipient@example.com>',
],
'substitution_data' => [
- 'recipient_type' => 'BCC'
- ]
+ 'recipient_type' => 'BCC',
+ ],
],
],
]);
diff --git a/examples/transmission/send_with_cc.php b/examples/transmission/send_with_cc.php
index fa1d9e9..7ad2a7b 100644
--- a/examples/transmission/send_with_cc.php
+++ b/examples/transmission/send_with_cc.php
@@ -36,8 +36,8 @@ try {
'email' => 'original.recipient@example.com',
],
'substitution_data' => [
- 'recipient_type' => 'Original'
- ]
+ 'recipient_type' => 'Original',
+ ],
],
[
'address' => [
@@ -46,13 +46,13 @@ try {
'header_to' => '"Original Recipient" <original.recipient@example.com>',
],
'substitution_data' => [
- 'recipient_type' => 'CC'
- ]
+ 'recipient_type' => 'CC',
+ ],
],
],
'customHeaders' => [
- 'CC' => '"Carbon Copy Recipient" <cc.recipient@example.com>'
- ]
+ 'CC' => '"Carbon Copy Recipient" <cc.recipient@example.com>',
+ ],
]);
echo 'Congrats! You sent an email with cc using SparkPost!';
} catch (\Exception $exception) {
diff --git a/examples/unwrapped/create_transmission.php b/examples/unwrapped/create_transmission.php
index f19ee6e..d3a44c5 100644
--- a/examples/unwrapped/create_transmission.php
+++ b/examples/unwrapped/create_transmission.php
@@ -24,8 +24,8 @@ try {
[
'address' => [
'email' => 'john.doe@example.com',
- ]
- ]
+ ],
+ ],
],
'content' => [
'from' => [
@@ -34,8 +34,8 @@ try {
],
'html' => '<p>Hello World!</p>',
'text' => 'Hello World!',
- 'subject' => 'Example Email'
- ]
+ 'subject' => 'Example Email',
+ ],
];
$results = $sparky->transmissions->create($message);
echo 'Congrats! You sent a message using SparkPost!';
@@ -44,4 +44,3 @@ try {
echo $exception->getAPICode()."\n";
echo $exception->getAPIDescription()."\n";
}
-
diff --git a/lib/SparkPost/SparkPost.php b/lib/SparkPost/SparkPost.php
index 7b011ed..e76bcd0 100644
--- a/lib/SparkPost/SparkPost.php
+++ b/lib/SparkPost/SparkPost.php
@@ -8,10 +8,24 @@ use GuzzleHttp\Psr7\Request as Request;
class SparkPost
{
+ /**
+ * Library version, used for setting User-Agent.
+ */
private $version = '2.0.0';
+
+ /**
+ * HttpClient used to make requests.
+ */
public $httpClient;
+
+ /**
+ * Options for requests.
+ */
private $options;
+ /**
+ * Default options for requests that can be overridden with the setOptions function.
+ */
private static $defaultOptions = [
'host' => 'api.sparkpost.com',
'protocol' => 'https',
@@ -19,11 +33,20 @@ class SparkPost
'key' => '',
'version' => 'v1',
'timeout' => 10,
- 'async' => true
+ 'async' => true,
];
+ /**
+ * Instance of Transmission class.
+ */
public $transmissions;
+ /**
+ * Sets up the SparkPost instance.
+ *
+ * @param HttpClient $httpClient - An httplug client or adapter
+ * @param array $options - An array to overide default options or a string to be used as an API key
+ */
public function __construct(HttpClient $httpClient, $options)
{
$this->setOptions($options);
@@ -31,49 +54,86 @@ class SparkPost
$this->setupEndpoints();
}
- public function request($method = 'GET', $uri = '', $payload = [], $headers = []) {
- if ($this->options['async'] === true && $this->httpClient instanceof HttpAsyncClient) {
+ /**
+ * Sends either sync or async request based on async option.
+ *
+ * @param string $method
+ * @param string $uri
+ * @param array $payload - either used as the request body or url query params
+ * @param array $headers
+ *
+ * @return SparkPostPromise or SparkPostResponse depending on sync or async request
+ */
+ public function request($method = 'GET', $uri = '', $payload = [], $headers = [])
+ {
+ if ($this->options['async'] === true) {
return $this->asyncRequest($method, $uri, $payload, $headers);
- }
- else {
+ } else {
return $this->syncRequest($method, $uri, $payload, $headers);
}
}
+ /**
+ * Sends sync request to SparkPost API.
+ *
+ * @param string $method
+ * @param string $uri
+ * @param array $payload
+ * @param array $headers
+ *
+ * @return SparkPostResponse
+ *
+ * @throws SparkPostException
+ */
public function syncRequest($method = 'GET', $uri = '', $payload = [], $headers = [])
{
$request = $this->buildRequest($method, $uri, $payload, $headers);
- try
- {
+ try {
return new SparkPostResponse($this->httpClient->sendRequest($request));
- }
- catch (\Exception $exception)
- {
- throw new SparkPostException($exception);
+ } catch (\Exception $exception) {
+ throw new SparkPostException($exception);
}
}
+ /**
+ * Sends async request to SparkPost API.
+ *
+ * @param string $method
+ * @param string $uri
+ * @param array $payload
+ * @param array $headers
+ *
+ * @return SparkPostPromise
+ */
public function asyncRequest($method = 'GET', $uri = '', $payload = [], $headers = [])
{
if ($this->httpClient instanceof HttpAsyncClient) {
$request = $this->buildRequest($method, $uri, $payload, $headers);
+
return new SparkPostPromise($this->httpClient->sendAsyncRequest($request));
- }
- else {
- throw new Exception('Your http client can not send asynchronous requests.');
+ } else {
+ throw new \Exception('Your http client does not support asynchronous requests. Please use a different client or use synchronous requests.');
}
}
- private function buildRequest($method, $uri, $payload, $headers)
+ /**
+ * Builds request from given params.
+ *
+ * @param string $method
+ * @param string $uri
+ * @param array $payload
+ * @param array $headers
+ *
+ * @return GuzzleHttp\Psr7\Request - A Psr7 compliant request
+ */
+ public function buildRequest($method, $uri, $payload, $headers)
{
-
$method = trim(strtoupper($method));
-
- if ($method === 'GET'){
+
+ if ($method === 'GET') {
$params = $payload;
$body = [];
- }
- else {
+ } else {
$params = [];
$body = $payload;
}
@@ -84,11 +144,19 @@ class SparkPost
return new Request($method, $url, $headers, json_encode($body));
}
+ /**
+ * Returns an array for the request headers.
+ *
+ * @param array $headers - any custom headers for the request
+ *
+ * @return array $headers - headers for the request
+ */
public function getHttpHeaders($headers = [])
{
$constantHeaders = [
'Authorization' => $this->options['key'],
- 'Content-Type' => 'application/json'
+ 'Content-Type' => 'application/json',
+ 'User-Agent' => 'php-sparkpost/'.$this->version,
];
foreach ($constantHeaders as $key => $value) {
@@ -98,24 +166,47 @@ class SparkPost
return $headers;
}
- public function getUrl($path, $params) {
+ /**
+ * Builds the request url from the options and given params.
+ *
+ * @param string $path - the path in the url to hit
+ * @param array $params - query parameters to be encoded into the url
+ *
+ * @return string $url - the url to send the desired request to
+ */
+ public function getUrl($path, $params = [])
+ {
$options = $this->options;
- for ($index = 0; $index < count($params); $index++) {
- if (is_array($params[$index]))
- $params[$index] = implode(',', $params);
+ $paramsArray = [];
+ foreach ($params as $key => $value) {
+ if (is_array($value)) {
+ $value = implode(',', $value);
+ }
+
+ array_push($paramsArray, $key.'='.$value);
}
- $paramsString = http_build_query($params);
+ $paramsString = implode('&', $paramsArray);
return $options['protocol'].'://'.$options['host'].($options['port'] ? ':'.$options['port'] : '').'/api/'.$options['version'].'/'.$path.($paramsString ? '?'.$paramsString : '');
}
+ /**
+ * Sets $httpClient to be used for request.
+ *
+ * @param Http\Client\HttpClient $httpClient - the client to be used for request
+ */
public function setHttpClient(HttpClient $httpClient)
{
$this->httpClient = $httpClient;
}
+ /**
+ * Sets the options from the param and defaults for the SparkPost object.
+ *
+ * @param array $options - either an string API key or an array of options
+ */
public function setOptions($options)
{
// if the options map is a string we should assume that its an api key
@@ -138,7 +229,11 @@ class SparkPost
}
}
- private function setupEndpoints() {
- $this->transmissions = new Transmission($this);
+ /**
+ * Sets up any endpoints from custom classes e.g. $this->transmissions.
+ */
+ private function setupEndpoints()
+ {
+ // $this->transmissions = new Transmission($this);
}
}
diff --git a/lib/SparkPost/SparkPostException.php b/lib/SparkPost/SparkPostException.php
index 92be3d5..f1e3146 100644
--- a/lib/SparkPost/SparkPostException.php
+++ b/lib/SparkPost/SparkPostException.php
@@ -4,23 +4,38 @@ namespace SparkPost;
use Http\Client\Exception\HttpException as HttpException;
-class SparkPostException extends \Exception {
-
+class SparkPostException extends \Exception
+{
+ /**
+ * Variable to hold json decoded body from http response.
+ */
private $body = null;
- public function __construct(\Exception $exception) {
+ /**
+ * Sets up the custom exception and copies over original exception values.
+ *
+ * @param Exception $exception - the exception to be wrapped
+ */
+ public function __construct(\Exception $exception)
+ {
$message = $exception->getMessage();
- if($exception instanceof HttpException) {
+ $code = $exception->getCode();
+ if ($exception instanceof HttpException) {
$message = $exception->getResponse()->getBody()->__toString();
$this->body = json_decode($message, true);
+ $code = $exception->getResponse()->getStatusCode();
}
- parent::__construct($message, $exception->getCode(), $exception->getPrevious());
+ parent::__construct($message, $code, $exception->getPrevious());
}
- public function getBody() {
+ /**
+ * Returns the body.
+ *
+ * @return array $body - the json decoded body from the http response
+ */
+ public function getBody()
+ {
return $this->body;
}
-}
-
-?> \ No newline at end of file
+} \ No newline at end of file
diff --git a/lib/SparkPost/SparkPostPromise.php b/lib/SparkPost/SparkPostPromise.php
index 462599a..15f129f 100644
--- a/lib/SparkPost/SparkPostPromise.php
+++ b/lib/SparkPost/SparkPostPromise.php
@@ -6,38 +6,64 @@ use Http\Promise\Promise as HttpPromise;
class SparkPostPromise implements HttpPromise
{
- private $promise;
+ /**
+ * HttpPromise to be wrapped by SparkPostPromise.
+ */
+ private $promise;
- public function __construct(HttpPromise $promise) {
- $this->promise = $promise;
- }
+ /**
+ * set the promise to be wrapped.
+ *
+ * @param HttpPromise $promise
+ */
+ public function __construct(HttpPromise $promise)
+ {
+ $this->promise = $promise;
+ }
- public function then(callable $onFulfilled = null, callable $onRejected = null) {
- $this->promise->then(
- function($response) {
- $onFulfilled(new SparkPostResponse($response));
- },
- function(\Exception $exception) {
- $onRejected(new SparkPostException($exception));
- });
- }
+ /**
+ * Hand off the response functions to the original promise and return a custom response or exception.
+ *
+ * @param callable $onFulfilled - function to be called if the promise is fulfilled
+ * @param callable $onRejected - function to be called if the promise is rejected
+ */
+ public function then(callable $onFulfilled = null, callable $onRejected = null)
+ {
+ return $this->promise->then(function($response) use ($onFulfilled) {
+ if (isset($onFulfilled))
+ $onFulfilled(new SparkPostResponse($response));
+ }, function($exception) use ($onRejected) {
+ if (isset($onRejected))
+ $onRejected(new SparkPostException($exception));
+ });
+ }
- public function getState() {
- return $this->promise->getState();
- }
+ /**
+ * Hand back the state.
+ *
+ * @return $state - returns the state of the promise
+ */
+ public function getState()
+ {
+ return $this->promise->getState();
+ }
-
- public function wait($unwrap = true) {
- try
- {
- $response = $this->promise->wait($unwrap);
- return new SparkPostResponse($response);
- }
- catch (\Exception $exception)
- {
- throw new SparkPostException($exception);
- }
- }
+ /**
+ * Wraps the wait function and returns a custom response or throws a custom exception.
+ *
+ * @param bool $unwrap
+ *
+ * @return SparkPostResponse
+ *
+ * @throws SparkPostException
+ */
+ public function wait($unwrap = true)
+ {
+ try {
+ $response = $this->promise->wait($unwrap);
+ return $response ? new SparkPostResponse($response) : $response;
+ } catch (\Exception $exception) {
+ throw new SparkPostException($exception);
+ }
+ }
}
-
-?> \ No newline at end of file
diff --git a/lib/SparkPost/SparkPostResponse.php b/lib/SparkPost/SparkPostResponse.php
index 161b864..9104b33 100644
--- a/lib/SparkPost/SparkPostResponse.php
+++ b/lib/SparkPost/SparkPostResponse.php
@@ -5,35 +5,39 @@ namespace SparkPost;
use Psr\Http\Message\ResponseInterface as ResponseInterface;
use Psr\Http\Message\StreamInterface as StreamInterface;
-class SparkPostResponse implements ResponseInterface {
-
- private $response;
-
- public function __construct(ResponseInterface $response) {
- $this->response = $response;
- }
+class SparkPostResponse implements ResponseInterface
+{
+ /**
+ * ResponseInterface to be wrapped by SparkPostResponse.
+ */
+ private $response;
+
+ /**
+ * set the response to be wrapped.
+ *
+ * @param ResponseInterface $response
+ */
+ public function __construct(ResponseInterface $response)
+ {
+ $this->response = $response;
+ }
+ /**
+ * Returns the body.
+ *
+ * @return array $body - the json decoded body from the http response
+ */
public function getBody()
{
$body = $this->response->getBody();
$body_string = $body->__toString();
-
- if (is_string($body_string)) {
- $json = json_decode($body_string, true);
-
- if (json_last_error() == JSON_ERROR_NONE) {
- return $json;
- }
- else {
- return $body;
- }
- }
-
- return $body;
+
+ $json = json_decode($body_string, true);
+
+ return $json;
}
// pass these down to the response given in the constructor
-
public function getProtocolVersion()
{
return $this->response->getProtocolVersion();
@@ -84,7 +88,7 @@ class SparkPostResponse implements ResponseInterface {
return $this->response->withBody($body);
}
- public function getStatusCode()
+ public function getStatusCode()
{
return $this->response->getStatusCode();
}
@@ -93,12 +97,9 @@ class SparkPostResponse implements ResponseInterface {
{
return $this->response->withStatus($code, $reasonPhrase);
}
-
+
public function getReasonPhrase()
{
- $this->response->getReasonPhrase();
+ return $this->response->getReasonPhrase();
}
-
}
-
-?> \ No newline at end of file
diff --git a/test/unit/APIResourceExceptionTest.php b/test/unit/APIResourceExceptionTest.php
deleted file mode 100644
index 8ae80de..0000000
--- a/test/unit/APIResourceExceptionTest.php
+++ /dev/null
@@ -1,43 +0,0 @@
-<?php
-
-namespace SparkPost\Test;
-
-use SparkPost\APIResponseException;
-
-class APIResourceExceptionTest extends \PHPUnit_Framework_TestCase
-{
- private $message;
- private $code;
- private $description;
- private $exception;
-
- /**
- * (non-PHPdoc).
- *
- * @before
- *
- * @see PHPUnit_Framework_TestCase::setUp()
- */
- public function setUp()
- {
- $this->message = 'Test message';
- $this->code = 400;
- $this->description = 'Test description';
- $this->exception = new APIResponseException(null, 0, $this->message, $this->code, $this->description);
- }
-
- public function testAPIMessage()
- {
- $this->assertEquals($this->message, $this->exception->getAPIMessage());
- }
-
- public function testAPICode()
- {
- $this->assertEquals($this->code, $this->exception->getAPICode());
- }
-
- public function testAPIDescription()
- {
- $this->assertEquals($this->description, $this->exception->getAPIDescription());
- }
-}
diff --git a/test/unit/APIResourceTest.php b/test/unit/APIResourceTest.php
deleted file mode 100644
index 67c37ab..0000000
--- a/test/unit/APIResourceTest.php
+++ /dev/null
@@ -1,196 +0,0 @@
-<?php
-
-namespace SparkPost\Test;
-
-use SparkPost\APIResource;
-use SparkPost\Test\TestUtils\ClassUtils;
-use Mockery;
-
-class APIResourceTest extends \PHPUnit_Framework_TestCase
-{
- private static $utils;
- private $adapterMock;
- private $resource;
-
- private function getExceptionMock($statusCode)
- {
- $exception = new \Ivory\HttpAdapter\HttpAdapterException();
- $response = Mockery::mock('Ivory\HttpAdapter\Message\ResponseInterface');
- $response->shouldReceive('getStatusCode')->andReturn($statusCode);
- $exception->setResponse($response);
-
- return $exception;
- }
-
- /**
- * (non-PHPdoc).
- *
- * @before
- *
- * @see PHPUnit_Framework_TestCase::setUp()
- */
- public function setUp()
- {
- $this->sparkPostMock = Mockery::mock('SparkPost\SparkPost', function ($mock) {
- $mock->shouldReceive('getHttpHeaders')->andReturn([]);
- });
- $this->sparkPostMock->httpAdapter = Mockery::mock();
- $this->resource = new APIResource($this->sparkPostMock);
- self::$utils = new ClassUtils($this->resource);
- self::$utils->setProperty($this->resource, 'sparkpost', $this->sparkPostMock);
- }
-
- public function tearDown()
- {
- Mockery::close();
- }
-
- public function testConstructorSetsUpSparkPostObject()
- {
- $this->sparkPostMock->newProp = 'new value';
- $this->assertEquals($this->sparkPostMock, self::$utils->getProperty($this->resource, 'sparkpost'));
- }
-
- public function testCreate()
- {
- $testInput = ['test' => 'body'];
- $testBody = ['results' => ['my' => 'test']];
- $responseMock = Mockery::mock();
- $this->sparkPostMock->httpAdapter->shouldReceive('send')->
- once()->
- with(Mockery::type('string'), 'POST', Mockery::type('array'), json_encode($testInput))->
- andReturn($responseMock);
- $responseMock->shouldReceive('getStatusCode')->andReturn(200);
- $responseMock->shouldReceive('getBody->getContents')->andReturn(json_encode($testBody));
-
- $this->assertEquals($testBody, $this->resource->create($testInput));
- }
-
- public function testUpdate()
- {
- $testInput = ['test' => 'body'];
- $testBody = ['results' => ['my' => 'test']];
- $responseMock = Mockery::mock();
- $this->sparkPostMock->httpAdapter->shouldReceive('send')->
- once()->
- with('/.*\/test/', 'PUT', Mockery::type('array'), json_encode($testInput))->
- andReturn($responseMock);
- $responseMock->shouldReceive('getStatusCode')->andReturn(200);
- $responseMock->shouldReceive('getBody->getContents')->andReturn(json_encode($testBody));
-
- $this->assertEquals($testBody, $this->resource->update('test', $testInput));
- }
-
- public function testGet()
- {
- $testBody = ['results' => ['my' => 'test']];
- $responseMock = Mockery::mock();
- $this->sparkPostMock->httpAdapter->shouldReceive('send')->
- once()->
- with('/.*\/test/', 'GET', Mockery::type('array'), null)->
- andReturn($responseMock);
- $responseMock->shouldReceive('getStatusCode')->andReturn(200);
- $responseMock->shouldReceive('getBody->getContents')->andReturn(json_encode($testBody));
-
- $this->assertEquals($testBody, $this->resource->get('test'));
- }
-
- public function testGetCommaSeparated()
- {
- $testBody = ['results' => ['my' => 'test']];
- $requestArray = [
- 'param1' => 'param1val',
- 'param2' => ['param2val1', 'param2val2'],
- ];
- $expectedGetParams = 'param1=param1val&param2='.urlencode('param2val1,param2val2');
-
- $responseMock = Mockery::mock();
- $this->sparkPostMock->httpAdapter->shouldReceive('send')->
- once()->
- with(matchesPattern("/.*\/test\?{$expectedGetParams}/"), 'GET', Mockery::type('array'), null)->
- andReturn($responseMock);
- $responseMock->shouldReceive('getStatusCode')->andReturn(200);
- $responseMock->shouldReceive('getBody->getContents')->andReturn(json_encode($testBody));
-
- $this->assertEquals($testBody, $this->resource->get('test', $requestArray));
- }
-
- public function testDelete()
- {
- $responseMock = Mockery::mock();
- $this->sparkPostMock->httpAdapter->shouldReceive('send')->
- once()->
- with('/.*\/test/', 'DELETE', Mockery::type('array'), null)->
- andReturn($responseMock);
- $responseMock->shouldReceive('getStatusCode')->andReturn(200);
- $responseMock->shouldReceive('getBody->getContents')->andReturn('');
-
- $this->assertEquals(null, $this->resource->delete('test'));
- }
-
- public function testAdapter404Exception()
- {
- try {
- $responseMock = Mockery::mock();
- $this->sparkPostMock->httpAdapter->shouldReceive('send')->
- once()->
- andReturn($responseMock);
- $responseMock->shouldReceive('getStatusCode')->andReturn(404);
-
- $this->resource->get('test');
- } catch (\Exception $e) {
- $this->assertRegExp('/.*resource does not exist.*/', $e->getMessage());
- }
- }
-
- public function testAdapter403Exception()
- {
- $testBody = ['errors' => [
- [
- 'message' => 'Forbidden.',
- ],
- ]];
- try {
- $responseMock = Mockery::mock();
- $this->sparkPostMock->httpAdapter->shouldReceive('send')->
- once()->
- andReturn($responseMock);
- $responseMock->shouldReceive('getStatusCode')->andReturn(403);
- $responseMock->shouldReceive('getBody')->andReturn(json_encode($testBody));
-
- $this->resource->get('test');
- } catch (\Exception $e) {
- $this->assertRegExp('/Request forbidden/', $e->getMessage());
- }
- }
-
- public function testAdapter4XXException()
- {
- try {
- $testBody = ['errors' => ['my' => 'test']];
- $responseMock = Mockery::mock();
- $this->sparkPostMock->httpAdapter->shouldReceive('send')->
- once()->
- andReturn($responseMock);
- $responseMock->shouldReceive('getStatusCode')->andReturn(400);
- $responseMock->shouldReceive('getBody')->andReturn(json_encode($testBody));
-
- $this->resource->get('test');
- } catch (\Exception $e) {
- $this->assertRegExp('/Received bad response.*/', $e->getMessage());
- }
- }
-
- public function testAdapter5XXException()
- {
- try {
- $this->sparkPostMock->httpAdapter->shouldReceive('send')->
- once()->
- andThrow(new \Exception('Something went wrong.'));
-
- $this->resource->get('test');
- } catch (\Exception $e) {
- $this->assertRegExp('/Unable to contact.*API.*/', $e->getMessage());
- }
- }
-}
diff --git a/test/unit/MessageEventTest.php b/test/unit/MessageEventTest.php
deleted file mode 100644
index 3d92412..0000000
--- a/test/unit/MessageEventTest.php
+++ /dev/null
@@ -1,74 +0,0 @@
-<?php
-
-namespace SparkPost;
-
-use Mockery;
-
-class MessageEventTest extends \PHPUnit_Framework_TestCase
-{
- private $sparkPostMock;
- private $sut;
-
- /**
- * (non-PHPdoc).
- *
- * @before
- *
- * @see PHPUnit_Framework_TestCase::setUp()
- */
- public function setUp()
- {
- $this->sparkPostMock = Mockery::mock('SparkPost\SparkPost', function ($mock) {
- $mock->shouldReceive('getHttpHeaders')->andReturn([]);
- });
- $this->sparkPostMock->httpAdapter = Mockery::mock();
- $this->sut = new MessageEvents($this->sparkPostMock);
- }
-
- public function testDateTimeConversion()
- {
- $testBody = ['results' => ['my' => 'test']];
- $testFrom = new \DateTime('1978-08-27 04:05:02');
- $testFromStr = urlencode('1978-08-27T04:05');
- $testTo = new \DateTime('2016-04-04 19:00');
- $testToStr = urlencode('2016-04-04T19:00');
-
- $responseMock = Mockery::mock();
- $this->sparkPostMock->httpAdapter->shouldReceive('send')->
- once()->
- with("/message-events/?from={$testFromStr}&to={$testToStr}", 'GET', Mockery::type('array'), null)->
- andReturn($responseMock);
- $responseMock->shouldReceive('getStatusCode')->andReturn(200);
- $responseMock->shouldReceive('getBody->getContents')->andReturn(json_encode($testBody));
-
- $this->assertEquals($testBody, $this->sut->search(['from' => $testFrom, 'to' => $testTo]));
- }
-
- public function testDocumentation()
- {
- $testBody = ['results' => ['my' => 'test']];
- $responseMock = Mockery::mock();
- $this->sparkPostMock->httpAdapter->shouldReceive('send')->
- once()->
- with('/message-events/events/documentation', 'GET', Mockery::type('array'), null)->
- andReturn($responseMock);
- $responseMock->shouldReceive('getStatusCode')->andReturn(200);
- $responseMock->shouldReceive('getBody->getContents')->andReturn(json_encode($testBody));
-
- $this->assertEquals($testBody, $this->sut->documentation());
- }
-
- public function testSamples()
- {
- $testBody = ['results' => ['my' => 'test']];
- $responseMock = Mockery::mock();
- $this->sparkPostMock->httpAdapter->shouldReceive('send')->
- once()->
- with('/message-events/events/samples?events='.urlencode('delivery,bounce'), 'GET', Mockery::type('array'), null)->
- andReturn($responseMock);
- $responseMock->shouldReceive('getStatusCode')->andReturn(200);
- $responseMock->shouldReceive('getBody->getContents')->andReturn(json_encode($testBody));
-
- $this->assertEquals($testBody, $this->sut->samples(['delivery', 'bounce']));
- }
-}
diff --git a/test/unit/SendGridCompatibiility/EmailTest.php b/test/unit/SendGridCompatibiility/EmailTest.php
deleted file mode 100644
index 2846e9e..0000000
--- a/test/unit/SendGridCompatibiility/EmailTest.php
+++ /dev/null
@@ -1,178 +0,0 @@
-<?php
-
-use SparkPost\SendGridCompatibility\Email;
-
-class SendGridCompatibilityEmailTest extends \PHPUnit_Framework_TestCase
-{
- private $email;
-
- public function setup()
- {
- $this->email = new Email();
- }
-
- public function testConstruct()
- {
- $email = new Email();
-
- $this->assertInstanceOf('SparkPost\SendGridCompatibility\Email', $email);
- $this->assertInternalType('array', $email->model);
- }
-
- public function testAddTo()
- {
- $fakeEmail = 'joe.schmoe@test.com';
- $this->email->addTo($fakeEmail);
-
- $this->assertEquals(array(array('address' => array('email' => $fakeEmail))), $this->email->model['recipients']);
- }
-
- public function testAddToWithName()
- {
- $fakeEmail = 'joe.schmoe@test.com';
- $fakeName = 'Joe Schmoe';
- $this->email->addTo($fakeEmail, $fakeName);
-
- $this->assertEquals(array(array('address' => array('email' => $fakeEmail, 'name' => $fakeName))), $this->email->model['recipients']);
- }
-
- public function testSetTos()
- {
- $tos = array();
- array_push($tos, array('address' => array('email' => 'joe.schmoe@test.com', 'name' => 'Joe Schmoe')));
- array_push($tos, array('address' => array('email' => 'jill.schmoe@test.com', 'name' => 'Jill Schmoe')));
- $this->email->setTos($tos);
-
- $this->assertEquals($tos, $this->email->model['recipients']);
- }
-
- public function testSetFrom()
- {
- $this->email->setFrom('test@email.com');
-
- $this->assertEquals(array('email' => 'test@email.com'), $this->email->model['from']);
- }
-
- public function testSetFromName()
- {
- $this->email->setFrom('test@email.com');
- $this->email->setFromName('Test Bot');
-
- $this->assertEquals(array('email' => 'test@email.com', 'name' => 'Test Bot'), $this->email->model['from']);
- }
-
- /**
- * @desc Tests that setting the fromName prior to setting the From field throws an exception
- * @expectedException Exception
- * @expectedExceptionMessage Must set 'From' prior to setting 'From Name'.
- */
- public function testSetFromNameWithoutAddress()
- {
- $this->email->setFromName('Test Bot');
- }
-
- public function testSetReplyto()
- {
- $this->email->setReplyTo('test@email.com');
-
- $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');
- }
-
- public function testSetSubject()
- {
- $this->email->setSubject('Awesome Subject');
-
- $this->assertEquals('Awesome Subject', $this->email->model['subject']);
- }
-
- public function testSetText()
- {
- $value = 'This is some plain/text';
- $this->email->setText($value);
-
- $this->assertEquals($value, $this->email->model['text']);
- }
-
- public function testSetHtml()
- {
- $value = '<html><body><p>This is some html</p></body></html>';
- $this->email->setHtml($value);
-
- $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()
- {
- $this->email->addCategory('');
- }
-
- /**
- * @desc Tests that setting an attachment throws a meaningful exception
- * @expectedException Exception
- * @expectedExceptionMessage Adding attachments is not yet supported
- */
- public function testAddAttachment()
- {
- $this->email->addAttachment('blah');
- }
-
- public function testAddSubstitution()
- {
- $this->email->addSubstitution('item', 'baseball bat');
-
- $this->assertEquals(array('item' => 'baseball bat'), $this->email->model['substitutionData']);
- }
-
- public function testAddSection()
- {
- $this->email->addSection('item', 'baseball bat');
-
- $this->assertEquals(array('item' => 'baseball bat'), $this->email->model['substitutionData']);
- }
-
- /**
- * @desc Tests that setting an attachment throws a meaningful exception
- * @expectedException Exception
- * @expectedExceptionMessage Adding Unique Arguments is not yet supported
- */
- public function testAddUniqueArguement()
- {
- $this->email->addUniqueArg('blah', 'someblah');
- }
-
- /**
- * @desc Tests that setting an unique argument throws a meaningful exception
- * @expectedException Exception
- * @expectedExceptionMessage Setting Unique Arguments is not yet supported
- */
- public function testSetUniqueArgs()
- {
- $this->email->setUniqueArgs(array('blah', 'andBlah'));
- }
-
- public function testAddHeader()
- {
- $value = 'My Header';
- $this->email->addHeader('X-header', $value);
-
- $this->assertEquals(array('X-header' => $value), $this->email->model['customHeaders']);
- }
-
- public function testToSparkPostTransmission()
- {
- $this->assertInternalType('array', $this->email->toSparkPostTransmission());
- }
-}
diff --git a/test/unit/SparkPostResponseTest.php b/test/unit/SparkPostResponseTest.php
new file mode 100644
index 0000000..db8600a
--- /dev/null
+++ b/test/unit/SparkPostResponseTest.php
@@ -0,0 +1,136 @@
+<?php
+namespace SparkPost\Test;
+
+use SparkPost\SparkPostResponse;
+use Psr\Http\Message\StreamInterface;
+use Psr\Http\Message\ResponseInterface;
+use Mockery;
+
+class SparkPostResponseTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * (non-PHPdoc).
+ *
+ * @before
+ *
+ * @see PHPUnit_Framework_TestCase::setUp()
+ */
+ public function setUp()
+ {
+ $this->returnValue = 'some_value_to_return';
+ $this->responseMock = Mockery::mock('Psr\Http\Message\ResponseInterface');
+ }
+
+ public function testGetProtocolVersion()
+ {
+ $this->responseMock->shouldReceive('getProtocolVersion')->andReturn($this->returnValue);
+ $sparkpostResponse = new SparkPostResponse($this->responseMock);
+ $this->assertEquals($this->responseMock->getProtocolVersion(), $sparkpostResponse->getProtocolVersion());
+ }
+
+ public function testWithProtocolVersion()
+ {
+ $param = 'protocol version';
+
+ $this->responseMock->shouldReceive('withProtocolVersion')->andReturn($this->returnValue);
+ $sparkpostResponse = new SparkPostResponse($this->responseMock);
+ $this->assertEquals($this->responseMock->withProtocolVersion($param), $sparkpostResponse->withProtocolVersion($param));
+ }
+
+ public function testGetHeaders()
+ {
+ $this->responseMock->shouldReceive('getHeaders')->andReturn($this->returnValue);
+ $sparkpostResponse = new SparkPostResponse($this->responseMock);
+ $this->assertEquals($this->responseMock->getHeaders(), $sparkpostResponse->getHeaders());
+ }
+
+ public function testHasHeader()
+ {
+ $param = 'header';
+
+ $this->responseMock->shouldReceive('hasHeader')->andReturn($this->returnValue);
+ $sparkpostResponse = new SparkPostResponse($this->responseMock);
+ $this->assertEquals($this->responseMock->hasHeader($param), $sparkpostResponse->hasHeader($param));
+ }
+
+ public function testGetHeader()
+ {
+ $param = 'header';
+
+ $this->responseMock->shouldReceive('getHeader')->andReturn($this->returnValue);
+ $sparkpostResponse = new SparkPostResponse($this->responseMock);
+ $this->assertEquals($this->responseMock->getHeader($param), $sparkpostResponse->getHeader($param));
+ }
+
+ public function testGetHeaderLine()
+ {
+ $param = 'header';
+
+ $this->responseMock->shouldReceive('getHeaderLine')->andReturn($this->returnValue);
+ $sparkpostResponse = new SparkPostResponse($this->responseMock);
+ $this->assertEquals($this->responseMock->getHeaderLine($param), $sparkpostResponse->getHeaderLine($param));
+ }
+
+ public function testWithHeader()
+ {
+ $param = 'header';
+ $param2 = 'value';
+
+ $this->responseMock->shouldReceive('withHeader')->andReturn($this->returnValue);
+ $sparkpostResponse = new SparkPostResponse($this->responseMock);
+ $this->assertEquals($this->responseMock->withHeader($param, $param2), $sparkpostResponse->withHeader($param, $param2));
+ }
+
+ public function testWithAddedHeader()
+ {
+ $param = 'header';
+ $param2 = 'value';
+
+
+ $this->responseMock->shouldReceive('withAddedHeader')->andReturn($this->returnValue);
+ $sparkpostResponse = new SparkPostResponse($this->responseMock);
+ $this->assertEquals($this->responseMock->withAddedHeader($param, $param2), $sparkpostResponse->withAddedHeader($param, $param2));
+ }
+
+ public function testWithoutHeader()
+ {
+ $param = 'header';
+
+ $this->responseMock->shouldReceive('withoutHeader')->andReturn($this->returnValue);
+ $sparkpostResponse = new SparkPostResponse($this->responseMock);
+ $this->assertEquals($this->responseMock->withoutHeader($param), $sparkpostResponse->withoutHeader($param));
+ }
+
+ public function testWithBody()
+ {
+ $param = Mockery::mock('Psr\Http\Message\StreamInterface');
+
+ $this->responseMock->shouldReceive('withBody')->andReturn($this->returnValue);
+ $sparkpostResponse = new SparkPostResponse($this->responseMock);
+ $this->assertEquals($this->responseMock->withBody($param), $sparkpostResponse->withBody($param));
+ }
+
+ public function testGetStatusCode()
+ {
+ $this->responseMock->shouldReceive('getStatusCode')->andReturn($this->returnValue);
+ $sparkpostResponse = new SparkPostResponse($this->responseMock);
+ $this->assertEquals($this->responseMock->getStatusCode(), $sparkpostResponse->getStatusCode());
+ }
+
+ public function testWithStatus()
+ {
+ $param = 'status';
+
+ $this->responseMock->shouldReceive('withStatus')->andReturn($this->returnValue);
+ $sparkpostResponse = new SparkPostResponse($this->responseMock);
+ $this->assertEquals($this->responseMock->withStatus($param), $sparkpostResponse->withStatus($param));
+ }
+
+ public function testGetReasonPhrase()
+ {
+ $this->responseMock->shouldReceive('getReasonPhrase')->andReturn($this->returnValue);
+ $sparkpostResponse = new SparkPostResponse($this->responseMock);
+ $this->assertEquals($this->responseMock->getReasonPhrase(), $sparkpostResponse->getReasonPhrase());
+ }
+}
+?> \ No newline at end of file
diff --git a/test/unit/SparkPostTest.php b/test/unit/SparkPostTest.php
index 26563c3..c5dca08 100644
--- a/test/unit/SparkPostTest.php
+++ b/test/unit/SparkPostTest.php
@@ -2,18 +2,43 @@
namespace SparkPost\Test;
-use Ivory\HttpAdapter\CurlHttpAdapter;
-use Mockery;
use SparkPost\SparkPost;
+use SparkPost\SparkPostResponse;
+use SparkPost\SparkPostPromise;
+use Psr\Http\Message\ResponseInterface;
+use Http\Promise\Promise;
+use GuzzleHttp\Promise\Promise as GuzzlePromise;
+use GuzzleHttp\Promise\FulfilledPromise as GuzzleFulfilledPromise;
+use GuzzleHttp\Promise\RejectedPromise as GuzzleRejectedPromise;
+use Http\Adapter\Guzzle6\Promise as GuzzleAdapterPromise;
+use Http\Client\Exception\HttpException;
+use Http\Adapter\Guzzle6\Client;
+use Mockery;
use SparkPost\Test\TestUtils\ClassUtils;
class SparkPostTest extends \PHPUnit_Framework_TestCase
{
private static $utils;
- private $adapterMock;
+ private $clientMock;
/** @var SparkPost */
private $resource;
+ private $postTransmissionPayload = [
+ 'content' => [
+ 'from' => [ 'name' => 'Sparkpost Team', 'email' => 'postmaster@sendmailfor.me' ],
+ 'subject' => 'First Mailing From PHP',
+ 'text' => 'Congratulations, {{name}}!! You just sent your very first mailing!',
+ ],
+ 'substitution_data' => ['name' => 'Avi'],
+ 'recipients' => [
+ ['address' => 'avi.goldman@sparkpost.com']
+ ]
+ ];
+
+ private $getTransmissionPayload = [
+ 'campaign_id' => 'thanksgiving'
+ ];
+
/**
* (non-PHPdoc).
*
@@ -24,14 +49,10 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase
public function setUp()
{
//setup mock for the adapter
- $this->adapterMock = Mockery::mock('Ivory\HttpAdapter\HttpAdapterInterface', function ($mock) {
- $mock->shouldReceive('setConfiguration');
- $mock->shouldReceive('getConfiguration->getUserAgent')->andReturn('php-sparkpost/0.2.0');
- });
+ $this->clientMock = Mockery::mock('Http\Adapter\Guzzle6\Client');
- $this->resource = new SparkPost($this->adapterMock, ['key' => 'a key']);
+ $this->resource = new SparkPost($this->clientMock, ['key' => 'SPARKPOST_API_KEY']);
self::$utils = new ClassUtils($this->resource);
- self::$utils->setProperty($this->resource, 'httpAdapter', $this->adapterMock);
}
public function tearDown()
@@ -39,45 +60,221 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase
Mockery::close();
}
- /**
- * @desc Ensures that the configuration class is not instantiable.
- */
- public function testConstructorSetsUpTransmissions()
+ public function testRequest() {
+ $responseMock = Mockery::mock('Psr\Http\Message\ResponseInterface');
+ $this->resource->setOptions(['async' => false]);
+ $this->resource->httpClient->shouldReceive('sendRequest')->andReturn($responseMock);
+ $this->assertInstanceOf('SparkPost\SparkPostResponse', $this->resource->request('POST', 'transmissions', $this->postTransmissionPayload));
+
+
+ $promiseMock = Mockery::mock('Http\Promise\Promise');
+ $this->resource->setOptions(['async' => true]);
+ $this->resource->httpClient->shouldReceive('sendAsyncRequest')->andReturn($promiseMock);
+ $this->assertInstanceOf('SparkPost\SparkPostPromise', $this->resource->request('GET', 'transmissions', $this->getTransmissionPayload));
+ }
+
+ public function testSuccessfulSyncRequest()
{
- $sparky = new SparkPost(new CurlHttpAdapter(), ['key' => 'a key']);
- $this->assertEquals('SparkPost\Transmission', get_class($sparky->transmission));
- $adapter = self::$utils->getProperty($this->resource, 'httpAdapter');
- $this->assertRegExp('/php-sparkpost.*/', $adapter->getConfiguration()->getUserAgent());
+ $responseMock = Mockery::mock('Psr\Http\Message\ResponseInterface');
+ $responseBodyMock = Mockery::mock();
+
+ $responseBody = ['results' => 'yay'];
+
+ $this->resource->httpClient->shouldReceive('sendRequest')->
+ once()->
+ with(Mockery::type('GuzzleHttp\Psr7\Request'))->
+ andReturn($responseMock);
+
+ $responseMock->shouldReceive('getStatusCode')->andReturn(200);
+ $responseMock->shouldReceive('getBody')->andReturn($responseBodyMock);
+ $responseBodyMock->shouldReceive('__toString')->andReturn(json_encode($responseBody));
+
+ $response = $this->resource->syncRequest('POST', 'transmissions', $this->postTransmissionPayload);
+
+ $this->assertEquals($responseBody, $response->getBody());
+ $this->assertEquals(200, $response->getStatusCode());
+ }
+
+ public function testUnsuccessfulSyncRequest()
+ {
+ $exceptionMock = Mockery::mock('Http\Client\Exception\HttpException');
+
+ $responseBody = ['results' => 'failed'];
+
+ $this->resource->httpClient->shouldReceive('sendRequest')->
+ once()->
+ with(Mockery::type('GuzzleHttp\Psr7\Request'))->
+ andThrow($exceptionMock);
+
+ $exceptionMock->shouldReceive('getResponse->getStatusCode')->andReturn(500);
+ $exceptionMock->shouldReceive('getResponse->getBody->__toString')->andReturn(json_encode($responseBody));
+
+ try {
+ $this->resource->syncRequest('POST', 'transmissions', $this->postTransmissionPayload);
+ } catch (\Exception $e) {
+ $this->assertEquals($responseBody, $e->getBody());
+ $this->assertEquals(500, $e->getCode());
+ }
}
- public function testSetConfigStringKey()
+ public function testSuccessfulAsyncRequestWithWait()
{
- $this->resource->setConfig('a key');
- $config = self::$utils->getProperty($this->resource, 'config');
- $this->assertEquals('a key', $config['key']);
+ $promiseMock = Mockery::mock('Http\Promise\Promise');
+ $responseMock = Mockery::mock('Psr\Http\Message\ResponseInterface');
+ $responseBodyMock = Mockery::mock();
+
+ $responseBody = ['results' => 'yay'];
+
+ $this->resource->httpClient->shouldReceive('sendAsyncRequest')->
+ once()->
+ with(Mockery::type('GuzzleHttp\Psr7\Request'))->
+ andReturn($promiseMock);
+
+ $promiseMock->shouldReceive('wait')->andReturn($responseMock);
+
+ $responseMock->shouldReceive('getStatusCode')->andReturn(200);
+ $responseMock->shouldReceive('getBody')->andReturn($responseBodyMock);
+ $responseBodyMock->shouldReceive('__toString')->andReturn(json_encode($responseBody));
+
+ $promise = $this->resource->asyncRequest('POST', 'transmissions', $this->postTransmissionPayload);
+
+ $response = $promise->wait();
+
+ $this->assertEquals($responseBody, $response->getBody());
+ $this->assertEquals(200, $response->getStatusCode());
+ }
+
+ public function testUnsuccessfulAsyncRequestWithWait()
+ {
+ $promiseMock = Mockery::mock('Http\Promise\Promise');
+ $exceptionMock = Mockery::mock('Http\Client\Exception\HttpException');
+
+ $responseBody = ['results' => 'failed'];
+
+ $this->resource->httpClient->shouldReceive('sendAsyncRequest')->
+ once()->
+ with(Mockery::type('GuzzleHttp\Psr7\Request'))->
+ andReturn($promiseMock);
+
+ $promiseMock->shouldReceive('wait')->andThrow($exceptionMock);
+
+ $exceptionMock->shouldReceive('getResponse->getStatusCode')->andReturn(500);
+ $exceptionMock->shouldReceive('getResponse->getBody->__toString')->andReturn(json_encode($responseBody));
+
+ $promise = $this->resource->asyncRequest('POST', 'transmissions', $this->postTransmissionPayload);
+
+ try {
+ $response = $promise->wait();
+ } catch (\Exception $e) {
+ $this->assertEquals($responseBody, $e->getBody());
+ $this->assertEquals(500, $e->getCode());
+ }
+ }
+
+ public function testSuccessfulAsyncRequestWithThen() {
+ $responseBody = ['results' => 'yay'];
+ $responseMock = Mockery::mock('Psr\Http\Message\ResponseInterface');
+ $responseBodyMock = Mockery::mock();
+ $responseMock->shouldReceive('getStatusCode')->andReturn(200);
+ $responseMock->shouldReceive('getBody')->andReturn($responseBodyMock);
+ $responseBodyMock->shouldReceive('__toString')->andReturn(json_encode($responseBody));
+
+ $guzzlePromise = new GuzzleFulfilledPromise($responseMock);
+
+ $promise = new SparkPostPromise(new GuzzleAdapterPromise($guzzlePromise, $this->resource->buildRequest('POST', 'transmissions', $this->postTransmissionPayload, [])));
+
+ $promise->then(function ($exception) use ($responseBody) {
+ $this->assertEquals(200, $exception->getStatusCode());
+ $this->assertEquals($responseBody, $exception->getBody());
+ }, null)->wait();
+ }
+
+ public function testUnsuccessfulAsyncRequestWithThen() {
+ $responseBody = ['results' => 'failed'];
+ $exceptionMock = Mockery::mock('Http\Client\Exception\HttpException');
+ $exceptionMock->shouldReceive('getResponse->getStatusCode')->andReturn(500);
+ $exceptionMock->shouldReceive('getResponse->getBody->__toString')->andReturn(json_encode($responseBody));
+
+ $guzzlePromise = new GuzzleRejectedPromise($exceptionMock);
+
+ $promise = new SparkPostPromise(new GuzzleAdapterPromise($guzzlePromise, $this->resource->buildRequest('POST', 'transmissions', $this->postTransmissionPayload, [])));
+
+ $promise->then(null, function ($exception) use ($responseBody) {
+ $this->assertEquals(500, $exception->getCode());
+ $this->assertEquals($responseBody, $exception->getBody());
+ })->wait();
+ }
+
+ public function testPromise()
+ {
+ $promiseMock = Mockery::mock('Http\Promise\Promise');
+
+ $this->resource->httpClient->shouldReceive('sendAsyncRequest')->
+ once()->
+ with(Mockery::type('GuzzleHttp\Psr7\Request'))->
+ andReturn($promiseMock);
+
+ $promise = $this->resource->asyncRequest('POST', 'transmissions', $this->postTransmissionPayload);
+
+ $promiseMock->shouldReceive('getState')->twice()->andReturn('pending');
+ $this->assertEquals($promiseMock->getState(), $promise->getState());
+
+ $promiseMock->shouldReceive('getState')->once()->andReturn('rejected');
+ $this->assertEquals('rejected', $promise->getState());
}
/**
* @expectedException Exception
- * @expectedExceptionMessageRegExp /API key/
*/
- public function testSetBadConfig()
+ public function testUnsupportedAsyncRequest()
{
- $this->resource->setConfig(['not' => 'a key']);
+
+ $this->resource->setHttpClient(Mockery::mock('Http\Client\HttpClient'));
+
+ $this->resource->asyncRequest('POST', 'transmissions', $this->postTransmissionPayload);
+ }
+
+ public function testGetHttpHeaders()
+ {
+ $headers = $this->resource->getHttpHeaders([
+ 'Custom-Header' => 'testing'
+ ]);
+
+ $version = self::$utils->getProperty($this->resource, 'version');
+
+ $this->assertEquals('SPARKPOST_API_KEY', $headers['Authorization']);
+ $this->assertEquals('application/json', $headers['Content-Type']);
+ $this->assertEquals('testing', $headers['Custom-Header']);
+ $this->assertEquals('php-sparkpost/'.$version, $headers['User-Agent']);
+ }
+
+ public function testGetUrl()
+ {
+ $url = 'https://api.sparkpost.com:443/api/v1/transmissions?key=value 1,value 2,value 3';
+ $testUrl = $this->resource->getUrl('transmissions', ['key' => ['value 1', 'value 2', 'value 3']]);
+ $this->assertEquals($url, $testUrl);
+ }
+
+ public function testSetHttpClient()
+ {
+ $this->resource->setHttpClient($this->clientMock);
+ $this->assertEquals($this->clientMock, self::$utils->getProperty($this->resource, 'httpClient'));
}
- public function testGetHeaders()
+ public function testSetOptionsStringKey()
{
- $results = $this->resource->getHttpHeaders();
- $this->assertEquals('a key', $results['Authorization']);
- $this->assertEquals('application/json', $results['Content-Type']);
+ $this->resource->setOptions('SPARKPOST_API_KEY');
+ $options = self::$utils->getProperty($this->resource, 'options');
+ $this->assertEquals('SPARKPOST_API_KEY', $options['key']);
}
- public function testSetUnwrapped()
+ /**
+ * @expectedException Exception
+ */
+ public function testSetBadOptions()
{
- $results = $this->resource->setupUnwrapped('ASweetEndpoint');
- $this->assertEquals($this->resource->ASweetEndpoint, $results);
- $this->assertInstanceOf('SparkPost\APIResource', $results);
- $this->assertEquals('ASweetEndpoint', $results->endpoint);
+ self::$utils->setProperty($this->resource, 'options', []);
+ $this->resource->setOptions(['not' => 'SPARKPOST_API_KEY']);
}
+
}
diff --git a/test/unit/TransmissionTest.php b/test/unit/TransmissionTest.php
deleted file mode 100644
index d606c53..0000000
--- a/test/unit/TransmissionTest.php
+++ /dev/null
@@ -1,114 +0,0 @@
-<?php
-
-namespace SparkPost\Test;
-
-use SparkPost\Transmission;
-use SparkPost\Test\TestUtils\ClassUtils;
-use Mockery;
-
-class TransmissionTest extends \PHPUnit_Framework_TestCase
-{
- private static $utils;
- private $sparkPostMock;
- private $resource;
-
- /**
- * (non-PHPdoc).
- *
- * @before
- *
- * @see PHPUnit_Framework_TestCase::setUp()
- */
- public function setUp()
- {
- $this->sparkPostMock = Mockery::mock('SparkPost\SparkPost', function ($mock) {
- $mock->shouldReceive('getHttpHeaders')->andReturn([]);
- });
- $this->sparkPostMock->httpAdapter = Mockery::mock();
- $this->resource = new Transmission($this->sparkPostMock);
- self::$utils = new ClassUtils($this->resource);
- }
-
- public function tearDown()
- {
- Mockery::close();
- }
-
- public function testSend()
- {
- $responseMock = Mockery::mock();
- $body = ['text' => 'awesomesauce', 'content' => ['subject' => 'awesomeness']];
- $responseBody = ['results' => 'yay'];
-
- $this->sparkPostMock->httpAdapter->shouldReceive('send')->
- once()->
- with('/.*\/transmissions/', 'POST', Mockery::type('array'), Mockery::type('string'))->
- andReturn($responseMock);
- $responseMock->shouldReceive('getStatusCode')->andReturn(200);
-
- $responseMock->shouldReceive('getBody->getContents')->andReturn(json_encode($responseBody));
-
- $this->assertEquals($responseBody, $this->resource->send($body));
- }
-
- public function testSendDateTimeConversion()
- {
- $testStartTime = new \DateTime('2016-08-27 13:01:02', new \DateTimeZone('UTC'));
-
- $responseMock = Mockery::mock();
- $responseBody = ['results' => 'yay'];
- $this->sparkPostMock->httpAdapter->shouldReceive('send')->
- once()->
- with('/.*\/transmissions/', 'POST', Mockery::type('array'), matchesPattern('/"start_time":"2016-08-27T13:01:02\+00:00"/'))->
- andReturn($responseMock);
- $responseMock->shouldReceive('getStatusCode')->andReturn(200);
- $responseMock->shouldReceive('getBody->getContents')->andReturn(json_encode($responseBody));
-
- $this->assertEquals($responseBody, $this->resource->send(['startTime' => $testStartTime]));
- }
-
- public function testAllWithFilter()
- {
- $responseMock = Mockery::mock();
- $responseBody = ['results' => 'yay'];
- $this->sparkPostMock->httpAdapter->shouldReceive('send')->
- once()->
- with('/.*transmissions.*?campaign_id=campaign&template_id=template/', 'GET', Mockery::type('array'), null)->
- andReturn($responseMock);
- $responseMock->shouldReceive('getStatusCode')->andReturn(200);
-
- $responseMock->shouldReceive('getBody->getContents')->andReturn(json_encode($responseBody));
-
- $this->assertEquals($responseBody, $this->resource->all('campaign', 'template'));
- }
-
- public function testAllWithOutFilter()
- {
- $responseMock = Mockery::mock();
- $responseBody = ['results' => 'yay'];
- $this->sparkPostMock->httpAdapter->shouldReceive('send')->
- once()->
- with('/.*\/transmissions/', 'GET', Mockery::type('array'), null)->
- andReturn($responseMock);
- $responseMock->shouldReceive('getStatusCode')->andReturn(200);
-
- $responseMock->shouldReceive('getBody->getContents')->andReturn(json_encode($responseBody));
-
- $this->assertEquals($responseBody, $this->resource->all());
- }
-
- public function testFind()
- {
- $responseMock = Mockery::mock();
- $responseBody = ['results' => 'yay'];
- $this->sparkPostMock->httpAdapter->shouldReceive('send')->
- once()->
- with('/.*\/transmissions.*\/test/', 'GET', Mockery::type('array'), null)->
- andReturn($responseMock);
- $responseMock->shouldReceive('getStatusCode')->andReturn(200);
-
- $responseMock->shouldReceive('getBody->getContents')->andReturn(json_encode($responseBody));
-
- $this->assertEquals($responseBody, $this->resource->find('test'));
- }
-}