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 }
@@ -145,7 +145,7 @@ protected function seeEmailContains($excerpt, Swift_Message $message = null)
145145 protected function seeEmailDoesNotContain ($ excerpt , Swift_Message $ message = null )
146146 {
147147 $ this ->assertNotContains ($ excerpt , $ this ->getEmail ($ message )
148- ->getBody (), "Email containing the provided text was found in the body. " );
148+ ->getBody (), "The last email sent contained the provided text in its body. " );
149149
150150 return $ this ;
151151 }
@@ -161,7 +161,7 @@ protected function seeEmailDoesNotContain($excerpt, Swift_Message $message = nul
161161 protected function seeEmailEquals ($ body , Swift_Message $ message = null )
162162 {
163163 $ this ->assertEquals ($ body , $ this ->getEmail ($ message )
164- ->getBody (), "No email with the provided body was sent . " );
164+ ->getBody (), "The last email sent did not match the given email . " );
165165
166166 return $ this ;
167167 }
@@ -178,7 +178,7 @@ protected function seeEmailFrom($sender, Swift_Message $message = null)
178178 {
179179 // TODO: Allow from to be an array to check email & name
180180 $ this ->assertArrayHasKey ($ sender , (array )$ this ->getEmail ($ message )
181- ->getFrom (), "No email was sent from $ sender. " );
181+ ->getFrom (), "The last email sent was not sent from $ sender. " );
182182
183183 return $ this ;
184184 }
@@ -194,7 +194,7 @@ protected function seeEmailFrom($sender, Swift_Message $message = null)
194194 protected function seeEmailReplyTo ($ reply_to , Swift_Message $ message = null )
195195 {
196196 $ this ->assertArrayHasKey ($ reply_to , (array )$ this ->getEmail ($ message )
197- ->getReplyTo (), "No email was set to reply to $ reply_to. " );
197+ ->getReplyTo (), "The last email sent was not set to reply to $ reply_to. " );
198198
199199 return $ this ;
200200 }
@@ -227,7 +227,7 @@ protected function seeEmailSubject($subject, Swift_Message $message = null)
227227 {
228228 // TODO: Consider a subject contains like the message contains
229229 $ this ->assertEquals ($ subject , $ this ->getEmail ($ message )
230- ->getSubject (), "No email with a subject of $ subject was found . " );
230+ ->getSubject (), "The last email sent did not contain a subject of $ subject. " );
231231
232232 return $ this ;
233233 }
@@ -243,7 +243,7 @@ protected function seeEmailSubject($subject, Swift_Message $message = null)
243243 protected function seeEmailTo ($ recipient , Swift_Message $ message = null )
244244 {
245245 $ this ->assertArrayHasKey ($ recipient , (array )$ this ->getEmail ($ message )
246- ->getTo (), "No email was sent to $ recipient. " );
246+ ->getTo (), "The last email sent was not sent to $ recipient. " );
247247
248248 return $ this ;
249249 }
@@ -255,7 +255,9 @@ protected function seeEmailTo($recipient, Swift_Message $message = null)
255255 */
256256 protected function seeEmailWasNotSent ()
257257 {
258- $ this ->assertEmpty ($ this ->emails , 'Did not expect any emails to have been sent. ' );
258+ $ emailsSent = count ($ this ->emails );
259+
260+ $ this ->assertEmpty ($ this ->emails , "Did not expect any emails to have been sent, but found $ emailsSent " );
259261
260262 return $ this ;
261263 }
@@ -267,7 +269,7 @@ protected function seeEmailWasNotSent()
267269 */
268270 protected function seeEmailWasSent ()
269271 {
270- $ this ->assertNotEmpty ($ this ->emails , 'No emails have been sent. ' );
272+ $ this ->assertNotEmpty ($ this ->emails , 'Expected at least one email to be sent, but found none . ' );
271273
272274 return $ this ;
273275 }
0 commit comments