Skip to content

Commit

Permalink
fix mailgun tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed Dec 6, 2016
1 parent 3c4bba3 commit a487a42
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
22 changes: 15 additions & 7 deletions appengine/standard/mailgun/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,33 @@
$recipient,
$mailgunDomain,
$mailgunApiKey,
$cc = 'cc@example.com',
$bcc = 'bcc@example.com'
$cc = '',
$bcc = ''
) {
# [START complex_message]
// Instantiate the client.
$httpClient = new Http\Adapter\Guzzle6\Client();
$mailgunClient = new Mailgun\Mailgun($mailgunApiKey, $httpClient);
$fileAttachment = __DIR__ . '/attachment.txt';

// Make the call to the client.
$result = $mailgunClient->sendMessage($mailgunDomain, array(
$postData = array(
'from' => sprintf('Example Sender <mailgun@%s>', $mailgunDomain),
'to' => $recipient,
'cc' => $cc,
'bcc' => $bcc,
'subject' => 'Hello',
'text' => 'Testing some Mailgun awesomeness!',
'html' => '<html>HTML version of the body</html>',
), array(
);

if ($cc) {
$postData['cc'] = $cc;
}

if ($bcc) {
$postData['bcc'] = $bcc;
}

// Make the call to the client.
$result = $mailgunClient->sendMessage($mailgunDomain, $postData, array(
'attachment' => array($fileAttachment, $fileAttachment),
));
# [END complex_message]
Expand Down
12 changes: 8 additions & 4 deletions appengine/standard/mailgun/test/mailgunTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

class mailgunTest extends WebTestCase
{
private $recipient;

public function createApplication()
{
$app = require __DIR__ . '/../app.php';
Expand All @@ -30,9 +32,11 @@ public function createApplication()
// set your Mailgun domain name and API key
$mailgunDomain = getenv('MAILGUN_DOMAIN');
$mailgunApiKey = getenv('MAILGUN_APIKEY');
$this->recipient = getenv('MAILGUN_RECIPIENT');

if (empty($mailgunDomain) || empty($mailgunApiKey)) {
$this->markTestSkipped('set the MAILGUN_DOMAIN and MAILGUN_APIKEY environment variables');
if (empty($mailgunDomain) || empty($mailgunApiKey) || empty($this->recipient)) {
$this->markTestSkipped('set the MAILGUN_DOMAIN, MAILGUN_APIKEY ' .
'and MAILGUN_RECIPIENT environment variables');
}

$app['mailgun.domain'] = $mailgunDomain;
Expand All @@ -58,7 +62,7 @@ public function testSimpleEmail()
$client = $this->createClient();

$crawler = $client->request('POST', '/', [
'recipient' => 'fake@example.com',
'recipient' => $this->recipient,
'submit' => 'simple',
]);

Expand All @@ -72,7 +76,7 @@ public function testComplexEmail()
$client = $this->createClient();

$crawler = $client->request('POST', '/', [
'recipient' => 'fake@example.com',
'recipient' => $this->recipient,
'submit' => 'complex',
]);

Expand Down

0 comments on commit a487a42

Please sign in to comment.