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

Skip to content

Commit aee9d51

Browse files
committed
throw exception if calling Email::from() with no address
1 parent 0db9cf2 commit aee9d51

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/Symfony/Component/Mime/Email.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ public function addFrom(...$addresses)
121121
*/
122122
public function from(...$addresses)
123123
{
124+
if (!$addresses) {
125+
throw new LogicException(sprintf('"from()" must be called with at least one address.'));
126+
}
127+
124128
return $this->setListAddressHeaderBody('From', $addresses);
125129
}
126130

src/Symfony/Component/Mime/Tests/EmailTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPUnit\Framework\TestCase;
1616
use Symfony\Component\Mime\Address;
1717
use Symfony\Component\Mime\Email;
18+
use Symfony\Component\Mime\Exception\LogicException;
1819
use Symfony\Component\Mime\Part\DataPart;
1920
use Symfony\Component\Mime\Part\Multipart\AlternativePart;
2021
use Symfony\Component\Mime\Part\Multipart\MixedPart;
@@ -62,6 +63,13 @@ public function testSender()
6263
$this->assertSame($fabien, $e->getSender());
6364
}
6465

66+
public function testFromWithNoAddress()
67+
{
68+
$e = new Email();
69+
$this->expectException(LogicException::class);
70+
$e->from();
71+
}
72+
6573
public function testFrom()
6674
{
6775
$e = new Email();

0 commit comments

Comments
 (0)