44
55require_once __DIR__ . '/PostmarkClientBaseTest.php ' ;
66
7+ use Postmark \Models ;
78use Postmark \PostmarkClient ;
9+ use Postmark \tests ;
810
911/**
1012 * @internal
1315 */
1416class PostmarkClientBounceTest extends PostmarkClientBaseTest
1517{
18+ public static function setUpBeforeClass (): void
19+ {
20+ PostmarkClientSuppressionsTest::tearDownAfterClass ();
21+ }
22+
1623 public function testClientCanGetDeliveryStatistics ()
1724 {
1825 $ tk = parent ::$ testKeys ;
@@ -41,6 +48,7 @@ public function testClientCanGetBounce()
4148 $ id = $ bounces ->getBounces ()[0 ]->getID ();
4249 $ bounce = $ client ->getBounce ($ id );
4350 $ this ->assertNotEmpty ($ bounce );
51+ $ this ->assertEquals ($ id , $ bounce ->getID ());
4452 }
4553
4654 public function testClientCanGetBounceDump ()
@@ -51,5 +59,71 @@ public function testClientCanGetBounceDump()
5159 $ id = $ bounces ->Bounces [0 ]->getID ();
5260 $ dump = $ client ->getBounceDump ($ id );
5361 $ this ->assertNotEmpty ($ dump );
62+ $ this ->assertNotEmpty ($ dump ->getBody ());
63+ }
64+
65+ public function testClientCanActivateBounce ()
66+ {
67+ $ tk = parent ::$ testKeys ;
68+ $ client = new PostmarkClient ($ tk ->WRITE_TEST_SERVER_TOKEN , $ tk ->TEST_TIMEOUT );
69+
70+ // make sure that this email is not suppressed
71+ // generate a bounces
72+ $ fromEmail = $ tk ->WRITE_TEST_SENDER_EMAIL_ADDRESS ;
73+ $ toEmail = "hardbounce@bounce-testing.postmarkapp.com " ; // special email to generate bounce
74+ $ subject = "Hello from Postmark! " ;
75+ $ htmlBody = "<strong>Hello</strong> dear Postmark user. " ;
76+ $ textBody = "Hello dear Postmark user. " ;
77+ $ tag = "example-email-tag " ;
78+ $ trackOpens = true ;
79+ $ trackLinks = "None " ;
80+
81+ $ sendResult = $ client ->sendEmail (
82+ $ fromEmail ,
83+ $ toEmail ,
84+ $ subject ,
85+ $ htmlBody ,
86+ $ textBody ,
87+ $ tag ,
88+ $ trackOpens ,
89+ NULL , // Reply To
90+ NULL , // CC
91+ NULL , // BCC
92+ NULL , // Header array
93+ NULL , // Attachment array
94+ $ trackLinks ,
95+ NULL // Metadata array
96+ );
97+
98+ // make sure there is enough time for the bounce to take place.
99+ sleep (180 );
100+
101+ $ bounceList = $ client ->getBounces (20 , 0 );
102+ $ id = 0 ;
103+ $ sentId = $ sendResult ->getMessageID ();
104+ $ bounces = $ bounceList ->getBounces ();
105+
106+ $ this ->assertNotEmpty ($ bounces );
107+ $ this ->assertNotEmpty ($ sentId );
108+
109+ foreach ($ bounces as $ bounce )
110+ {
111+ $ bmid = $ bounce ->getMessageID ();
112+ echo "\n Bounce ID: $ bmid Sent id: $ sentId " ;
113+ if ($ sentId === $ bmid )
114+ {
115+ $ id = $ bounce ->getID ();
116+ echo "Made it!! $ id " ;
117+ break ;
118+ }
119+ }
120+
121+ $ this ->assertGreaterThan (0 , $ id );
122+
123+ $ bounceActivation = $ client ->activateBounce ($ id );
124+ $ actBounce = $ bounceActivation ->getBounce ();
125+
126+ $ this ->assertNotEmpty ($ actBounce );
127+ $ this ->assertEquals ($ id , $ actBounce ->getID ());
54128 }
55129}
0 commit comments