-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathPostmarkClientBaseTest.php
More file actions
53 lines (40 loc) · 1.71 KB
/
PostmarkClientBaseTest.php
File metadata and controls
53 lines (40 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace Postmark\Tests;
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/TestingKeys.php';
use Postmark\PostmarkClientBase;
abstract class PostmarkClientBaseTest extends \PHPUnit\Framework\TestCase
{
public static $testKeys;
public static function setUpBeforeClass(): void
{
// get the config keys for the various tests
self::$testKeys = new TestingKeys();
PostmarkClientBase::$BASE_URL = self::$testKeys->BASE_URL ?: 'https://api.postmarkapp.com';
date_default_timezone_set('UTC');
}
/**
* Get the first available verified sender signature or create one if needed
*/
public static function getVerifiedSenderSignature()
{
try {
$tk = self::$testKeys;
$client = new \Postmark\PostmarkAdminClient($tk->WRITE_ACCOUNT_TOKEN, $tk->TEST_TIMEOUT);
$signatures = $client->listSenderSignatures()->getSenderSignatures();
if (!empty($signatures)) {
// Return the first verified sender signature
return $signatures[0]->getEmailAddress();
}
// If no signatures exist, try to create one using a unique email
$uniqueEmail = 'test-' . uniqid() . '@wildbit.com';
$client->createSenderSignature($uniqueEmail, 'Test Signature ' . uniqid());
// Wait for the signature to be processed
sleep(2);
return $uniqueEmail;
} catch (\Exception $e) {
// If we can't get or create signatures, use the prototype as-is
return $tk->WRITE_TEST_SENDER_SIGNATURE_PROTOTYPE;
}
}
}