Skip to content

Commit 2fc3b4b

Browse files
committed
Merge branch '7.1' into 7.2
* 7.1: [FrameworkBundle] Add missing `not-compromised-password` entry in XSD [AssetMapper] Fix CssCompiler matches url in comments Add support for doctrine/persistence 4 Ensure TransportExceptionInterface populates stream debug data Fix typo in validators.sk.xlf [Mime] Fix body validity check in `Email` when using `Message::setBody()` Review Arabic translations for the validator Fixed mistakes in proper hebrew writing in the previous translation and confirmed the rest to be correct and in the same style. Review translation [Cache] Don't clear system caches on cache:clear [FrameworkBundle] Fix patching refs to the tmp warmup dir in files generated by optional cache warmers Mark Czech Validator translation as reviewed [PropertyInfo] Fix `TypeTest` duplicated assert [Validator] Fix `Url` constraint attribute assertion convert legacy types to TypeInfo types if getType() is not implemented [HtmlSanitizer] Avoid accessing non existent array key when checking for hosts validity Update validators.ar.xlf [DomCrawler] Make `ChoiceFormField::isDisabled` return `true` for unchecked disabled checkboxes
2 parents 7f9617f + c252e20 commit 2fc3b4b

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

Email.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ public function ensureValidity(): void
401401

402402
private function ensureBodyValid(): void
403403
{
404-
if (null === $this->text && null === $this->html && !$this->attachments) {
404+
if (null === $this->text && null === $this->html && !$this->attachments && null === parent::getBody()) {
405405
throw new LogicException('A message must have a text or an HTML part or attachments.');
406406
}
407407
}

Tests/EmailTest.php

+56
Original file line numberDiff line numberDiff line change
@@ -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('[email protected]')
711+
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('[email protected]')
723+
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('[email protected]')
735+
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('[email protected]')
747+
748+
->setBody(new TextPart('foo'));
749+
750+
$email->ensureValidity();
751+
752+
$this->expectNotToPerformAssertions();
753+
}
698754
}

0 commit comments

Comments
 (0)