1111 *
1212 * Trait to mixin to your test to allow for custom assertions when using PHPUnit with Laravel.
1313 *
14- * This originally started out as a copy & paste from a video series that Jeffery Way did on laracasts.com. If you do
15- * not have an account on Laracasts, you should get one. It is an amazing resource to learn from. We used that
16- * example & converted it to a package so that it would be easy to install. We have also expanded on initial
14+ * This originally started out as a copy & paste from a video series that Jeffrey Way did on laracasts.com. If you do
15+ * not have an account on Laracasts, you should get one. It is an amazing resource to learn from. We used that
16+ * example & converted it to a package so that it would be easy to install. We have also expanded on the initial
1717 * assertions.
1818 *
19- * I WANT IT CLEAR THAT THIS WOULD NOT HAVE HAPPENED WITHOUT THE INITIAL WORK OF JEFFERY WAY. WE ARE NOT CLAIMING TO
19+ * I WANT IT CLEAR THAT THIS WOULD NOT HAVE HAPPENED WITHOUT THE INITIAL WORK OF JEFFREY WAY. WE ARE NOT CLAIMING TO
2020 * BE THE CREATORS OF THE CONCEPT.
2121 *
2222 * @package Spinen\MailAssertions
@@ -41,8 +41,8 @@ trait MailTracking
4141 /**
4242 * Register a listener for new emails.
4343 *
44- * Called my PHPUnit before each test it run. It registers the MailRecorder "plugin" with Swift, so that we can
45- * get a copy of each email that is sent during that test.
44+ * This calls my PHPUnit before each test it runs. It registers the MailRecorder "plugin" with Swift, so that we
45+ * can get a copy of each email that is sent during that test.
4646 *
4747 * @before
4848 */
@@ -53,7 +53,7 @@ public function setUpMailTracking()
5353 }
5454
5555 /**
56- * Retrieve the appropriate swift message.
56+ * Retrieve the appropriate Swift message.
5757 *
5858 * @param Swift_Message|null $message
5959 *
@@ -67,15 +67,15 @@ protected function getEmail(Swift_Message $message = null)
6767 }
6868
6969 /**
70- * Retrieve the mostly recently sent swift message.
70+ * Retrieve the mostly recently sent Swift message.
7171 */
7272 protected function lastEmail ()
7373 {
7474 return end ($ this ->emails );
7575 }
7676
7777 /**
78- * Store a new swift message.
78+ * Store a new Swift message.
7979 *
8080 * Collection of emails that were received by the MailRecorder plugin during a test.
8181 *
@@ -97,7 +97,7 @@ public function recordMail(Swift_Message $email)
9797 protected function seeEmailBcc ($ bcc , Swift_Message $ message = null )
9898 {
9999 $ this ->assertArrayHasKey ($ bcc , (array )$ this ->getEmail ($ message )
100- ->getBcc (), "No email was bcc'ed to $ bcc. " );
100+ ->getBcc (), "The last email sent was not bcc'ed to $ bcc. " );
101101
102102 return $ this ;
103103 }
@@ -113,7 +113,7 @@ protected function seeEmailBcc($bcc, Swift_Message $message = null)
113113 protected function seeEmailCc ($ cc , Swift_Message $ message = null )
114114 {
115115 $ this ->assertArrayHasKey ($ cc , (array )$ this ->getEmail ($ message )
116- ->getCc (), "No email was cc'ed to $ cc. " );
116+ ->getCc (), "The last email sent was not cc'ed to $ cc. " );
117117
118118 return $ this ;
119119 }
@@ -129,7 +129,7 @@ protected function seeEmailCc($cc, Swift_Message $message = null)
129129 protected function seeEmailContains ($ excerpt , Swift_Message $ message = null )
130130 {
131131 $ this ->assertContains ($ excerpt , $ this ->getEmail ($ message )
132- ->getBody (), "No email containing the provided body was found . " );
132+ ->getBody (), "The last email sent did not contain the provided body. " );
133133
134134 return $ this ;
135135 }
@@ -146,7 +146,7 @@ protected function seeEmailDoesNotContain($excerpt, Swift_Message $message = nul
146146 {
147147 $ this ->assertNotContains ($ excerpt , $ this ->getEmail ($ message )
148148 ->getBody (),
149- "Email containing the provided text was found in the body. " );
149+ "The last email sent contained the provided text in its body. " );
150150
151151 return $ this ;
152152 }
@@ -162,7 +162,7 @@ protected function seeEmailDoesNotContain($excerpt, Swift_Message $message = nul
162162 protected function seeEmailEquals ($ body , Swift_Message $ message = null )
163163 {
164164 $ this ->assertEquals ($ body , $ this ->getEmail ($ message )
165- ->getBody (), "No email with the provided body was sent . " );
165+ ->getBody (), "The last email sent did not match the given email . " );
166166
167167 return $ this ;
168168 }
@@ -179,7 +179,7 @@ protected function seeEmailFrom($sender, Swift_Message $message = null)
179179 {
180180 // TODO: Allow from to be an array to check email & name
181181 $ this ->assertArrayHasKey ($ sender , (array )$ this ->getEmail ($ message )
182- ->getFrom (), "No email was sent from $ sender. " );
182+ ->getFrom (), "The last email sent was not sent from $ sender. " );
183183
184184 return $ this ;
185185 }
@@ -195,7 +195,8 @@ protected function seeEmailFrom($sender, Swift_Message $message = null)
195195 protected function seeEmailReplyTo ($ reply_to , Swift_Message $ message = null )
196196 {
197197 $ this ->assertArrayHasKey ($ reply_to , (array )$ this ->getEmail ($ message )
198- ->getReplyTo (), "No email was set to reply to $ reply_to. " );
198+ ->getReplyTo (),
199+ "The last email sent was not set to reply to $ reply_to. " );
199200
200201 return $ this ;
201202 }
@@ -227,7 +228,8 @@ protected function seeEmailsSent($count)
227228 protected function seeEmailSubject ($ subject , Swift_Message $ message = null )
228229 {
229230 $ this ->assertEquals ($ subject , $ this ->getEmail ($ message )
230- ->getSubject (), "No email with a subject of $ subject was found. " );
231+ ->getSubject (),
232+ "The last email sent did not contain a subject of $ subject. " );
231233
232234 return $ this ;
233235 }
@@ -243,7 +245,8 @@ protected function seeEmailSubject($subject, Swift_Message $message = null)
243245 protected function seeEmailSubjectContains ($ excerpt , Swift_Message $ message = null )
244246 {
245247 $ this ->assertContains ($ excerpt , $ this ->getEmail ($ message )
246- ->getSubject (), "No email containing the provided subject was found. " );
248+ ->getSubject (),
249+ "The last email sent did not contain the provided subject. " );
247250
248251 return $ this ;
249252 }
@@ -260,7 +263,7 @@ protected function seeEmailSubjectDoesNotContain($excerpt, Swift_Message $messag
260263 {
261264 $ this ->assertNotContains ($ excerpt , $ this ->getEmail ($ message )
262265 ->getSubject (),
263- "Email containing the provided text was found in the subject. " );
266+ "The last email sent contained the provided text in its subject. " );
264267
265268 return $ this ;
266269 }
@@ -276,7 +279,7 @@ protected function seeEmailSubjectDoesNotContain($excerpt, Swift_Message $messag
276279 protected function seeEmailTo ($ recipient , Swift_Message $ message = null )
277280 {
278281 $ this ->assertArrayHasKey ($ recipient , (array )$ this ->getEmail ($ message )
279- ->getTo (), "No email was sent to $ recipient. " );
282+ ->getTo (), "The last email sent was not sent to $ recipient. " );
280283
281284 return $ this ;
282285 }
@@ -288,7 +291,9 @@ protected function seeEmailTo($recipient, Swift_Message $message = null)
288291 */
289292 protected function seeEmailWasNotSent ()
290293 {
291- $ this ->assertEmpty ($ this ->emails , 'Did not expect any emails to have been sent. ' );
294+ $ emailsSent = count ($ this ->emails );
295+
296+ $ this ->assertEmpty ($ this ->emails , "Did not expect any emails to have been sent, but found $ emailsSent " );
292297
293298 return $ this ;
294299 }
@@ -300,7 +305,7 @@ protected function seeEmailWasNotSent()
300305 */
301306 protected function seeEmailWasSent ()
302307 {
303- $ this ->assertNotEmpty ($ this ->emails , 'No emails have been sent. ' );
308+ $ this ->assertNotEmpty ($ this ->emails , 'Expected at least one email to be sent, but found none . ' );
304309
305310 return $ this ;
306311 }
0 commit comments