diff options
20 files changed, 1007 insertions, 116 deletions
diff --git a/RoboFile.php b/RoboFile.php index 592e7ae..9b7df90 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -10,7 +10,7 @@ class RoboFile extends \Robo\Tasks // $coverage = new PHP_CodeCoverage(); // $coverage->start('PHP-SDK Unit Tests'); // $this->taskPHPUnit('./test/unit/')->run(); - $res = $this->taskExec('phpunit --coverage-html test/output/report --bootstrap ./vendor/autoload.php ./test/unit')->run(); + $res = $this->taskExec('phpunit --coverage-html test/output/report --bootstrap test/unit/bootstrap.php ./test/unit')->run(); // print message when tests passed if ($res->wasSuccessful()) $this->say("All tests passed"); diff --git a/composer.json b/composer.json index bab9bac..a2f5c40 100644 --- a/composer.json +++ b/composer.json @@ -18,10 +18,9 @@ "codegyre/robo": "0.4.6" }, "autoload": { - "psr-0": { - "MessageSystems": "lib/", - "SparkPost": "index.php" - + "psr-4": { + "MessageSystems\\": "lib/MessageSystems/", + "SparkPost\\": "lib/" } } } diff --git a/composer.lock b/composer.lock index ef3132f..7b617f6 100644 --- a/composer.lock +++ b/composer.lock @@ -3,7 +3,7 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "d5f1714c86afc4c3ef134d8a2f39b529", + "hash": "25bb67c57c5a357f0cc9873a717dfd51", "packages": [ { "name": "guzzlehttp/guzzle", @@ -65,16 +65,16 @@ }, { "name": "guzzlehttp/ringphp", - "version": "1.0.0", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/guzzle/RingPHP.git", - "reference": "9e44b565d726d9614cd970319e6eea70ee15bff3" + "reference": "bdb67d6da3e2af33dee5c85c971203d4503c8540" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/RingPHP/zipball/9e44b565d726d9614cd970319e6eea70ee15bff3", - "reference": "9e44b565d726d9614cd970319e6eea70ee15bff3", + "url": "https://api.github.com/repos/guzzle/RingPHP/zipball/bdb67d6da3e2af33dee5c85c971203d4503c8540", + "reference": "bdb67d6da3e2af33dee5c85c971203d4503c8540", "shasum": "" }, "require": { @@ -111,7 +111,7 @@ "homepage": "https://github.com/mtdowling" } ], - "time": "2014-10-13 00:59:38" + "time": "2014-10-26 21:10:50" }, { "name": "guzzlehttp/streams", @@ -622,16 +622,16 @@ }, { "name": "phpunit/phpunit", - "version": "4.3.3", + "version": "4.3.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "5a0bc4dcbb7340c0a9a9bc3507854a67c564edc4" + "reference": "23e4e0310f037aae873cc81b8658dbbb82878f71" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/5a0bc4dcbb7340c0a9a9bc3507854a67c564edc4", - "reference": "5a0bc4dcbb7340c0a9a9bc3507854a67c564edc4", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/23e4e0310f037aae873cc81b8658dbbb82878f71", + "reference": "23e4e0310f037aae873cc81b8658dbbb82878f71", "shasum": "" }, "require": { @@ -642,7 +642,7 @@ "ext-spl": "*", "php": ">=5.3.3", "phpunit/php-code-coverage": "~2.0", - "phpunit/php-file-iterator": "~1.3.1", + "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", @@ -692,7 +692,7 @@ "testing", "xunit" ], - "time": "2014-10-16 16:53:00" + "time": "2014-10-22 11:43:12" }, { "name": "phpunit/phpunit-mock-objects", @@ -867,16 +867,16 @@ }, { "name": "sebastian/environment", - "version": "1.1.0", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "6288ebbf6fa3ed2b2ff2d69c356fbaaf4f0971a7" + "reference": "0d9bf79554d2a999da194a60416c15cf461eb67d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/6288ebbf6fa3ed2b2ff2d69c356fbaaf4f0971a7", - "reference": "6288ebbf6fa3ed2b2ff2d69c356fbaaf4f0971a7", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/0d9bf79554d2a999da194a60416c15cf461eb67d", + "reference": "0d9bf79554d2a999da194a60416c15cf461eb67d", "shasum": "" }, "require": { @@ -888,7 +888,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.1.x-dev" + "dev-master": "1.2.x-dev" } }, "autoload": { @@ -913,7 +913,7 @@ "environment", "hhvm" ], - "time": "2014-10-07 09:23:16" + "time": "2014-10-22 06:38:05" }, { "name": "sebastian/exporter", @@ -1017,7 +1017,7 @@ }, { "name": "symfony/config", - "version": "v2.5.5", + "version": "v2.5.6", "target-dir": "Symfony/Component/Config", "source": { "type": "git", @@ -1065,17 +1065,17 @@ }, { "name": "symfony/console", - "version": "v2.5.5", + "version": "v2.5.6", "target-dir": "Symfony/Component/Console", "source": { "type": "git", "url": "https://github.com/symfony/Console.git", - "reference": "ca053eaa031c93afb68a71e4eb1f4168dfd4a661" + "reference": "6f177fca24200a5b97aef5ce7a5c98124a0f0db0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Console/zipball/ca053eaa031c93afb68a71e4eb1f4168dfd4a661", - "reference": "ca053eaa031c93afb68a71e4eb1f4168dfd4a661", + "url": "https://api.github.com/repos/symfony/Console/zipball/6f177fca24200a5b97aef5ce7a5c98124a0f0db0", + "reference": "6f177fca24200a5b97aef5ce7a5c98124a0f0db0", "shasum": "" }, "require": { @@ -1116,21 +1116,21 @@ ], "description": "Symfony Console Component", "homepage": "http://symfony.com", - "time": "2014-09-25 09:53:56" + "time": "2014-10-05 13:57:04" }, { "name": "symfony/event-dispatcher", - "version": "v2.5.5", + "version": "v2.5.6", "target-dir": "Symfony/Component/EventDispatcher", "source": { "type": "git", "url": "https://github.com/symfony/EventDispatcher.git", - "reference": "f6281337bf5f985f585d1db6a83adb05ce531f46" + "reference": "804eb28dbbfba9ffdab21fe2066744906cea2212" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/f6281337bf5f985f585d1db6a83adb05ce531f46", - "reference": "f6281337bf5f985f585d1db6a83adb05ce531f46", + "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/804eb28dbbfba9ffdab21fe2066744906cea2212", + "reference": "804eb28dbbfba9ffdab21fe2066744906cea2212", "shasum": "" }, "require": { @@ -1173,11 +1173,11 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "http://symfony.com", - "time": "2014-09-28 15:56:11" + "time": "2014-10-01 15:43:05" }, { "name": "symfony/filesystem", - "version": "v2.5.5", + "version": "v2.5.6", "target-dir": "Symfony/Component/Filesystem", "source": { "type": "git", @@ -1224,17 +1224,17 @@ }, { "name": "symfony/finder", - "version": "v2.5.5", + "version": "v2.5.6", "target-dir": "Symfony/Component/Finder", "source": { "type": "git", "url": "https://github.com/symfony/Finder.git", - "reference": "d5033742b9a6206ef6d06e813870bca18e9205df" + "reference": "cf66df4e783e6aade319b273c9bcf9e42aa9b10f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Finder/zipball/d5033742b9a6206ef6d06e813870bca18e9205df", - "reference": "d5033742b9a6206ef6d06e813870bca18e9205df", + "url": "https://api.github.com/repos/symfony/Finder/zipball/cf66df4e783e6aade319b273c9bcf9e42aa9b10f", + "reference": "cf66df4e783e6aade319b273c9bcf9e42aa9b10f", "shasum": "" }, "require": { @@ -1267,21 +1267,21 @@ ], "description": "Symfony Finder Component", "homepage": "http://symfony.com", - "time": "2014-09-27 08:35:39" + "time": "2014-10-01 05:50:18" }, { "name": "symfony/process", - "version": "v2.5.5", + "version": "v2.5.6", "target-dir": "Symfony/Component/Process", "source": { "type": "git", "url": "https://github.com/symfony/Process.git", - "reference": "8a1ec96c4e519cee0fb971ea48a1eb7369dda54b" + "reference": "9bbacbb3a7a27b17c0d51e2f126f59e0e588ad3a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Process/zipball/8a1ec96c4e519cee0fb971ea48a1eb7369dda54b", - "reference": "8a1ec96c4e519cee0fb971ea48a1eb7369dda54b", + "url": "https://api.github.com/repos/symfony/Process/zipball/9bbacbb3a7a27b17c0d51e2f126f59e0e588ad3a", + "reference": "9bbacbb3a7a27b17c0d51e2f126f59e0e588ad3a", "shasum": "" }, "require": { @@ -1314,21 +1314,21 @@ ], "description": "Symfony Process Component", "homepage": "http://symfony.com", - "time": "2014-09-23 05:25:11" + "time": "2014-10-01 05:50:18" }, { "name": "symfony/yaml", - "version": "v2.5.5", + "version": "v2.5.6", "target-dir": "Symfony/Component/Yaml", "source": { "type": "git", "url": "https://github.com/symfony/Yaml.git", - "reference": "b1dbc53593b98c2d694ebf383660ac9134d30b96" + "reference": "2d9f527449cabfa8543dd7fa3a466d6ae83d6726" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/b1dbc53593b98c2d694ebf383660ac9134d30b96", - "reference": "b1dbc53593b98c2d694ebf383660ac9134d30b96", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/2d9f527449cabfa8543dd7fa3a466d6ae83d6726", + "reference": "2d9f527449cabfa8543dd7fa3a466d6ae83d6726", "shasum": "" }, "require": { @@ -1361,7 +1361,7 @@ ], "description": "Symfony Yaml Component", "homepage": "http://symfony.com", - "time": "2014-09-22 09:14:18" + "time": "2014-10-01 05:50:18" } ], "aliases": [], diff --git a/examples/bootstrap.php b/examples/bootstrap.php new file mode 100644 index 0000000..8a5f839 --- /dev/null +++ b/examples/bootstrap.php @@ -0,0 +1,3 @@ +<?php + require_once dirname(__FILE__).'/../vendor/autoload.php'; +?>
\ No newline at end of file diff --git a/examples/transmission/configuration_based.php b/examples/transmission/configuration_based.php new file mode 100644 index 0000000..374f446 --- /dev/null +++ b/examples/transmission/configuration_based.php @@ -0,0 +1,31 @@ +<?php +namespace Examples\Transmisson; + require_once (dirname(__FILE__).'/../bootstrap.php'); + + use SparkPost\SparkPost; + + $key = 'YOURAPIKEY'; + $sdk = new SparkPost(['key'=>$key]); + + $transmission = $sdk->Transmission([ + "return_path"=>"return@example.com", + "from"=>"From Envelope <from@example.com>", + "html"=>"<p>Hello World!</p>", + "text"=>"Hello World!", + "subject"=>"Example Email", + "recipients"=>[ + [ + "address"=>[ + "email"=>"john.doe@sample.com" + ] + ] + ] + ]); + + try { + $results = $transmission->send(); + echo 'Congrats you can use your SDK!'; + } catch (\Exception $exception) { + echo $exception->getMessage(); + } +?>
\ No newline at end of file diff --git a/examples/transmission/get_all_transmissions.php b/examples/transmission/get_all_transmissions.php new file mode 100644 index 0000000..9ffc2fd --- /dev/null +++ b/examples/transmission/get_all_transmissions.php @@ -0,0 +1,18 @@ +<?php +namespace Examples\Transmisson; + require_once (dirname(__FILE__).'/../bootstrap.php'); + + use SparkPost\SparkPost; + + $key = 'YOURAPIKEY'; + $sdk = new SparkPost(['key'=>$key]); + + $transmission = $sdk->Transmission(); + + try { + $results = $transmission->all(); + echo 'Congrats you can use your SDK!'; + } catch (\Exception $exception) { + echo $exception->getMessage(); + } +?>
\ No newline at end of file diff --git a/examples/transmission/get_transmission.php b/examples/transmission/get_transmission.php new file mode 100644 index 0000000..86e9f0f --- /dev/null +++ b/examples/transmission/get_transmission.php @@ -0,0 +1,17 @@ +<?php +namespace Examples\Transmisson; +require_once (dirname(__FILE__).'/../bootstrap.php'); +use SparkPost\SparkPost; + +$key = 'YOURAPIKEY'; +$sdk = new SparkPost(['key'=>$key]); + +$transmission = $sdk->Transmission(); + +try { + $results = $transmission->find('11860038888980495'); + echo 'Congrats you can use your SDK!'; +} catch (\Exception $exception) { + echo $exception->getMessage(); +} +?>
\ No newline at end of file diff --git a/examples/transmission/mime_parts.php b/examples/transmission/mime_parts.php new file mode 100644 index 0000000..2b68b46 --- /dev/null +++ b/examples/transmission/mime_parts.php @@ -0,0 +1,29 @@ +<?php +namespace Examples\Transmisson; +require_once (dirname(__FILE__).'/../bootstrap.php'); +use SparkPost\SparkPost; + +$key = 'YOURAPIKEY'; +$sdk = new SparkPost(['key'=>$key]); + +$transmission = $sdk->Transmission(); + +$transmission->setReturnPath('return@example.com') + ->setFrom('From Envelope <from@example.com>') + ->addRecipient([ + 'address'=> [ + 'email'=> 'john.doe@sample.com' + ] + ]) + ->setSubject('Example Email') + ->setHTMLContent('<p>Hello World!</p>') + ->setTextContent('Hello World!'); + + +try { + $results = $transmission->send(); + echo 'Congrats you can use your SDK!'; +} catch (\Exception $exception) { + echo $exception->getMessage(); +} +?>
\ No newline at end of file diff --git a/examples/transmission/rfc822.php b/examples/transmission/rfc822.php new file mode 100644 index 0000000..58c62cc --- /dev/null +++ b/examples/transmission/rfc822.php @@ -0,0 +1,28 @@ +<?php +namespace Examples\Transmisson; +require_once (dirname(__FILE__).'/../bootstrap.php'); +use SparkPost\SparkPost; + +$key = 'YOURAPIKEY'; +$sdk = new SparkPost(['key'=>$key]); + + + +$transmission = $sdk->Transmission(); + +$transmission->setReturnPath('return@example.com') + ->addRecipient([ + 'address'=>[ + 'email'=>'john.doe@sample.com' + ] + ]) + ->setRfc822Content("Content-Type: text/plain\nFrom: From Envelope <from@example.com>\nSubject: Example Email\n\nHello World"); + + +try { + $results = $transmission->send(); + echo 'Congrats you can use your SDK!'; +} catch (\Exception $exception) { + echo $exception->getMessage(); +} +?>
\ No newline at end of file diff --git a/examples/transmission/send_transmission_all_fields.php b/examples/transmission/send_transmission_all_fields.php new file mode 100644 index 0000000..5aec6b8 --- /dev/null +++ b/examples/transmission/send_transmission_all_fields.php @@ -0,0 +1,47 @@ +<?php +namespace Examples\Transmisson; +require_once (dirname(__FILE__).'/../bootstrap.php'); +use SparkPost\SparkPost; + +$key = 'YOURAPIKEY'; +$sdk = new SparkPost(['key'=>$key]); + + + +$transmission = $sdk->Transmission([ + "campaign"=>"my-campaign", + "metadata"=>[ + "sample_campaign"=>true, + "type"=>"these are custom fields" + ], + "substitutionData"=>[ + "name"=>"Test Name" + ], + "description"=>"my description", + "return_path"=>"return@example.com", + "replyTo"=>"reply@test.com", + "headers"=>[ + "X-Custom-Header"=>"Sample Custom Header" + ], + "openTracking"=>false, + "clickTracking"=>false, + "from"=>"From Envelope <from@example.com>", + "html"=>"<p>Hello World! Your name is: {{name}}</p>", + "text"=>"Hello World!", + "subject"=>"Example Email: {{name}}", + "recipients"=>[ + [ + "address"=>[ + "email"=>"john.doe@sample.com" + ] + ] + ] +]); + +try { + $results = $transmission->send(); + echo 'Congrats you can use your SDK!'; +} catch (\Exception $exception) { + echo $exception->getMessage(); +} +?>
\ No newline at end of file diff --git a/examples/transmission/send_transmission_all_fields_method_based.php b/examples/transmission/send_transmission_all_fields_method_based.php new file mode 100644 index 0000000..0f3314b --- /dev/null +++ b/examples/transmission/send_transmission_all_fields_method_based.php @@ -0,0 +1,45 @@ +<?php +namespace Examples\Transmisson; +require_once (dirname(__FILE__).'/../bootstrap.php'); +use SparkPost\SparkPost; + +$key = 'YOURAPIKEY'; +$sdk = new SparkPost(['key'=>$key]); + + + +$transmission = $sdk->Transmission(); + +$transmission->setCampaign('my campaign') + ->setMetadata([ + "sample_campaign"=>"true", + "type"=>"test type meta data" + ]) + ->setSubstitutionData([ + "name"=>"Test Name" + ]) + ->setDescription('My Description') + ->setReturnPath('return@example.com') + ->setReplyTo('reply@test.com') + ->setContentHeaders([ + "X-Custom-Header"=>"Sample Custom Header" + ]) + ->disableOpenTracking() + ->disableClickTracking() + ->setFrom('From Envelope <from@example.com>') + ->addRecipient([ + "address"=> [ + "email"=>"john.doe@sample.com" + ] + ]) + ->setSubject('Example Email: {{name}}') + ->setHTMLContent('<p>Hello World! Your name is: {{name}}</p>') + ->setTextContent('Hello World!'); + + +try { + $results = $transmission->send(); + echo 'Congrats you can use your SDK!'; +} catch (\Exception $exception) { + echo $exception->getMessage(); +}
\ No newline at end of file diff --git a/examples/transmission/stored_recipients_inline_content.php b/examples/transmission/stored_recipients_inline_content.php new file mode 100644 index 0000000..8dccdda --- /dev/null +++ b/examples/transmission/stored_recipients_inline_content.php @@ -0,0 +1,27 @@ +<?php +namespace Examples\Transmisson; +require_once (dirname(__FILE__).'/../bootstrap.php'); +use SparkPost\SparkPost; + +$key = 'YOURAPIKEY'; +$sdk = new SparkPost(['key'=>$key]); + + + +$transmission = $sdk->Transmission(); + +$transmission->setCampaign('my campaign') + ->setReturnPath('return@example.com') + ->setFrom('From Envelope <from@example.com>') + ->useRecipientList('Example List') + ->setSubject('Example Email') + ->setHTMLContent('<p>Hello World!</p>') + ->setTextContent('Hello World!'); + +try { + $results = $transmission->send(); + echo 'Congrats you can use your SDK!'; +} catch (\Exception $exception) { + echo $exception->getMessage(); +} +?>
\ No newline at end of file diff --git a/examples/transmission/stored_template_send.php b/examples/transmission/stored_template_send.php new file mode 100644 index 0000000..7a0e784 --- /dev/null +++ b/examples/transmission/stored_template_send.php @@ -0,0 +1,29 @@ +<?php +namespace Examples\Transmisson; +require_once (dirname(__FILE__).'/../bootstrap.php'); +use SparkPost\SparkPost; + + +$key = 'YOURAPIKEY'; +$sdk = new SparkPost(['key'=>$key]); + + + +$transmission = $sdk->Transmission(); + +$transmission->setReturnPath('return@example.com') + ->setFrom('From Envelope <from@example.com>') + ->addRecipient([ + "address"=>[ + "email"=>"john.doe@sample.com" + ] + ]) + ->useStoredTemplate('my-template'); + +try { + $results = $transmission->send(); + echo 'Congrats you can use your SDK!'; +} catch (\Exception $exception) { + echo $exception->getMessage(); +} +?>
\ No newline at end of file diff --git a/lib/MessageSystems/SendGridCompatibility/Email.php b/lib/MessageSystems/SendGridCompatibility/Email.php new file mode 100644 index 0000000..68c94b7 --- /dev/null +++ b/lib/MessageSystems/SendGridCompatibility/Email.php @@ -0,0 +1,84 @@ +<?php +namespace MessageSystems\SendGridCompatibility; + +use MessageSystems\Transmission; + +class Email { + private $transmission; + + public function __construct() { + $this->transmission = new Transmission(); + } + + public function send() { + $this->transmission->send(); + } + + public function addTo($address) { + $this->transmission->addRecipient($address); + return $this; + } + + public function setTos(Array $addresses) { + $this->transmission->addRecipients($addresses); + return $this; + } + + /** + * + * @param string $address + * @return \MessageSystems\SendGridCompatibility\Email + */ + public function setFrom($address) { + $this->transmission->setFrom($address); + return $this; + } + + /** + * TODO:figure this out + * @param string $name + */ + public function setFromName($name) { + + return $this; + } + + + /** + * + * @param string $address + * @return \MessageSystems\SendGridCompatibility\Email + */ + public function setReplyTo($address) { + $this->transmission->setReplyTo($address); + return $this; + } + + /** + * TODO: Does this work? + * + * + * @param string $address + * @return \MessageSystems\SendGridCompatibility\Email + */ + public function addBcc($address) { + $this->transmission->addRecipient($address); + return $this; + } + + public function setSubject($subject) { + $this->transmission->setSubject($subject); + return $this; + } + + public function setText($text) { + $this->transmission->setTextContent($text); + return $this; + } + + public function setHtml($html) { + $this->transmission->setHTMLContent($html); + return $this; + } +} +?>
\ No newline at end of file diff --git a/lib/MessageSystems/SendGridCompatibility/SDK.php b/lib/MessageSystems/SendGridCompatibility/SDK.php new file mode 100644 index 0000000..f1a4df3 --- /dev/null +++ b/lib/MessageSystems/SendGridCompatibility/SDK.php @@ -0,0 +1,24 @@ +<?php +namespace MessageSystems\SendGridCompatibility; + +use MessageSystems\Transmission; +use MessageSystems\SendGridCompatibility\Email; +use MessageSystems\Configuration; + +class SDK{ + private $sparkPost; + + public function __construct($username, $password, $options = null) { + //username isn't used in our system + $opts = ['key'=>$password]; + if (!is_null($options)) { + $opts = array_merge($opts, $options); + } + Configuration::setConfig($opts); + } + + public function send(Email $email) { + $email->send(); + } +} +?>
\ No newline at end of file diff --git a/lib/MessageSystems/Transmission.php b/lib/MessageSystems/Transmission.php index 513efac..294ec01 100644 --- a/lib/MessageSystems/Transmission.php +++ b/lib/MessageSystems/Transmission.php @@ -3,14 +3,65 @@ namespace MessageSystems; use GuzzleHttp\Client; use GuzzleHttp\Exception\RequestException; +/** + * @desc SDK interface for managing transmissions + */ class Transmission { private $model; private $config; private $request; + private $parameterMappings = [ + 'campaign'=>'setCampaign', + 'metadata'=>'setMetadata', + 'substitutionData'=>'setSubstitutionData', + 'description'=>'setDescription', + 'returnPath'=>'setReturnPath', + 'replyTo'=>'setReplyTo', + 'subject'=>'setSubject', + 'from'=>'setFrom', + 'html'=>'setHTMLContent', + 'text'=>'setTextContent', + 'rfc822Part'=>'setRfc822Content', + 'headers'=>'setContentHeaders', + 'recipients'=>'addRecipients', + 'recipientList'=>'useRecipientList', + 'template'=>'useStoredTemplate', + 'openTracking'=>1, + 'clickTracking'=>1, + 'useDraftTemplate'=>1 + ]; + /** + * @desc Sets up an object for managaging Transmissions + * + * Please note that key values that can be specified are: + * - campaign + * - metadata + * - substitutionData + * - description + * - returnPath + * - replyTo + * - subject + * - from + * - html + * - text + * - rfc822Part + * - headers + * - recipients + * - recipientList + * - template + * - openTracking + * - clickTracking + * - useDraftTemplate + * + * @param array $params (optional) key-value pairs representing the Transmission's settings + */ public function __construct($params = null) { $this->config = Configuration::getConfig(); + + $this->config['baseUrl'] = '/api/' . $this->config['version'] . '/transmissions'; + $this->request = new Client(); $this->model = [ 'campaign_id'=>null, @@ -26,6 +77,7 @@ class Transmission { 'text'=>null, 'email_rfc822'=>null, 'headers'=>null, + 'template_id'=>null, 'use_draft_template'=>false, ], 'options'=>[ @@ -35,29 +87,58 @@ class Transmission { 'recipients'=>null ]; + //if params were supplied, set their values on the model if(!is_null($params)) { foreach($params as $key=>$value) { - if(key_exists($key, $this->model)) { - $this->model[$key] = $value; - } else if (key_exists($key, $this->model['content'])) { - $this->model['content'][$key] = $value; - } else if (key_exists($key, $this->model['options'])) { - $this->model['options'][$key] = $value; - } - } - - if (isset($params['recipientList'])) { - $this->useRecipientList($params['recipientList']); + $this->setMappedValue($key, $value); } } } + /** + * @desc Private Method helper to reference parameter mappings and set the right value for the right parameter + */ + private function setMappedValue ($mapKey, $value) { + //get mapping + if(array_key_exists($mapKey, $this->parameterMappings)) { + // if its an option, set the value directly + if(in_array($mapKey, ['openTracking', 'clickTracking', 'useDraftTemplate'])) { + switch ($mapKey) { + case 'openTracking': + $this->model['options']['open_tracking'] = $value; + break; + case 'clickTracking': + $this->model['options']['click_tracking'] = $value; + break; + case 'useDraftTemplate': + $this->model['content']['use_draft_template'] = $value; + break; + } + } else { //otherwise call the method to set the value + $method = $this->parameterMappings[$mapKey]; + $this->$method($value); + } + } //ignore anything we don't have a mapping for + } + /** + * @desc Private Method helper to get the configuration values to create the base url for the transmissions API + * + * @return string base url for the transmissions API + */ private function getBaseUrl() { return $this->config['protocol'] . '://' . $this->config['host'] . ($this->config['port'] ? ':' . $this->config['port'] : '') . $this->config['baseUrl']; } - + /** + * @desc Method for issuing POST request to the Transmissions API + * + * This method assumes that all the appropriate fields have + * been populated by the user through configuration or calling + * helper methods + * + * @return array API repsonse represented as key-value pairs + */ public function send() { try { $response = $this->request->post($this->getBaseUrl(), [ @@ -65,22 +146,25 @@ class Transmission { "headers"=>['authorization' => $this->config['key']], "verify"=>$this->config['strictSSL'] ]); - - $body = $response->json(); - - if ($response->getStatusCode() !== 200) { - return $body['errors']; - } - return $body; - + return $response->json(); } catch (RequestException $exception) { + $response = $exception->getResponse(); + throw new \Exception(json_encode($response->json()['errors'])); + } catch (\Exception $exception) { throw new \Exception('Unable to contact Transmissions API: '. $exception->getMessage()); } } /** - * - * @return multitype:multitype:string + * @desc Private Method for issuing GET request to Transmissions API + * + * This method is responsible for getting the collection _and_ + * a specific entity from the Transmissions API + * + * If TransmissionID parameter is omitted, then we fetch the collection + * + * @param string $transmissionID (optional) string Transmission ID of specific Transmission to retrieve + * @return array Result set of transmissions found */ private function fetch ($transmissionID = null) { //figure out the url @@ -95,98 +179,288 @@ class Transmission { "headers"=>['authorization' => $this->config['key']], "verify"=>$this->config['strictSSL'] ]); - - if($response->getStatusCode() === 404) { + return $response->json(); + } catch (RequestException $exception) { + $response = $exception->getResponse(); + if($response->getStatusCode() === '404') { throw new \Exception("The specified Transmission ID does not exist", 404); - } else if ($response->getStatusCode() !== 200) { - throw new \Exception("Received bad response from Transmission API: ". $response->getStatusCode()); } else { - $results = $response->json(); + throw new \Exception("Received bad response from Transmission API: ". $response->getStatusCode()); } - - } catch (RequestException $exception) { - throw new \Exception('Unable to contact Transmissions API: '. $exception->getMessage()); + } catch (\Exception $exception) { + throw new \Exception('Unable to contact Transmissions API: '. $exception->getMessage()); } - return $results; } + /** + * @desc Method for retrieving information about all transmissions + * Wrapper method for a cleaner interface + * + * @return array result Set of transmissions + */ public function all() { return $this->fetch(); } + /** + * @desc Method for retrieving information about a single transmission + * Wrapper method for a cleaner interface + * + * @param string $transmissionID Identifier of the transmission to be found + * @return array result Single transmission represented in key-value pairs + */ public function find($transmissionID) { - $this->fetch($transmissionID); + return $this->fetch($transmissionID); } + /** + * @desc Method for adding metadata to a Transmission + * + * Metadata for a Transmission are key-value pairs that will be made available + * in the webhooks payloads as identifiers for events that are associated with a particular Transmission + * + * Please note that metadata can be applied at the recipient level, and any recipient level metadata takes + * precedence over Transmission level metadata + * + * @param array $meta Key-value pairs to be applied to the Transmission level metadata + * @return \MessageSystems\Transmission Object + */ public function setMetadata ($meta) { $this->model['metadata'] = $meta; return $this; } + /** + * @desc Method for adding substitution data to a Transmission + * + * Substitution data are key-value pairs that are provided + * to the subsititution engine. The substitution engine scans + * parts of the content for substitution syntax '{{ }}' and + * substitutes the values of a given key where the syntax was found + * + * Please note that recipient level substitution data takes precedence + * over any Transmission level substitution data + * + * @param array $subs Key-value pairs of substitution data to be applied at the Transmission level + * @return \MessageSystems\Transmission Object + */ public function setSubstitutiondata ($subs) { $this->model['substitution_data'] = $subs; return $this; } + /** + * @desc Method for adding a campaign to a Transmission + * + * Campaigns are logical groupings of related Transmissions + * + * For example, I may have multiple mailings related to my Labor Day Sale, + * and would apply the campaign 'LaborDay2k14' to all Transmissions associated with + * said sale. + * + * It is also worth noting that Transmissions flagged with a given campaign will be available + * for filtering in both webhooks, as well as the Reporting UI/Metrics API + * + * @param string $campaignID Campaign Name, with a max length of 64 bytes + * @return \MessageSystems\Transmission Object + */ public function setCampaign ($campaignID) { $this->model['campaign_id'] = $campaignID; return $this; } + /** + * @desc Method for adding a description to a Transmission + * + * Descriptions are arbitrary strings used further describe what a specific + * Transmission was/is for the user's benefit. + * + * Please note that the only place currently that description is exposed is via + * the Transmissions API, and the fetch method of this SDK + * + * @param string $description Description of a Transmission with a max length of 1024 bytes + * @return \MessageSystems\Transmission Object + */ public function setDescription ($description) { $this->model['description'] = $description; return $this; } - + + /** + * @desc Method for adding a Return Path to a Transmission + * + * A return path is an email address supplied to a Transmission where any + * bounces generated 'in the wild' will be sent back to this address. Return + * Path is used at the server level. + * + * Please note that this field can be specified in recipients if using + * VERP (Variable Envelope Return Path), which will give each recipient + * a unique envelope MAIL FROM + * + * @param string $returnPath Return Path to be applied to a Transmission + * @return \MessageSystems\Transmission Object + */ public function setReturnPath ($returnPath) { $this->model['return_path'] = $returnPath; return $this; } + /** + * @desc Method for adding a Reply To to a Transmission + * + * A Reply To is very similar to Return Path, but instead of + * being used by servers, Reply To is used by humans. When a human + * in their mail client clicks the reply button, the To field of that email + * will be populated with the email address provided in the Reply To field + * + * @param string $replyTo Reply To to be applied to a Transmission + * @return \MessageSystems\Transmission Object + */ public function setReplyTo ($replyTo) { $this->model['content']['reply_to'] = $replyTo; return $this; } + /** + * @desc Method for adding a Subject to a Transmission + * + * Sets the subject line of content for a given Transmission + * + * @param string $subject Subject to be applied to a Transmission + * @return \MessageSystems\Transmission Object + */ public function setSubject ($subject) { $this->model['content']['subject'] = $subject; return $this; } + /** + * @desc Method for adding a From to a Transmission + * + * Sets the from header of content for a given Transmission. + * Please note that there are three ways to provide the from header + * + * 1. From is a string, like 'person@example.com' + * 2. From is an object with a key email, like '{email: 'person@example.com'}' + * 3. From is an object with a email and name key, like '{name: 'Jane Doe', email: 'person@example.com'}' + * + * Using the third form of From will result is a 'pretty' From headers, like From: Jane Doe <person@example.com> + * + * @param mixed $fromField array/string From header to be applied to a Transmission + * @return \MessageSystems\Transmission Object + */ public function setFrom ($fromField) { $this->model['content']['from'] = $fromField; return $this; } + /** + * @desc Method for adding HTML content to a Transmission + * + * Used for generating a Transmission using inline HTML content + * Please note that you cannot specify HTML content if you've also + * provided a stored template (useStoredTemplate) + * + * You cannot specify HTML content if you've also provided RFC-822 + * encoded content + * + * @param string $html HTML Content to be used when the Transmission is sent + * @return \MessageSystems\Transmission Object + */ public function setHTMLContent ($html) { $this->model['content']['html'] = $html; return $this; } + /** + * @desc Method for adding Plain Text content to a Transmission + * + * Use for generating a Transmission using line Plain Text content + * Please note that you cannot specify Plain Text content if you've also + * provided a stored template (useStoredTemplate) + * + * You cannot specify Plain Text content if you've also provided RFC-822 + * encoded content + * + * @param string $plaintext Plain Text Content to be used when the Transmission is sent + * @return \MessageSystems\Transmission Object + */ public function setTextContent ($plaintext) { $this->model['content']['text'] = $plaintext; return $this; } + /** + * @desc Method for adding RFC 822 encoded content to a Transmission + * + * Used for generating a Transmission using inline encoded content + * Please note that you cannot specify RFC-822 content if you've also + * provided a stored template (useStoredTemplate) + * + * You cannot specify RFC-822 content if you've already provided HTML + * or Plain Text content + * + * @param string $rfc RFC-822 encoded content to be used when the Transmission is sent + * @return \MessageSystems\Transmission Object + */ public function setRfc822Content ($rfc) { - $this->model['content']['rfc'] = $rfc; + $this->model['content']['email_rfc822'] = $rfc; return $this; } - public function setContentHeaders ($headers) { + /** + * @desc Method for adding custom headers to the content of a Transmission + * + * Can contain any key-value pairs _except_ + * - Subject + * - From + * - To + * - Reply-To + * + * @param array $headers Key-value pairs of headers to add to the content of a Transmission + * @return \MessageSystems\Transmission Object + */ + public function setContentHeaders (Array $headers) { $this->model['content']['headers'] = $headers; return $this; } - public function addRecipient ($recipient) { + /** + * @desc Method for adding a single recipient to a Transmission + * + * Used for supplying inline recipients for a Transmission. Emails will be generated + * for each recipient in the list. + * + * The only required field in the recipient definition is address, all others are optional + * If using multiple recipients, iteratively call this method, or use addRecipients + * + * If you call useRecipientList after using this method, recipient value will be overridden + * + * @param array $recipient An associative array of recipient data to send a Transmission + * @return \MessageSystems\Transmission Object + */ + public function addRecipient (Array $recipient) { if(!is_array($this->model['recipients'])) { $this->model['recipients'] = []; } - $this->model['recipients'].push($recipient); + array_push($this->model['recipients'], $recipient); return $this; } - public function addRecipients ($recipients) { + /** + * @desc Method for adding multiple recipients at once to a Transmission + * + * Used for supplying inline recipients for a Transmission. Emails will be generated + * for each recipient in the list. + * + * The only required field in the recipient definition is address, all others are optional + * + * If you call useRecipientList after using this method, recipients value will be overridden + * + * @param array $recipients An array of associative arrays containing recipient data + * @return \MessageSystems\Transmission Object + */ + public function addRecipients (Array $recipients) { if(!is_array($this->model['recipients'])) { $this->model['recipients'] = []; } @@ -194,45 +468,102 @@ class Transmission { return $this; } + /** + * @desc Method for specifying a stored recipient list + * + * Used for supplying a Transmission with recipients from a stored recipient list + * Please note that you cannot use a stored recipient list _and_ inline recipients (addRecipient) + * If you use addRecipient or addRecipients after using this method, recipientList value + * will be overridden + * + * @param string $recipientList Name of the recipient list to be used during Transmission + * @return \MessageSystems\Transmission Object + */ public function useRecipientList ($recipientList) { - //reset the recipients field + // Resetting the data type as it could've been an array of inline recipients $this->model['recipients'] = []; - $this->model['recipients']['list_name'] = $recipientList; + $this->model['recipients']['list_id'] = $recipientList; return $this; } + /** + * @desc Method for specifying a stored template + * + * Used for supplying a Transmission with content from a stored template + * Please note that you cannot use a stored template if you've also added inline + * HTML, Plain Text, or RFC-822 encoded content + * + * @param string $templateID Name of template to be used during Transmission + * @return \MessageSystems\Transmission Object + */ public function useStoredTemplate ($templateID) { $this->model['content']['template_id'] = $templateID; return $this; } + /** + * @desc Method for enabling click tracking for a given transmission + * By default, click tracking is enabled for a transmission + * + * @return \MessageSystems\Transmission Object + */ public function enableClickTracking () { - $this->model['opitons']['click_tracking'] = true; + $this->model['options']['click_tracking'] = true; return $this; } + /** + * @desc Method for disabling click tracking for a given transmission + * By default, click tracking is enabled for a transmission + * + * @return \MessageSystems\Transmission Object + */ public function disableClickTracking () { - $this->model['opitons']['click_tracking'] = false; + $this->model['options']['click_tracking'] = false; return $this; } + /** + * @desc Method for enabling open tracking for a given transmission + * By default, open tracking is enabled for a transmission + * + * @return \MessageSystems\Transmission Object + */ public function enableOpenTracking () { - $this->model['opitons']['open_tracking'] = true; + $this->model['options']['open_tracking'] = true; return $this; } + /** + * @desc Method for disabling open tracking for a given transmission + * By default, open tracking is enabled for a transmission + * + * @return \MessageSystems\Transmission Object + */ public function disableOpenTracking () { - $this->model['opitons']['open_tracking'] = false; + $this->model['options']['open_tracking'] = false; return $this; } + /** + * @desc Method for allowing the sending of a draft version of a template with a transmission + * By default, you cannot send a draft version of a stored template + * + * @return \MessageSystems\Transmission Object + */ public function useDraftTemplate () { - $this->model['opitons']['use_draft_template'] = true; + $this->model['content']['use_draft_template'] = true; return $this; } + /** + * @desc Method for disallowing the sending of a draft version of a template with a transmission + * By default, you cannot send a draft version of a stored template + * + * @return \MessageSystems\Transmission Object + */ public function usePublishedTemplate () { - $this->model['opitons']['use_draft_template'] = false; + $this->model['content']['use_draft_template'] = false; return $this; } } diff --git a/index.php b/lib/SparkPost.php index 39592f0..2a4b589 100644 --- a/index.php +++ b/lib/SparkPost.php @@ -1,6 +1,5 @@ <?php - -require_once 'vendor/autoload.php'; // Autoload files using Composer autoload +namespace SparkPost; use MessageSystems\Transmission; use MessageSystems\Configuration; @@ -11,7 +10,11 @@ class SparkPost { public function __construct($globalOpts) { Configuration::setConfig($globalOpts); - $this->transmission = new Transmission(); + } + + public function Transmission(Array $options = null) { + $this->transmission = new Transmission($options); + return $this->transmission; } } ?>
\ No newline at end of file diff --git a/test/unit/bootstrap.php b/test/unit/bootstrap.php new file mode 100644 index 0000000..7e73606 --- /dev/null +++ b/test/unit/bootstrap.php @@ -0,0 +1,3 @@ +<?php + require_once dirname(__FILE__).'/../../vendor/autoload.php'; +?>
\ No newline at end of file diff --git a/test/unit/configurationTest.php b/test/unit/configurationTest.php index 034ce4c..52c60be 100644 --- a/test/unit/configurationTest.php +++ b/test/unit/configurationTest.php @@ -1,16 +1,15 @@ <?php -require_once 'vendor/autoload.php'; +namespace SparkPost\Test; use MessageSystems\Configuration; - -class ConfigurationTest extends PHPUnit_Framework_TestCase { +class ConfigurationTest extends \PHPUnit_Framework_TestCase { /** * @desc Ensures that the configuration class is not instantiable. */ public function testConstructorCannotBeCalled() { - $class = new ReflectionClass('\MessageSystems\Configuration'); + $class = new \ReflectionClass('\MessageSystems\Configuration'); $this->assertFalse($class->isInstantiable()); } diff --git a/test/unit/transmissionTest.php b/test/unit/transmissionTest.php index 8d3e0f6..3d2f6d3 100644 --- a/test/unit/transmissionTest.php +++ b/test/unit/transmissionTest.php @@ -1,33 +1,51 @@ <?php -require_once 'vendor/autoload.php'; +namespace SparkPost\Test; use MessageSystems\Transmission; use MessageSystems\Configuration; -use GuzzleHttp\Client; use GuzzleHttp\Subscriber\Mock; use GuzzleHttp\Message\Response; +use GuzzleHttp\Stream\Stream; -class TransmissionTest extends PHPUnit_Framework_TestCase { +/** + * + * + */ +class TransmissionTest extends \PHPUnit_Framework_TestCase { private $transmission = null; private $client = null; private static function getMethod($name) { - $class = new ReflectionClass('\MessageSystems\Transmission'); + $class = new \ReflectionClass('\MessageSystems\Transmission'); $method = $class->getMethod($name); $method->setAccessible(true); return $method; } private static function getProperty($obj, $name) { - $class = new ReflectionClass('\MessageSystems\Transmission'); + $class = new \ReflectionClass('\MessageSystems\Transmission'); $property = $class->getProperty($name); $property->setAccessible(true); return $property->getValue($obj); } /** + * Dynamically dereferences an array for a path list provided by the $dereferenceArray + * @param array $array Nested array to be dereferenced + * @param array $dereferenceArray list of key values to dereference + * @return mixed + */ + private static function dereference($array, $dereferenceArray) { + $value = $array; + foreach($dereferenceArray as $derefValue) { + $value = $value[$derefValue]; + } + return $value; + } + + /** * (non-PHPdoc) * @before * @see PHPUnit_Framework_TestCase::setUp() @@ -35,7 +53,7 @@ class TransmissionTest extends PHPUnit_Framework_TestCase { public function setUp() { Configuration::setConfig(['key'=>'blah']); $this->transmission = new Transmission(); - $this->client = new Client(); + $this->client = self::getProperty($this->transmission, 'request'); //so we can bootstrap api responses } /** @@ -46,24 +64,180 @@ class TransmissionTest extends PHPUnit_Framework_TestCase { $this->assertArrayNotHasKey('blah', $this->getProperty($transmission, 'model')); } + /** + * + */ public function testConstructorWillSetValidKeys() { - $transmission = new Transmission(['description'=>'this is a test', 'text'=>'test txt', 'open_tracking'=>false, 'recipientList'=>'my recip list']); + $transmission = new Transmission(['description'=>'this is a test', 'text'=>'test txt', 'openTracking'=>false, 'clickTracking'=>false, 'useDraftTemplate'=>false, 'recipientList'=>'my recip list']); $this->assertArrayHasKey('description', $this->getProperty($transmission, 'model')); $this->assertEquals('this is a test', $this->getProperty($transmission, 'model')['description']); $this->assertEquals('test txt', $this->getProperty($transmission, 'model')['content']['text']); $this->assertEquals(false, $this->getProperty($transmission, 'model')['options']['open_tracking']); - $this->assertEquals('my recip list', $this->getProperty($transmission, 'model')['recipients']['list_name']); + $this->assertEquals(false, $this->getProperty($transmission, 'model')['options']['click_tracking']); + $this->assertEquals(false, $this->getProperty($transmission, 'model')['content']['use_draft_template']); + $this->assertEquals('my recip list', $this->getProperty($transmission, 'model')['recipients']['list_id']); + } + + /** + * + */ + public function testAllWithGoodResponse() { + $mock = new Mock([new Response(200, [], Stream::factory('{"results":[{"test":"This is a test"}, {"test":"two"}]}'))]); + $this->client->getEmitter()->attach($mock); + $this->assertEquals(["results"=>[['test'=>'This is a test'], ['test'=>'two']]], $this->transmission->all()); } + /** + * + */ + public function testFindWithGoodResponse() { + $mock = new Mock([new Response(200, [], Stream::factory('{"results":[{"test":"This is a test"}]}'))]); + $this->client->getEmitter()->attach($mock); + $this->assertEquals(["results"=>[['test'=>'This is a test']]], $this->transmission->find('someId')); + } -// public function testFetch() { -// $mock = new Mock([new Response(200, ['body'=>['test'=>'This is a test']])]); + /** + * @expectedException Exception + * @expectedExceptionMessage The specified Transmission ID does not exist + */ + public function testFindWith404Response() { + $mock = new Mock([new Response(404, [])]); + $this->client->getEmitter()->attach($mock); + $this->transmission->find('someId'); + } + + /** + * @expectedException Exception + * @expectedExceptionMessage Received bad response from Transmission API: 400 + */ + public function testFindWithOtherBadResponse() { + $mock = new Mock([new Response(400, [])]); + $this->client->getEmitter()->attach($mock); + $this->transmission->find('someId'); + } + +// /** +// * @expectedException Exception +// * @expectedExceptionMessageRegExp /Unable to contact Transmissions API:.* / +// */ +// public function testFindForUnableToContactServer() { +// $mock = new Mock([new Response(500)]); // $this->client->getEmitter()->attach($mock); -// $this->assertEquals(['test'=>'This is a test'], self::getMethod('fetch')->invokeArgs($this->transmission, [null])); +// $this->transmission->find('someId'); // } - public function testSend() { - //$this->transmission + + /** + * + */ + public function testSuccessfulSend() { + $body = ["result"=>["transmission_id"=> "11668787484950529"], "status"=>["message"=> "ok","code"=> "1000"]]; + $mock = new Mock([new Response(200, [], Stream::factory(json_encode($body)))]); + $this->client->getEmitter()->attach($mock); + $this->assertEquals($body, $this->transmission->send()); } + + /** + * @expectedException Exception + * @expectedExceptionMessage This is a fake error + */ + public function testFindForRequestException() { + $body = ['errors'=>['This is a fake error']]; + $mock = new Mock([new Response(400, [], Stream::factory(json_encode($body)))]); + $this->client->getEmitter()->attach($mock); + $this->transmission->send(); + } + +// /** +// * @expectedException Exception +// * @expectedExceptionMessageRegExp /Unable to contact Traissions API: \w+/ +// */ +// public function testSendForUnableToContactServer() { +// $mock = new Mock([new Response(500, [])]); +// $this->client->getEmitter()->attach($mock); +// $this->transmission->send(); +// } + + + public function setProvider() { + return [ + ['setMetadata', ['metadata']], + ['setSubstitutionData', ['substitution_data']], + ['setCampaign', ['campaign_id']], + ['setDescription', ['description']], + ['setReturnPath', ['return_path']], + ['setReplyTo', ['content', 'reply_to']], + ['setSubject', ['content', 'subject']], + ['setFrom', ['content', 'from']], + ['setHTMLContent', ['content', 'html']], + ['setTextContent', ['content', 'text']], + ['setRfc822Content', ['content', 'email_rfc822']], + + ['useRecipientList', ['recipients', 'list_id']], + ['useStoredTemplate', ['content', 'template_id']] + ]; + } + + /** + * @dataProvider setProvider + */ + public function testSimpleSetFunctions($setterFunction, $dereference) { + $testValue = 'test'; + $returnValue = $this->transmission->$setterFunction($testValue); + $this->assertInstanceOf('MessageSystems\Transmission', $returnValue); + $this->assertSame($this->transmission, $returnValue); + $this->assertEquals($testValue, self::dereference(self::getProperty($this->transmission, 'model'), $dereference)); + } + + public function complexSetFunctionsProvider() { + return [ + ['addRecipient', ['recipients'], ['address'=>'testRecipient@example.com'], [['address'=>'testRecipient@example.com']]], + ['addRecipients', ['recipients'], [ + ['address'=>'testRecipient1@example.com'], + ['address'=>'testRecipient2@example.com'], + ['address'=>'testRecipient3@example.com'] + ], + [ + ['address'=>'testRecipient1@example.com'], + ['address'=>'testRecipient2@example.com'], + ['address'=>'testRecipient3@example.com'] + ]], + ['setContentHeaders', ['content', 'headers'], ['x-head'=>'somevalue'], ['x-head'=>'somevalue']], + ]; + } + + /** + * @dataProvider complexSetFunctionsProvider + */ + public function testComplexSetFunctions($setterFunction, $dereference, $setValue, $expected) { + $returnValue = $this->transmission->$setterFunction($setValue); + $this->assertInstanceOf('MessageSystems\Transmission', $returnValue); + $this->assertSame($this->transmission, $returnValue); + $this->assertEquals($expected, self::dereference(self::getProperty($this->transmission, 'model'), $dereference)); + } + + + + public function optionsProvider() { + return [ + ['enableClickTracking', ['options', 'click_tracking'], true], + ['disableClickTracking', ['options', 'click_tracking'], false], + ['enableOpenTracking', ['options', 'open_tracking'], true], + ['disableOpenTracking', ['options', 'open_tracking'], false], + ['useDraftTemplate', ['content', 'use_draft_template'], true], + ['usePublishedTemplate', ['content', 'use_draft_template'], false] + ]; + } + + /** + * @dataProvider optionsProvider + */ + public function testOptionsFunctions($setterFunction, $dereference, $expected) { + $returnValue = $this->transmission->$setterFunction(); + $this->assertInstanceOf('MessageSystems\Transmission', $returnValue); + $this->assertSame($this->transmission, $returnValue); + $this->assertEquals($expected, self::dereference(self::getProperty($this->transmission, 'model'), $dereference)); + } + } ?>
\ No newline at end of file |