summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornornholdj <nornholdj@gmail.com>2014-10-22 17:18:53 -0400
committernornholdj <nornholdj@gmail.com>2014-10-22 17:18:53 -0400
commitc004fdc8fd6140d0074000ae112e7d0ca70437c1 (patch)
treeec3eb92e2d1c7081559a3d05f4ad184630482121
parentd9d40f3ce24068d5a0d0fecb4aa9cffcf15c5555 (diff)
downloadphp-sparkpost-c004fdc8fd6140d0074000ae112e7d0ca70437c1.zip
php-sparkpost-c004fdc8fd6140d0074000ae112e7d0ca70437c1.tar.gz
php-sparkpost-c004fdc8fd6140d0074000ae112e7d0ca70437c1.tar.bz2
MA-946 #time 2h Wrote Configuration Unit tests.
-rw-r--r--RoboFile.php3
-rw-r--r--lib/MessageSystems/Configuration.php20
-rw-r--r--test/unit/configurationTest.php61
-rw-r--r--test/unit/transmissionTest.php4
4 files changed, 81 insertions, 7 deletions
diff --git a/RoboFile.php b/RoboFile.php
index cdb49ab..592e7ae 100644
--- a/RoboFile.php
+++ b/RoboFile.php
@@ -15,9 +15,6 @@ class RoboFile extends \Robo\Tasks
// print message when tests passed
if ($res->wasSuccessful()) $this->say("All tests passed");
- // alternatively
- if ($res()) $this->say("All tests passed");
-
// $coverage->stop();
// $writer = new PHP_CodeCoverage_Report_HTML;
// $writer->process($coverage, 'test/output/report');
diff --git a/lib/MessageSystems/Configuration.php b/lib/MessageSystems/Configuration.php
index 9f7c4ea..106d1d5 100644
--- a/lib/MessageSystems/Configuration.php
+++ b/lib/MessageSystems/Configuration.php
@@ -13,10 +13,16 @@ class Configuration {
'version'=>'v1'
];
+ /**
+ * Enforce that this object can't be instansiated
+ */
+ private function __construct(){}
- private function __constructor(){
- }
-
+ /**
+ * Allows the user to pass in values to override the defaults and set their API key
+ * @param Array $configMap - Hashmap that contains config values for the SDK to connect to SparkPost
+ * @throws \Exception
+ */
public static function setConfig($configMap) {
//check for API key because its required
if (!isset($configMap['key']) || empty(trim($configMap['key']))){
@@ -24,10 +30,16 @@ class Configuration {
}
self::$config = self::$defaults;
foreach ($configMap as $configOption => $configValue) {
- self::$config[$configOption] = $configValue;
+ if(key_exists($configOption, self::$config)) {
+ self::$config[$configOption] = $configValue;
+ }
}
}
+ /**
+ * Retrieves the configuration that was previously setup by the user
+ * @throws \Exception
+ */
public static function getConfig() {
if (self::$config === null) {
throw new \Exception('No configuration has been provided');
diff --git a/test/unit/configurationTest.php b/test/unit/configurationTest.php
new file mode 100644
index 0000000..034ce4c
--- /dev/null
+++ b/test/unit/configurationTest.php
@@ -0,0 +1,61 @@
+<?php
+require_once 'vendor/autoload.php';
+
+use MessageSystems\Configuration;
+
+
+class ConfigurationTest extends PHPUnit_Framework_TestCase {
+
+ /**
+ * @desc Ensures that the configuration class is not instantiable.
+ */
+ public function testConstructorCannotBeCalled() {
+ $class = new ReflectionClass('\MessageSystems\Configuration');
+ $this->assertFalse($class->isInstantiable());
+ }
+
+ /**
+ * @desc Tests that an exception is thrown when a library tries to recieve the config and it has not yet been set.
+ * Since its a singleton this test must come before any setConfig tests.
+ * @expectedException Exception
+ * @expectedExceptionMessage No configuration has been provided
+ */
+ public function testGetConfigEmptyException() {
+ Configuration::getConfig();
+ }
+
+ /**
+ * @desc Tests that the api key is set when setting the config
+ * @expectedException Exception
+ * @expectedExceptionMessage You must provide an API key
+ */
+ public function testSetConfigAPIKeyNotSetException() {
+ Configuration::setConfig(['something'=>'other than an API Key']);
+ }
+
+ /**
+ * @desc Tests that the api key is set when setting the config and that its not empty
+ * @expectedException Exception
+ * @expectedExceptionMessage You must provide an API key
+ */
+ public function testSetConfigAPIKeyEmptyException() {
+ Configuration::setConfig(['key'=>'']);
+ }
+
+ /**
+ * @desc Tests overridable values are set while invalid values are ignored
+ */
+ public function testSetConfigMultipleValuesAndGetConfig() {
+ Configuration::setConfig(['key'=>'lala', 'version'=>'v8', 'port'=>1024, 'someOtherValue'=>'fakeValue']);
+
+ $testConfig = Configuration::getConfig();
+ $this->assertEquals('lala', $testConfig['key']);
+ $this->assertEquals('v8', $testConfig['version']);
+ $this->assertEquals(1024, $testConfig['port']);
+ $this->assertNotContains('someOtherValue', array_keys($testConfig));
+ $this->assertEquals('https', $testConfig['protocol']);
+ $this->assertEquals('app.cloudplaceholder.com', $testConfig['host']);
+ $this->assertEquals(true, $testConfig['strictSSL']);
+ }
+}
+?> \ No newline at end of file
diff --git a/test/unit/transmissionTest.php b/test/unit/transmissionTest.php
index f402730..8d3e0f6 100644
--- a/test/unit/transmissionTest.php
+++ b/test/unit/transmissionTest.php
@@ -61,5 +61,9 @@ class TransmissionTest extends PHPUnit_Framework_TestCase {
// $this->client->getEmitter()->attach($mock);
// $this->assertEquals(['test'=>'This is a test'], self::getMethod('fetch')->invokeArgs($this->transmission, [null]));
// }
+
+ public function testSend() {
+ //$this->transmission
+ }
}
?> \ No newline at end of file