@@ -167,6 +167,28 @@ public function attachments_are_added_to_the_email()
167167 $ this ->assertEquals ('application/pdf ' , $ attachment ->getContentType ());
168168 }
169169
170+ /** @test */
171+ public function attachments_are_not_added_if_the_data_is_not_valid ()
172+ {
173+ $ this ->sent = [];
174+ $ this ->composeEmail ()->attach (null )->send ();
175+ $ this ->artisan ('email:send ' );
176+ $ attachments = reset ($ this ->sent )->getMessage ()->getChildren ();
177+ $ this ->assertCount (0 , $ attachments );
178+
179+ $ this ->sent = [];
180+ $ this ->composeEmail ()->attach (false )->send ();
181+ $ this ->artisan ('email:send ' );
182+ $ attachments = reset ($ this ->sent )->getMessage ()->getChildren ();
183+ $ this ->assertCount (0 , $ attachments );
184+
185+ $ this ->sent = [];
186+ $ this ->composeEmail ()->attach ('' )->send ();
187+ $ this ->artisan ('email:send ' );
188+ $ attachments = reset ($ this ->sent )->getMessage ()->getChildren ();
189+ $ this ->assertCount (0 , $ attachments );
190+ }
191+
170192 /** @test */
171193 public function raw_attachments_are_added_to_the_email ()
172194 {
@@ -189,4 +211,26 @@ public function raw_attachments_are_added_to_the_email()
189211 $ this ->assertEquals ('application/pdf ' , $ attachment ->getContentType ());
190212 $ this ->assertContains ('Hello CI! ' , $ attachment ->getBody ());
191213 }
214+
215+ /** @test */
216+ public function raw_attachments_are_not_added_if_the_data_is_not_valid ()
217+ {
218+ $ this ->sent = [];
219+ $ this ->composeEmail ()->attachData (null , 'test.png ' )->send ();
220+ $ this ->artisan ('email:send ' );
221+ $ attachments = reset ($ this ->sent )->getMessage ()->getChildren ();
222+ $ this ->assertCount (0 , $ attachments );
223+
224+ $ this ->sent = [];
225+ $ this ->composeEmail ()->attachData (false , 'test.png ' )->send ();
226+ $ this ->artisan ('email:send ' );
227+ $ attachments = reset ($ this ->sent )->getMessage ()->getChildren ();
228+ $ this ->assertCount (0 , $ attachments );
229+
230+ $ this ->sent = [];
231+ $ this ->composeEmail ()->attachData ('' , 'test.png ' )->send ();
232+ $ this ->artisan ('email:send ' );
233+ $ attachments = reset ($ this ->sent )->getMessage ()->getChildren ();
234+ $ this ->assertCount (0 , $ attachments );
235+ }
192236}
0 commit comments