@@ -12,65 +12,65 @@ class EmailsTests extends \PHPUnit\Framework\TestCase
12
12
{
13
13
/** @var \Mailosaur\MailosaurClient
14
14
*/
15
- public $ client ;
15
+ protected static $ client ;
16
16
17
17
/** @var string */
18
- public $ server ;
18
+ protected static $ server ;
19
19
20
20
/** @var \Mailosaur\Models\MessageSummary[] */
21
- public $ emails ;
21
+ protected static $ emails ;
22
22
23
23
24
- public function setUp (): void
24
+ public static function setUpBeforeClass (): void
25
25
{
26
26
$ baseUrl = ($ h = getenv ('MAILOSAUR_BASE_URL ' )) ? $ h : 'https://mailosaur.com/ ' ;
27
27
$ apiKey = getenv ('MAILOSAUR_API_KEY ' );
28
- $ this -> server = getenv ('MAILOSAUR_SERVER ' );
28
+ self :: $ server = getenv ('MAILOSAUR_SERVER ' );
29
29
30
- if (empty ($ apiKey ) || empty ($ this -> server )) {
30
+ if (empty ($ apiKey ) || empty (self :: $ server )) {
31
31
throw new \Exception ('Missing necessary environment variables - refer to README.md ' );
32
32
}
33
33
34
- $ this -> client = new MailosaurClient ($ apiKey , $ baseUrl );
34
+ self :: $ client = new MailosaurClient ($ apiKey , $ baseUrl );
35
35
36
- $ this -> client ->messages ->deleteAll ($ this -> server );
36
+ self :: $ client ->messages ->deleteAll (self :: $ server );
37
37
38
- Mailer::sendEmails ($ this -> client , $ this -> server , 5 );
38
+ Mailer::sendEmails (self :: $ client , self :: $ server , 5 );
39
39
40
- $ this -> emails = $ this -> client ->messages ->all ($ this -> server )->items ;
40
+ self :: $ emails = self :: $ client ->messages ->all (self :: $ server )->items ;
41
41
}
42
42
43
43
public function testListWithReceivedAfter ()
44
44
{
45
45
$ pastDate = new \DateTime ();
46
46
$ pastDate ->sub (new \DateInterval ('PT10M ' ));
47
- $ pastEmails = $ this -> client ->messages ->all ($ this -> server , null , null , $ pastDate )->items ;
47
+ $ pastEmails = self :: $ client ->messages ->all (self :: $ server , null , null , $ pastDate )->items ;
48
48
$ this ->assertTrue (count ($ pastEmails ) > 0 );
49
49
50
- $ futureEmails = $ this -> client ->messages ->all ($ this -> server , null , null , new \DateTime ())->items ;
50
+ $ futureEmails = self :: $ client ->messages ->all (self :: $ server , null , null , new \DateTime ())->items ;
51
51
$ this ->assertCount (0 , $ futureEmails );
52
52
}
53
53
54
54
public function testGet ()
55
55
{
56
56
$ host = ($ h = getenv ('MAILOSAUR_SMTP_HOST ' )) ? $ h : 'mailosaur.io ' ;
57
- $ testEmailAddress = 'wait_for_test. ' . $ this -> server . '@ ' . $ host ;
57
+ $ testEmailAddress = 'wait_for_test. ' . self :: $ server . '@ ' . $ host ;
58
58
59
- Mailer::sendEmail ($ this -> client , $ this -> server , $ testEmailAddress );
59
+ Mailer::sendEmail (self :: $ client , self :: $ server , $ testEmailAddress );
60
60
61
61
$ criteria = new SearchCriteria ();
62
62
$ criteria ->sentTo = $ testEmailAddress ;
63
63
64
- $ email = $ this -> client ->messages ->get ($ this -> server , $ criteria );
64
+ $ email = self :: $ client ->messages ->get (self :: $ server , $ criteria );
65
65
66
66
$ this ->validateEmail ($ email );
67
67
}
68
68
69
69
public function testGetById ()
70
70
{
71
- $ emailToRetrieve = $ this -> emails [0 ];
71
+ $ emailToRetrieve = self :: $ emails [0 ];
72
72
73
- $ email = $ this -> client ->messages ->getById ($ emailToRetrieve ->id );
73
+ $ email = self :: $ client ->messages ->getById ($ emailToRetrieve ->id );
74
74
75
75
$ this ->validateEmail ($ email );
76
76
$ this ->validateHeaders ($ email );
@@ -79,32 +79,32 @@ public function testGetById()
79
79
public function testGetByIdNotFound ()
80
80
{
81
81
$ this ->expectException (\Mailosaur \Models \MailosaurException::class);
82
- $ this -> client ->messages ->getById (uniqid ());
82
+ self :: $ client ->messages ->getById (uniqid ());
83
83
}
84
84
85
85
public function testSearchNoCriteriaError ()
86
86
{
87
87
$ this ->expectException (\Mailosaur \Models \MailosaurException::class);
88
- $ this -> client ->messages ->search ($ this -> server , new SearchCriteria ());
88
+ self :: $ client ->messages ->search (self :: $ server , new SearchCriteria ());
89
89
}
90
90
91
91
public function testSearchTimeoutErrorsSuppressed ()
92
92
{
93
93
$ criteria = new SearchCriteria ();
94
94
$ criteria->
sentFrom =
'[email protected] ' ;
95
- $ results = $ this -> client ->messages ->search ($ this -> server , $ criteria , 0 , 1 , 1 , new \DateTime (), false )->items ;
95
+ $ results = self :: $ client ->messages ->search (self :: $ server , $ criteria , 0 , 1 , 1 , new \DateTime (), false )->items ;
96
96
$ this ->assertCount (0 , $ results );
97
97
}
98
98
99
99
public function testSearchBySentFrom ()
100
100
{
101
- $ targetEmail = $ this -> emails [1 ];
101
+ $ targetEmail = self :: $ emails [1 ];
102
102
103
103
$ criteria = new SearchCriteria ();
104
104
105
105
$ criteria ->sentFrom = $ targetEmail ->from [0 ]->email ;
106
106
107
- $ results = $ this -> client ->messages ->search ($ this -> server , $ criteria )->items ;
107
+ $ results = self :: $ client ->messages ->search (self :: $ server , $ criteria )->items ;
108
108
109
109
$ this ->assertCount (1 , $ results );
110
110
$ this ->assertEquals ($ targetEmail ->from [0 ]->email , $ results [0 ]->from [0 ]->email );
@@ -118,18 +118,18 @@ public function testSearchBySentFromInvalidEmail()
118
118
$ criteria = new SearchCriteria ();
119
119
$ criteria ->sentFrom = '.not_an_email_address ' ;
120
120
121
- $ this -> client ->messages ->search ($ this -> server , $ criteria );
121
+ self :: $ client ->messages ->search (self :: $ server , $ criteria );
122
122
}
123
123
124
124
public function testSearchBySentTo ()
125
125
{
126
- $ targetEmail = $ this -> emails [1 ];
126
+ $ targetEmail = self :: $ emails [1 ];
127
127
128
128
$ criteria = new SearchCriteria ();
129
129
130
130
$ criteria ->sentTo = $ targetEmail ->to [0 ]->email ;
131
131
132
- $ results = $ this -> client ->messages ->search ($ this -> server , $ criteria )->items ;
132
+ $ results = self :: $ client ->messages ->search (self :: $ server , $ criteria )->items ;
133
133
134
134
$ this ->assertCount (1 , $ results );
135
135
$ this ->assertEquals ($ targetEmail ->to [0 ]->email , $ results [0 ]->to [0 ]->email );
@@ -143,17 +143,17 @@ public function testSearchBySentToInvalidEmail()
143
143
$ criteria = new SearchCriteria ();
144
144
$ criteria ->sentTo = '.not_an_email_address ' ;
145
145
146
- $ this -> client ->messages ->search ($ this -> server , $ criteria );
146
+ self :: $ client ->messages ->search (self :: $ server , $ criteria );
147
147
}
148
148
149
149
public function testSearchByBody ()
150
150
{
151
- $ targetEmail = $ this -> emails [1 ];
151
+ $ targetEmail = self :: $ emails [1 ];
152
152
$ uniqueString = substr ($ targetEmail ->subject , 0 , 10 );
153
153
$ criteria = new SearchCriteria ();
154
154
$ criteria ->body = $ uniqueString . ' html ' ;
155
155
156
- $ results = $ this -> client ->messages ->search ($ this -> server , $ criteria )->items ;
156
+ $ results = self :: $ client ->messages ->search (self :: $ server , $ criteria )->items ;
157
157
158
158
$ this ->assertCount (1 , $ results );
159
159
$ this ->assertEquals ($ targetEmail ->to [0 ]->email , $ results [0 ]->to [0 ]->email );
@@ -162,11 +162,11 @@ public function testSearchByBody()
162
162
163
163
public function testSearchBySubject ()
164
164
{
165
- $ targetEmail = $ this -> emails [1 ];
165
+ $ targetEmail = self :: $ emails [1 ];
166
166
$ criteria = new SearchCriteria ();
167
167
$ criteria ->subject = substr ($ targetEmail ->subject , 0 , 10 );
168
168
169
- $ results = $ this -> client ->messages ->search ($ this -> server , $ criteria )->items ;
169
+ $ results = self :: $ client ->messages ->search (self :: $ server , $ criteria )->items ;
170
170
171
171
$ this ->assertCount (1 , $ results );
172
172
$ this ->assertEquals ($ targetEmail ->to [0 ]->email , $ results [0 ]->to [0 ]->email );
@@ -175,45 +175,45 @@ public function testSearchBySubject()
175
175
176
176
public function testSearchMatchAll ()
177
177
{
178
- $ targetEmail = $ this -> emails [1 ];
178
+ $ targetEmail = self :: $ emails [1 ];
179
179
$ criteria = new SearchCriteria ();
180
180
$ criteria ->subject = substr ($ targetEmail ->subject , 0 , 10 );
181
181
$ criteria ->body = 'this is a link ' ;
182
182
$ criteria ->match = 'ALL ' ;
183
183
184
- $ results = $ this -> client ->messages ->search ($ this -> server , $ criteria )->items ;
184
+ $ results = self :: $ client ->messages ->search (self :: $ server , $ criteria )->items ;
185
185
186
186
$ this ->assertCount (1 , $ results );
187
187
}
188
188
189
189
public function testSearchMatchAny ()
190
190
{
191
- $ targetEmail = $ this -> emails [1 ];
191
+ $ targetEmail = self :: $ emails [1 ];
192
192
$ criteria = new SearchCriteria ();
193
193
$ criteria ->subject = substr ($ targetEmail ->subject , 0 , 10 );
194
194
$ criteria ->body = 'this is a link ' ;
195
195
$ criteria ->match = 'ANY ' ;
196
196
197
- $ results = $ this -> client ->messages ->search ($ this -> server , $ criteria )->items ;
197
+ $ results = self :: $ client ->messages ->search (self :: $ server , $ criteria )->items ;
198
198
199
- $ this ->assertCount (5 , $ results );
199
+ $ this ->assertCount (6 , $ results );
200
200
}
201
201
202
202
public function testSearchWithSpecialCharacters ()
203
203
{
204
204
$ criteria = new SearchCriteria ();
205
205
$ criteria ->subject = 'Search with ellipsis … and emoji 👨🏿🚒 ' ;
206
206
207
- $ results = $ this -> client ->messages ->search ($ this -> server , $ criteria )->items ;
207
+ $ results = self :: $ client ->messages ->search (self :: $ server , $ criteria )->items ;
208
208
209
209
$ this ->assertCount (0 , $ results );
210
210
}
211
211
212
212
public function testSpamAnalysis ()
213
213
{
214
- $ targetId = $ this -> emails [0 ]->id ;
214
+ $ targetId = self :: $ emails [0 ]->id ;
215
215
216
- $ result = $ this -> client ->analysis ->spam ($ targetId );
216
+ $ result = self :: $ client ->analysis ->spam ($ targetId );
217
217
218
218
foreach ($ result ->spamFilterResults ->spamAssassin as $ rule ) {
219
219
$ this ->assertNotEmpty ($ rule ->rule );
@@ -223,19 +223,19 @@ public function testSpamAnalysis()
223
223
224
224
public function testDelete ()
225
225
{
226
- $ targetEmailId = $ this -> emails [4 ]->id ;
226
+ $ targetEmailId = self :: $ emails [4 ]->id ;
227
227
228
- $ this -> client ->messages ->delete ($ targetEmailId );
228
+ self :: $ client ->messages ->delete ($ targetEmailId );
229
229
230
230
$ this ->expectException (\Mailosaur \Models \MailosaurException::class);
231
231
232
- $ this -> client ->messages ->delete ($ targetEmailId );
232
+ self :: $ client ->messages ->delete ($ targetEmailId );
233
233
}
234
234
235
235
public function testAll ()
236
236
{
237
- foreach ($ this -> emails as $ emailSummary ) {
238
- $ this ->validateEmailSummary ($ emailSummary );
237
+ foreach (self :: $ emails as $ emailsummary ) {
238
+ $ this ->validateEmailSummary ($ emailsummary );
239
239
}
240
240
}
241
241
0 commit comments