public function testSendRequest()
 {
     $sr = new SendRequest('464bed09-9875-45b3-9111-44f633de9d30');
     $sr->setChannel('Sysout');
     $sr->setTemplate('Dummy');
     $sr->setRecipient(new Address('*****@*****.**', 'weweave GbR'));
     $sr->setEcho(true);
     $sr->setKeyword('UnitTest');
     $sr->setDetails('php unit test testSendSuccess()');
     $sr->addModelParam('firstname', 'John');
     $sr->addModelParam('code', '123456');
     $attachment = new Attachment('test.txt');
     $attachment->setPayloadFromFile('test.txt');
     $attachment->setContentType('text/plain');
     $sr->addAttachment($attachment);
     $o = $sr->getObject();
     $this->assertNotEmpty($o);
     $this->assertEquals('464bed09-9875-45b3-9111-44f633de9d30', $o['token']);
     $this->assertEquals('Sysout', $o['channel']);
     $this->assertEquals('Dummy', $o['template']);
     $this->assertEquals(true, $o['echo']);
     $this->assertEquals('UnitTest', $o['keyword']);
     $this->assertEquals('php unit test testSendSuccess()', $o['details']);
     $this->assertNotEmpty($o['recipient']);
     $this->assertEquals('*****@*****.**', $o['recipient']['address']);
     $this->assertEquals('weweave GbR', $o['recipient']['name']);
     $this->assertEquals('firstname', $o['model'][0]['key']);
     $this->assertEquals('John', $o['model'][0]['value']);
     $this->assertEquals('code', $o['model'][1]['key']);
     $this->assertEquals('123456', $o['model'][1]['value']);
     $this->assertEquals('test.txt', $o['attachments'][0]['filename']);
     $this->assertEquals('text/plain', $o['attachments'][0]['contentType']);
     $this->assertEquals('VGhpcyBpcyBqdXN0IGEgdGVzdCBjYXNl', $o['attachments'][0]['payload']);
 }
Exemple #2
0
// Include the required files
require '../src/TubewarderRestClient.php';
// Import the classes
use Tubewarder\TubewarderRestClient;
use Tubewarder\SendRequest;
use Tubewarder\Address;
use Tubewarder\ErrorCode;
// Create a new client
$client = new TubewarderRestClient('http://*****:*****@weweave.net', 'weweave GbR'));
$sr->setEcho(true);
$sr->setKeyword('UnitTest');
$sr->setDetails('php unit test testSendSuccess()');
$sr->addModelParam('firstname', 'John');
$sr->addModelParam('code', '123456');
try {
    // Send the request
    $res = $client->send($sr);
    // We received a response code from the server
    if ($res->getError() == ErrorCode::OK) {
        echo "Success!\n";
    } else {
        echo "Error code: " . $res->getError() . "\n";
    }
} catch (Exception $e) {
    // Could not connect to the server
    echo "An errror occurred while connecting to the Tubewarder Server!\n";