diff options
-rw-r--r-- | lib/SparkPost/SparkPost.php | 16 | ||||
-rw-r--r-- | test/unit/SparkPostTest.php | 6 |
2 files changed, 15 insertions, 7 deletions
diff --git a/lib/SparkPost/SparkPost.php b/lib/SparkPost/SparkPost.php index d4449b8..2a554dd 100644 --- a/lib/SparkPost/SparkPost.php +++ b/lib/SparkPost/SparkPost.php @@ -40,11 +40,6 @@ class SparkPost { * its just they API Key. */ public function __construct($httpAdapter, $settingsConfig) { - // if the config map is a string we should assume that its an api key - if (gettype($settingsConfig) === 'string') { - $settingsConfig = ['key'=>$settingsConfig]; - } - //config needs to be setup before adapter because of default adapter settings $this->setConfig($settingsConfig); $this->setHttpAdapter($httpAdapter); @@ -114,10 +109,17 @@ class SparkPost { /** * Allows the user to pass in values to override the defaults and set their API key - * @param Array $settingsConfig - Hashmap that contains config values for the SDK to connect to SparkPost + * @param String | Array $settingsConfig - Hashmap that contains config values + * for the SDK to connect to SparkPost. If its a string we assume that + * its just they API Key. * @throws \Exception */ - public function setConfig(Array $settingsConfig) { + public function setConfig($settingsConfig) { + // if the config map is a string we should assume that its an api key + if (gettype($settingsConfig) === 'string') { + $settingsConfig = ['key'=>$settingsConfig]; + } + // Validate API key because its required if (!isset($settingsConfig['key']) || empty(trim($settingsConfig['key']))){ throw new \Exception('You must provide an API key'); diff --git a/test/unit/SparkPostTest.php b/test/unit/SparkPostTest.php index 101784a..b1b38fe 100644 --- a/test/unit/SparkPostTest.php +++ b/test/unit/SparkPostTest.php @@ -51,6 +51,12 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase { $this->resource->setHttpAdapter(new \stdClass()); } + public function testSetConfigStringKey() { + $this->resource->setConfig('a key'); + $config = self::$utils->getProperty($this->resource, 'config'); + $this->assertEquals('a key', $config['key']); + } + /** * @expectedException Exception * @expectedExceptionMessageRegExp /API key/ |