@@ -695,4 +695,60 @@ public function testEmailsWithAttachmentsWhichAreAFileInstanceCanBeUnserialized(
695695 $ this ->assertCount (1 , $ attachments );
696696 $ this ->assertStringContainsString ('foo_bar_xyz_123 ' , $ attachments [0 ]->getBody ());
697697 }
698+
699+ public function testInvalidBodyWithEmptyEmail ()
700+ {
701+ $ this ->expectException (\LogicException::class);
702+ $ this ->expectExceptionMessage ('A message must have a text or an HTML part or attachments. ' );
703+
704+ (new Email ())->ensureValidity ();
705+ }
706+
707+ public function testBodyWithTextIsValid ()
708+ {
709+ $ email = new Email ();
710+ $ email ->to ('test@example.com ' )
711+ ->from ('test@example.com ' )
712+ ->text ('foo ' );
713+
714+ $ email ->ensureValidity ();
715+
716+ $ this ->expectNotToPerformAssertions ();
717+ }
718+
719+ public function testBodyWithHtmlIsValid ()
720+ {
721+ $ email = new Email ();
722+ $ email ->to ('test@example.com ' )
723+ ->from ('test@example.com ' )
724+ ->html ('foo ' );
725+
726+ $ email ->ensureValidity ();
727+
728+ $ this ->expectNotToPerformAssertions ();
729+ }
730+
731+ public function testEmptyBodyWithAttachmentsIsValid ()
732+ {
733+ $ email = new Email ();
734+ $ email ->to ('test@example.com ' )
735+ ->from ('test@example.com ' )
736+ ->addPart (new DataPart ('foo ' ));
737+
738+ $ email ->ensureValidity ();
739+
740+ $ this ->expectNotToPerformAssertions ();
741+ }
742+
743+ public function testSetBodyIsValid ()
744+ {
745+ $ email = new Email ();
746+ $ email ->to ('test@example.com ' )
747+ ->from ('test@example.com ' )
748+ ->setBody (new TextPart ('foo ' ));
749+
750+ $ email ->ensureValidity ();
751+
752+ $ this ->expectNotToPerformAssertions ();
753+ }
698754}
0 commit comments