Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Component/Mime/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public function ensureValidity()

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 src/Symfony/Component/Mime/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();
}
}