99
1010class ResendTest extends Base
1111{
12- public function testSendEmail (): void
12+ private Resend $ sender ;
13+ private string $ testEmail ;
14+
15+ protected function setUp (): void
1316 {
17+ parent ::setUp ();
1418 $ key = \getenv ('RESEND_API_KEY ' );
15- $ sender = new Resend ($ key );
19+ $ this ->sender = new Resend ($ key );
20+ $ this ->testEmail = \getenv ('RESEND_TEST_EMAIL ' );
21+ }
1622
17- $ to = \getenv ('RESEND_TEST_EMAIL ' );
23+ public function testSendEmail (): void
24+ {
25+ $ to = $ this ->testEmail ;
1826 $ subject = 'Test Subject ' ;
1927 $ content = 'Test Content ' ;
20- $ fromEmail = \getenv ( ' RESEND_TEST_EMAIL ' ) ;
21- $ cc = [['email ' => \getenv ( ' RESEND_TEST_EMAIL ' ) ]];
22- $ bcc = [['name ' => 'Test BCC ' , 'email ' => \getenv ( ' RESEND_TEST_EMAIL ' ) ]];
28+ $ fromEmail = $ this -> testEmail ;
29+ $ cc = [['email ' => $ this -> testEmail ]];
30+ $ bcc = [['name ' => 'Test BCC ' , 'email ' => $ this -> testEmail ]];
2331
2432 $ message = new Email (
2533 to: [$ to ],
@@ -31,20 +39,17 @@ public function testSendEmail(): void
3139 bcc: $ bcc ,
3240 );
3341
34- $ response = $ sender ->send ($ message );
42+ $ response = $ this -> sender ->send ($ message );
3543
3644 $ this ->assertResponse ($ response );
3745 }
3846
3947 public function testSendEmailWithHtml (): void
4048 {
41- $ key = \getenv ('RESEND_API_KEY ' );
42- $ sender = new Resend ($ key );
43-
44- $ to = \getenv ('RESEND_TEST_EMAIL ' );
49+ $ to = $ this ->testEmail ;
4550 $ subject = 'Test HTML Subject ' ;
4651 $ content = '<h1>Test HTML Content</h1><p>This is a test email with HTML content.</p> ' ;
47- $ fromEmail = \getenv ( ' RESEND_TEST_EMAIL ' ) ;
52+ $ fromEmail = $ this -> testEmail ;
4853
4954 $ message = new Email (
5055 to: [$ to ],
@@ -55,21 +60,18 @@ public function testSendEmailWithHtml(): void
5560 html: true ,
5661 );
5762
58- $ response = $ sender ->send ($ message );
63+ $ response = $ this -> sender ->send ($ message );
5964
6065 $ this ->assertResponse ($ response );
6166 }
6267
6368 public function testSendEmailWithReplyTo (): void
6469 {
65- $ key = \getenv ('RESEND_API_KEY ' );
66- $ sender = new Resend ($ key );
67-
68- $ to = \getenv ('RESEND_TEST_EMAIL ' );
70+ $ to = $ this ->testEmail ;
6971 $ subject = 'Test Reply-To Subject ' ;
7072 $ content = 'Test Content with Reply-To ' ;
71- $ fromEmail = \getenv ( ' RESEND_TEST_EMAIL ' ) ;
72- $ replyToEmail = \getenv ( ' RESEND_TEST_EMAIL ' ) ;
73+ $ fromEmail = $ this -> testEmail ;
74+ $ replyToEmail = $ this -> testEmail ;
7375
7476 $ message = new Email (
7577 to: [$ to ],
@@ -81,21 +83,18 @@ public function testSendEmailWithReplyTo(): void
8183 replyToEmail: $ replyToEmail ,
8284 );
8385
84- $ response = $ sender ->send ($ message );
86+ $ response = $ this -> sender ->send ($ message );
8587
8688 $ this ->assertResponse ($ response );
8789 }
8890
8991 public function testSendMultipleEmails (): void
9092 {
91- $ key = \getenv ('RESEND_API_KEY ' );
92- $ sender = new Resend ($ key );
93-
94- $ to1 = \getenv ('RESEND_TEST_EMAIL ' );
95- $ to2 = \getenv ('RESEND_TEST_EMAIL ' );
93+ $ to1 = $ this ->testEmail ;
94+ $ to2 = $ this ->testEmail ;
9695 $ subject = 'Test Batch Subject ' ;
9796 $ content = 'Test Batch Content ' ;
98- $ fromEmail = \getenv ( ' RESEND_TEST_EMAIL ' ) ;
97+ $ fromEmail = $ this -> testEmail ;
9998
10099 $ message = new Email (
101100 to: [$ to1 , $ to2 ],
@@ -105,7 +104,7 @@ public function testSendMultipleEmails(): void
105104 fromEmail: $ fromEmail ,
106105 );
107106
108- $ response = $ sender ->send ($ message );
107+ $ response = $ this -> sender ->send ($ message );
109108
110109 $ this ->assertEquals (2 , $ response ['deliveredTo ' ], \var_export ($ response , true ));
111110 $ this ->assertEquals ('' , $ response ['results ' ][0 ]['error ' ], \var_export ($ response , true ));
@@ -119,13 +118,10 @@ public function testSendEmailWithAttachmentsThrowsException(): void
119118 $ this ->expectException (\Exception::class);
120119 $ this ->expectExceptionMessage ('Resend does not support attachments at this time ' );
121120
122- $ key = \getenv ('RESEND_API_KEY ' );
123- $ sender = new Resend ($ key );
124-
125- $ to = \getenv ('RESEND_TEST_EMAIL ' );
121+ $ to = $ this ->testEmail ;
126122 $ subject = 'Test Subject ' ;
127123 $ content = 'Test Content ' ;
128- $ fromEmail = \getenv ( ' RESEND_TEST_EMAIL ' ) ;
124+ $ fromEmail = $ this -> testEmail ;
129125
130126 $ message = new Email (
131127 to: [$ to ],
@@ -140,6 +136,6 @@ public function testSendEmailWithAttachmentsThrowsException(): void
140136 )],
141137 );
142138
143- $ sender ->send ($ message );
139+ $ this -> sender ->send ($ message );
144140 }
145141}
0 commit comments