2
2
3
3
namespace Spinen \MailAssertions ;
4
4
5
- use Illuminate \Support \Facades \Mail ;
5
+ use Illuminate \Container \Container ;
6
+ use Illuminate \Contracts \Container \BindingResolutionException ;
7
+ use Illuminate \Contracts \Mail \Mailer ;
6
8
use Swift_Message ;
7
9
8
10
/**
@@ -48,15 +50,30 @@ trait MailTracking
48
50
public function setUpMailTracking ()
49
51
{
50
52
$ register_plugin = function () {
51
- Mail::getSwiftMailer ()
52
- ->registerPlugin (new MailRecorder ($ this ));
53
+ $ this ->resolveMailer ()
54
+ ->getSwiftMailer ()
55
+ ->registerPlugin (new MailRecorder ($ this ));
53
56
};
54
57
55
58
$ this ->afterApplicationCreated (function () use ($ register_plugin ) {
56
59
$ register_plugin ();
57
60
});
58
61
}
59
62
63
+ /**
64
+ * Resolve the mailer from the IoC
65
+ *
66
+ * We are staying away from the Mail facade, so that we can support PHP 7.4 with Laravel 5.x
67
+ *
68
+ * @return Mailer
69
+ * @throws BindingResolutionException
70
+ */
71
+ protected function resolveMailer ()
72
+ {
73
+ return Container::getInstance ()
74
+ ->make (Mailer::class);
75
+ }
76
+
60
77
/**
61
78
* Retrieve the appropriate Swift message.
62
79
*
@@ -133,8 +150,8 @@ protected function seeEmailCc($cc, Swift_Message $message = null)
133
150
*/
134
151
protected function seeEmailContains ($ excerpt , Swift_Message $ message = null )
135
152
{
136
- $ this ->assertContains ($ excerpt , $ this ->getEmail ($ message )
137
- ->getBody (), "The last email sent did not contain the provided body. " );
153
+ $ this ->assertStringContainsString ($ excerpt , $ this ->getEmail ($ message )
154
+ ->getBody (), "The last email sent did not contain the provided body. " );
138
155
139
156
return $ this ;
140
157
}
@@ -167,9 +184,8 @@ protected function seeEmailContentTypeEquals($content_type, Swift_Message $messa
167
184
*/
168
185
protected function seeEmailDoesNotContain ($ excerpt , Swift_Message $ message = null )
169
186
{
170
- $ this ->assertNotContains ($ excerpt , $ this ->getEmail ($ message )
171
- ->getBody (),
172
- "The last email sent contained the provided text in its body. " );
187
+ $ this ->assertStringNotContainsString ($ excerpt , $ this ->getEmail ($ message )
188
+ ->getBody (), "The last email sent contained the provided text in its body. " );
173
189
174
190
return $ this ;
175
191
}
@@ -297,9 +313,8 @@ protected function seeEmailSubject($subject, Swift_Message $message = null)
297
313
*/
298
314
protected function seeEmailSubjectContains ($ excerpt , Swift_Message $ message = null )
299
315
{
300
- $ this ->assertContains ($ excerpt , $ this ->getEmail ($ message )
301
- ->getSubject (),
302
- "The last email sent did not contain the provided subject. " );
316
+ $ this ->assertStringContainsString ($ excerpt , $ this ->getEmail ($ message )
317
+ ->getSubject (), "The last email sent did not contain the provided subject. " );
303
318
304
319
return $ this ;
305
320
}
@@ -314,9 +329,8 @@ protected function seeEmailSubjectContains($excerpt, Swift_Message $message = nu
314
329
*/
315
330
protected function seeEmailSubjectDoesNotContain ($ excerpt , Swift_Message $ message = null )
316
331
{
317
- $ this ->assertNotContains ($ excerpt , $ this ->getEmail ($ message )
318
- ->getSubject (),
319
- "The last email sent contained the provided text in its subject. " );
332
+ $ this ->assertStringNotContainsString ($ excerpt , $ this ->getEmail ($ message )
333
+ ->getSubject (), "The last email sent contained the provided text in its subject. " );
320
334
321
335
return $ this ;
322
336
}
@@ -332,8 +346,7 @@ protected function seeEmailSubjectDoesNotContain($excerpt, Swift_Message $messag
332
346
protected function seeEmailSubjectEquals ($ subject , Swift_Message $ message = null )
333
347
{
334
348
$ this ->assertEquals ($ subject , $ this ->getEmail ($ message )
335
- ->getSubject (),
336
- "The last email sent did not contain a subject of $ subject. " );
349
+ ->getSubject (), "The last email sent did not contain a subject of $ subject. " );
337
350
338
351
return $ this ;
339
352
}
0 commit comments