/**
  * @desc Tests overridable values are set while invalid values are ignored
  */
 public function testSetConfigMultipleValuesAndGetConfig()
 {
     SparkPost::setConfig(array('key' => 'lala', 'version' => 'v8', 'port' => 1024, 'someOtherValue' => 'fakeValue'));
     $testConfig = SparkPost::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('api.sparkpost.com', $testConfig['host']);
     $this->assertEquals(true, $testConfig['strictSSL']);
 }
Exemplo n.º 2
0
 /**
  * @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 static function fetch($transmissionID = null)
 {
     //figure out the url
     $hostConfig = SparkPost::getConfig();
     $url = self::getBaseUrl($hostConfig);
     if (!is_null($transmissionID)) {
         $url .= '/' . $transmissionID;
     }
     $request = self::getHttpClient();
     //make request
     try {
         $response = $request->get($url, array('authorization' => $hostConfig['key']), array("verify" => $hostConfig['strictSSL']))->send();
         return $response->json();
     } catch (ClientErrorResponseException $exception) {
         $response = $exception->getResponse();
         $statusCode = $response->getStatusCode();
         if ($statusCode === 404) {
             throw new \Exception("The specified Transmission ID does not exist", 404);
         }
         throw new \Exception("Received bad response from Transmission API: " . $statusCode);
     } catch (\Exception $exception) {
         throw new \Exception('Unable to contact Transmissions API: ' . $exception->getMessage());
     }
 }