@@ -16,7 +16,7 @@ trait MakesMailAssertions
1616 /**
1717 * @var Mailer
1818 */
19- private static $ emailSender ;
19+ private $ emailSender ;
2020
2121 /**
2222 * See that there is no email sent
@@ -26,7 +26,7 @@ trait MakesMailAssertions
2626 public function assertEmailNotSent ($ message = 'An unexpected email was sent. ' )
2727 {
2828 $ this ->assertNull (
29- $ this ->lastEmail (),
29+ $ this ->getLastEmail (),
3030 $ message
3131 );
3232
@@ -41,7 +41,7 @@ public function assertEmailNotSent($message = 'An unexpected email was sent.')
4141 public function assertEmailSent ($ message = 'Unable to find a generated email. ' )
4242 {
4343 $ this ->assertNotNull (
44- $ this ->lastEmail (),
44+ $ this ->getlastEmail (),
4545 $ message
4646 );
4747
@@ -107,23 +107,34 @@ public function assertLastEmailContains($string)
107107 {
108108 $ this ->assertEmailSent ();
109109 $ this ->assertTrue (
110- $ this ->lastEmail ()->contains ($ string ),
111- sprintf ("%s \n Could not find [%s] in the above message. " , $ this ->lastEmail ()->getBody (), $ string )
110+ $ this ->getLastEmail ()->contains ($ string ),
111+ sprintf ("%s \n Could not find [%s] in the above message. " , $ this ->getLastEmail ()->getBody (), $ string )
112112 );
113113 }
114114
115+ /**
116+ * @after
117+ */
118+ public function emptyMail ()
119+ {
120+ $ this ->getEmailSender ()->empty ();
121+ \Mockery::close ();
122+ }
123+
115124 /**
116125 * @before
117126 */
118127 public function fakeMail ()
119128 {
120- if (method_exists ($ this , 'afterApplicationCreated ' )) {
121- $ this ->afterApplicationCreated (function () {
122- $ this ->mockMailFacade ();
123- });
124- } else {
125- $ this ->mockMailFacade ();
126- }
129+ Mail::shouldReceive ('send ' )->andReturnUsing (function (...$ args ) {
130+ $ this ->getEmailSender ()->send (...$ args );
131+ });
132+
133+ Mail::shouldReceive ('raw ' )->andReturnUsing (function (...$ args ) {
134+ $ this ->getEmailSender ()->sendRaw (...$ args );
135+ });
136+
137+ Mail::shouldReceive ('failures ' );
127138 }
128139
129140 /**
@@ -132,7 +143,7 @@ public function fakeMail()
132143 */
133144 public function getEmails (): Collection
134145 {
135- return $ this ->getEmailSender ()->getEmails ();
146+ return $ this ->getEmailSender ()->all ();
136147 }
137148
138149 /**
@@ -161,38 +172,15 @@ public function getLastEmailFor($email)
161172 */
162173 public function getLastEmail ()
163174 {
164- return $ this ->getEmailSender ()->lastEmail ();
175+ return $ this ->getEmailSender ()->last ();
165176 }
166177
167-
168178 /**
169179 * Gets the sender class
170180 * @return Mailer
171181 */
172182 private function getEmailSender ()
173183 {
174- if (static ::$ emailSender === null ) {
175- static ::$ emailSender = new Mailer ;
176- }
177-
178- return static ::$ emailSender ;
179- }
180-
181- /**
182- * Mock the mail facade
183- * @return void
184- */
185- private function mockMailFacade ()
186- {
187- $ this ->getEmailSender ()->empty ();
188- Mail::shouldReceive ('send ' )->andReturnUsing (function (...$ args ) {
189- $ this ->getEmailSender ()->send (...$ args );
190- });
191-
192- Mail::shouldReceive ('raw ' )->andReturnUsing (function (...$ args ) {
193- $ this ->getEmailSender ()->sendRaw (...$ args );
194- });
195-
196- Mail::shouldReceive ('failures ' );
184+ return Mailer::instance ();
197185 }
198186}
0 commit comments