@@ -169,6 +169,28 @@ public function attachments_are_added_to_the_email()
169169 $ this ->assertEquals ('application/pdf ' , $ attachment ->getContentType ());
170170 }
171171
172+ /** @test */
173+ public function attachments_are_not_added_if_the_data_is_not_valid ()
174+ {
175+ $ this ->sent = [];
176+ $ this ->composeEmail ()->attach (null )->send ();
177+ $ this ->artisan ('email:send ' );
178+ $ attachments = reset ($ this ->sent )->getMessage ()->getChildren ();
179+ $ this ->assertCount (0 , $ attachments );
180+
181+ $ this ->sent = [];
182+ $ this ->composeEmail ()->attach (false )->send ();
183+ $ this ->artisan ('email:send ' );
184+ $ attachments = reset ($ this ->sent )->getMessage ()->getChildren ();
185+ $ this ->assertCount (0 , $ attachments );
186+
187+ $ this ->sent = [];
188+ $ this ->composeEmail ()->attach ('' )->send ();
189+ $ this ->artisan ('email:send ' );
190+ $ attachments = reset ($ this ->sent )->getMessage ()->getChildren ();
191+ $ this ->assertCount (0 , $ attachments );
192+ }
193+
172194 /** @test */
173195 public function raw_attachments_are_added_to_the_email ()
174196 {
@@ -207,4 +229,26 @@ public function emails_can_be_sent_immediately()
207229 $ this ->artisan ('email:send ' );
208230 $ this ->assertCount (1 , $ this ->sent );
209231 }
232+
233+ /** @test */
234+ public function raw_attachments_are_not_added_if_the_data_is_not_valid ()
235+ {
236+ $ this ->sent = [];
237+ $ this ->composeEmail ()->attachData (null , 'test.png ' )->send ();
238+ $ this ->artisan ('email:send ' );
239+ $ attachments = reset ($ this ->sent )->getMessage ()->getChildren ();
240+ $ this ->assertCount (0 , $ attachments );
241+
242+ $ this ->sent = [];
243+ $ this ->composeEmail ()->attachData (false , 'test.png ' )->send ();
244+ $ this ->artisan ('email:send ' );
245+ $ attachments = reset ($ this ->sent )->getMessage ()->getChildren ();
246+ $ this ->assertCount (0 , $ attachments );
247+
248+ $ this ->sent = [];
249+ $ this ->composeEmail ()->attachData ('' , 'test.png ' )->send ();
250+ $ this ->artisan ('email:send ' );
251+ $ attachments = reset ($ this ->sent )->getMessage ()->getChildren ();
252+ $ this ->assertCount (0 , $ attachments );
253+ }
210254}
0 commit comments