Skip to content

Commit

Permalink
Merge branch '7.1' into 7.2
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
xabbuh committed Jan 27, 2025
2 parents 7f9617f + c252e20 commit 2fc3b4b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ public function ensureValidity(): void

private function ensureBodyValid(): void
{
if (null === $this->text && null === $this->html && !$this->attachments) {
if (null === $this->text && null === $this->html && !$this->attachments && null === parent::getBody()) {
throw new LogicException('A message must have a text or an HTML part or attachments.');
}
}
Expand Down
56 changes: 56 additions & 0 deletions Tests/EmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -695,4 +695,60 @@ public function testEmailsWithAttachmentsWhichAreAFileInstanceCanBeUnserialized(
$this->assertCount(1, $attachments);
$this->assertStringContainsString('foo_bar_xyz_123', $attachments[0]->getBody());
}

public function testInvalidBodyWithEmptyEmail()
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('A message must have a text or an HTML part or attachments.');

(new Email())->ensureValidity();
}

public function testBodyWithTextIsValid()
{
$email = new Email();
$email->to('[email protected]')
->from('[email protected]')
->text('foo');

$email->ensureValidity();

$this->expectNotToPerformAssertions();
}

public function testBodyWithHtmlIsValid()
{
$email = new Email();
$email->to('[email protected]')
->from('[email protected]')
->html('foo');

$email->ensureValidity();

$this->expectNotToPerformAssertions();
}

public function testEmptyBodyWithAttachmentsIsValid()
{
$email = new Email();
$email->to('[email protected]')
->from('[email protected]')
->addPart(new DataPart('foo'));

$email->ensureValidity();

$this->expectNotToPerformAssertions();
}

public function testSetBodyIsValid()
{
$email = new Email();
$email->to('[email protected]')
->from('[email protected]')
->setBody(new TextPart('foo'));

$email->ensureValidity();

$this->expectNotToPerformAssertions();
}
}

0 comments on commit 2fc3b4b

Please sign in to comment.