/**
  * @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
<?php

/*Cron will automaticly run this program every minute, seeing which polls are old. Old polls have their data sent to the specified email and are removed.*/
namespace Examples\Transmisson;

require_once "config.php";
require 'vendor/autoload.php';
use SparkPost\SparkPost;
use SparkPost\Transmission;
SparkPost::setConfig(["key" => SPARK_KEY]);
$result = $db->query("SELECT * FROM poll WHERE end_time < NOW()");
while ($row = $result->fetch_array()) {
    try {
        $results = Transmission::send(array("from" => "From Envelope <*****@*****.**>", "recipients" => array(array("address" => array("email" => $row['email']))), "template" => "suggest-app-poll-dat", 'substitutionData' => $row));
    } catch (\Exception $exception) {
        echo $exception->getMessage();
    }
}
$db->query("DELETE FROM poll WHERE end_time < NOW()");
<?php

namespace Examples\Transmisson;

require_once dirname(__FILE__) . '/../bootstrap.php';
use SparkPost\SparkPost;
use SparkPost\Transmission;
$key = 'YOURAPIKEY';
SparkPost::setConfig(array('key' => $key));
try {
    $results = Transmission::send(array("campaign" => "my-campaign", "metadata" => array("sample_campaign" => true, "type" => "these are custom fields"), "substitutionData" => array("name" => "Test Name"), "description" => "my description", "replyTo" => "*****@*****.**", "customHeaders" => array("X-Custom-Header" => "Sample Custom Header"), "trackOpens" => false, "trackClicks" => false, "from" => "From Envelope <*****@*****.**>", "html" => "<p>Hello World! Your name is: {{name}}</p>", "text" => "Hello World!", "subject" => "Example Email: {{name}}", "recipients" => array(array("address" => array("email" => "*****@*****.**")))));
    echo 'Congrats you can use your SDK!';
} catch (\Exception $exception) {
    echo $exception->getMessage();
}
 /**
  * (non-PHPdoc)
  * @before
  * @see PHPUnit_Framework_TestCase::setUp()
  */
 public function setUp()
 {
     SparkPost::setConfig(array('key' => 'blah'));
     $this->client = self::getMethod('getHttpClient')->invoke(null);
     //so we can bootstrap api responses
 }