-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathPostmarkClientBounceTest.php
More file actions
151 lines (124 loc) · 4.37 KB
/
PostmarkClientBounceTest.php
File metadata and controls
151 lines (124 loc) · 4.37 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
namespace Postmark\Tests;
require_once __DIR__ . '/PostmarkClientBaseTest.php';
use Postmark\PostmarkClient;
/**
* @internal
*
* @coversNothing
*/
class PostmarkClientBounceTest extends PostmarkClientBaseTest
{
public static function setUpBeforeClass(): void
{
PostmarkClientSuppressionsTest::tearDownAfterClass();
}
/**
* @depends testClientCanActivateBounce
*/
public function testClientCanGetBounce()
{
$tk = parent::$testKeys;
$client = new PostmarkClient($tk->READ_SELENIUM_TEST_SERVER_TOKEN, $tk->TEST_TIMEOUT);
$bounces = $client->getBounces(10, 0);
$bounceList = $bounces->getBounces();
if (empty($bounceList)) {
$this->markTestSkipped('No bounces available for testing');
return;
}
$id = $bounceList[0]->getID();
$bounce = $client->getBounce($id);
$this->assertNotEmpty($bounce);
$this->assertEquals($id, $bounce->getID());
}
/**
* @depends testClientCanActivateBounce
*/
public function testClientCanGetBounceDump()
{
$tk = parent::$testKeys;
$client = new PostmarkClient($tk->READ_SELENIUM_TEST_SERVER_TOKEN, $tk->TEST_TIMEOUT);
$bounces = $client->getBounces(10, 0);
$bounceList = $bounces->getBounces();
if (empty($bounceList)) {
$this->markTestSkipped('No bounces available for testing');
return;
}
$id = $bounceList[0]->getID();
$dump = $client->getBounceDump($id);
$this->assertNotEmpty($dump);
$this->assertNotEmpty($dump->getBody());
}
public function testClientCanActivateBounce()
{
$tk = parent::$testKeys;
$client = new PostmarkClient($tk->WRITE_TEST_SERVER_TOKEN, $tk->TEST_TIMEOUT);
// make sure that this email is not suppressed
// generate a bounces
$fromEmail = $tk->WRITE_TEST_SENDER_EMAIL_ADDRESS;
$toEmail = 'hardbounce@bounce-testing.postmarkapp.com'; // special email to generate bounce
$subject = 'Hello from Postmark!';
$htmlBody = '<strong>Hello</strong> dear Postmark user.';
$textBody = 'Hello dear Postmark user.';
$tag = 'example-email-tag';
$trackOpens = true;
$trackLinks = 'None';
$sendResult = $client->sendEmail(
$fromEmail,
$toEmail,
$subject,
$htmlBody,
$textBody,
$tag,
$trackOpens,
null, // Reply To
null, // CC
null, // BCC
null, // Header array
null, // Attachment array
$trackLinks,
null // Metadata array
);
// make sure there is enough time for the bounce to take place.
sleep(180);
$bounceList = $client->getBounces(20, 0);
$id = 0;
$sentId = $sendResult->getMessageID();
$bounces = $bounceList->getBounces();
$this->assertNotEmpty($bounces);
$this->assertNotEmpty($sentId);
foreach ($bounces as $bounce) {
$bmid = $bounce->getMessageID();
if ($sentId === $bmid) {
$id = $bounce->getID();
break;
}
}
$this->assertGreaterThan(0, $id);
$bounceActivation = $client->activateBounce($id);
$actBounce = $bounceActivation->getBounce();
$this->assertNotEmpty($actBounce);
$this->assertEquals($id, $actBounce->getID());
}
/**
* @depends testClientCanActivateBounce
*/
public function testClientCanGetDeliveryStatistics()
{
$tk = parent::$testKeys;
$client = new PostmarkClient($tk->READ_SELENIUM_TEST_SERVER_TOKEN, $tk->TEST_TIMEOUT);
$stats = $client->getDeliveryStatistics();
$this->assertNotEmpty($stats, 'Stats from getDeliveryStatistics() should never be null or empty.');
$this->assertGreaterThan(0, $stats->getInactiveMails(), 'The inactive mail count should be greater than zero.');
}
/**
* @depends testClientCanActivateBounce
*/
public function testClientCanGetBounces()
{
$tk = parent::$testKeys;
$client = new PostmarkClient($tk->READ_SELENIUM_TEST_SERVER_TOKEN, $tk->TEST_TIMEOUT);
$bounces = $client->getBounces(10, 0);
$this->assertNotEmpty($bounces);
}
}