22
33namespace Spinen \MailAssertions ;
44
5- use Illuminate \Support \Facades \Mail ;
5+ use Illuminate \Container \Container ;
6+ use Illuminate \Contracts \Container \BindingResolutionException ;
7+ use Illuminate \Contracts \Mail \Mailer ;
68use Swift_Message ;
79
810/**
@@ -48,15 +50,30 @@ trait MailTracking
4850 public function setUpMailTracking ()
4951 {
5052 $ register_plugin = function () {
51- Mail::getSwiftMailer ()
52- ->registerPlugin (new MailRecorder ($ this ));
53+ $ this ->resolveMailer ()
54+ ->getSwiftMailer ()
55+ ->registerPlugin (new MailRecorder ($ this ));
5356 };
5457
5558 $ this ->afterApplicationCreated (function () use ($ register_plugin ) {
5659 $ register_plugin ();
5760 });
5861 }
5962
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+
6077 /**
6178 * Retrieve the appropriate Swift message.
6279 *
@@ -133,8 +150,8 @@ protected function seeEmailCc($cc, Swift_Message $message = null)
133150 */
134151 protected function seeEmailContains ($ excerpt , Swift_Message $ message = null )
135152 {
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. " );
138155
139156 return $ this ;
140157 }
@@ -167,9 +184,8 @@ protected function seeEmailContentTypeEquals($content_type, Swift_Message $messa
167184 */
168185 protected function seeEmailDoesNotContain ($ excerpt , Swift_Message $ message = null )
169186 {
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. " );
173189
174190 return $ this ;
175191 }
@@ -297,9 +313,8 @@ protected function seeEmailSubject($subject, Swift_Message $message = null)
297313 */
298314 protected function seeEmailSubjectContains ($ excerpt , Swift_Message $ message = null )
299315 {
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. " );
303318
304319 return $ this ;
305320 }
@@ -314,9 +329,8 @@ protected function seeEmailSubjectContains($excerpt, Swift_Message $message = nu
314329 */
315330 protected function seeEmailSubjectDoesNotContain ($ excerpt , Swift_Message $ message = null )
316331 {
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. " );
320334
321335 return $ this ;
322336 }
@@ -332,8 +346,7 @@ protected function seeEmailSubjectDoesNotContain($excerpt, Swift_Message $messag
332346 protected function seeEmailSubjectEquals ($ subject , Swift_Message $ message = null )
333347 {
334348 $ 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. " );
337350
338351 return $ this ;
339352 }
0 commit comments