Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitad833aa

Browse files
committed
refactor Email::generateBody()
1 parent1c2ac11 commitad833aa

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

‎src/Symfony/Component/Mailer/Mailer.php‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313

1414
usePsr\EventDispatcher\EventDispatcherInterface;
1515
useSymfony\Component\Mailer\Event\MessageEvent;
16-
useSymfony\Component\Mailer\Exception\LogicException;
1716
useSymfony\Component\Mailer\Messenger\SendEmailMessage;
1817
useSymfony\Component\Mailer\Transport\TransportInterface;
1918
useSymfony\Component\Messenger\MessageBusInterface;
20-
useSymfony\Component\Mime\Message;
2119
useSymfony\Component\Mime\RawMessage;
2220

2321
/**
@@ -38,10 +36,6 @@ public function __construct(TransportInterface $transport, MessageBusInterface $
3836

3937
publicfunctionsend(RawMessage$message,Envelope$envelope =null):void
4038
{
41-
if ($messageinstanceof Message &&'1' ===$message->getHeaders()->getHeaderBody('X-Unsent')) {
42-
thrownewLogicException('Cannot send messages marked as "draft".');
43-
}
44-
4539
if (null ===$this->bus) {
4640
$this->transport->send($message,$envelope);
4741

‎src/Symfony/Component/Mailer/Tests/MailerTest.php‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,4 @@ public function dispatch($message, array $stamps = []): Envelope
6969
self::assertCount(1,$bus->messages);
7070
self::assertSame($email,$bus->messages[0]->getMessage());
7171
}
72-
73-
publicfunctiontestCannotSendDraftEmails()
74-
{
75-
$transport =newMailer($this->createMock(TransportInterface::class),$this->createMock(MessageBusInterface::class),$this->createMock(EventDispatcherInterface::class));
76-
$email =newEmail();
77-
$email->getHeaders()->addTextHeader('X-Unsent','1');
78-
79-
$this->expectException(LogicException::class);
80-
81-
$transport->send($email);
82-
}
8372
}

‎src/Symfony/Component/Mime/Email.php‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -386,17 +386,22 @@ public function getBody(): AbstractPart
386386

387387
publicfunctionensureValidity()
388388
{
389-
if (null ===$this->text &&null ===$this->html && !$this->attachments) {
390-
thrownewLogicException('A message must have a text or an HTML part or attachments.');
391-
}
389+
$this->ensureBodyValid();
392390

393391
if ('1' ===$this->getHeaders()->getHeaderBody('X-Unsent')) {
394-
return;
392+
thrownewLogicException('Cannot send messages marked as "draft".');
395393
}
396394

397395
parent::ensureValidity();
398396
}
399397

398+
privatefunctionensureBodyValid():void
399+
{
400+
if (null ===$this->text &&null ===$this->html && !$this->attachments) {
401+
thrownewLogicException('A message must have a text or an HTML part or attachments.');
402+
}
403+
}
404+
400405
/**
401406
* Generates an AbstractPart based on the raw body of a message.
402407
*
@@ -419,7 +424,7 @@ public function ensureValidity()
419424
*/
420425
privatefunctiongenerateBody():AbstractPart
421426
{
422-
$this->ensureValidity();
427+
$this->ensureBodyValid();
423428

424429
[$htmlPart,$attachmentParts,$inlineParts] =$this->prepareParts();
425430

‎src/Symfony/Component/Mime/Tests/DraftEmailTest.php‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,17 @@ public function testMustHaveBody()
4242

4343
(newDraftEmail())->toString();
4444
}
45+
46+
publicfunctiontestEnsureValidityAlwaysFails()
47+
{
48+
$email = (newDraftEmail())
49+
->to('alice@example.com')
50+
->from('webmaster@example.com')
51+
->text('some text')
52+
;
53+
54+
$this->expectException(LogicException::class);
55+
56+
$email->ensureValidity();
57+
}
4558
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp