forked from swiftmailer/swiftmailer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report RFC exceptions as send failures (if sending a message) rather …
…than letting the bubble up.
- Loading branch information
Showing
2 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
require_once 'Swift/Tests/SwiftUnitTestCase.php'; | ||
require_once 'Swift/Mailer.php'; | ||
require_once 'Swift/RfcComplianceException.php'; | ||
require_once 'Swift/Transport.php'; | ||
require_once 'Swift/Mime/Message.php'; | ||
require_once 'Swift/Mailer/RecipientIterator.php'; | ||
|
@@ -251,6 +252,48 @@ public function testBatchSendCanReadFromIterator() | |
$mailer->batchSend($message, $failures, $it); | ||
} | ||
|
||
public function testSendRecordsRfcComplianceExceptionAsEntireSendFailure() | ||
{ | ||
$failures = array(); | ||
|
||
$rfcException = new Swift_RfcComplianceException('test'); | ||
$transport = $this->_createTransport(); | ||
$message = $this->_createMessage(); | ||
$this->_checking(Expectations::create() | ||
-> allowing($message)->getTo() -> returns(array('foo&invalid' => 'Foo', '[email protected]' => 'Bar')) | ||
-> one($transport)->send($message, reference($failures)) -> throws($rfcException) | ||
-> ignoring($transport) | ||
-> ignoring($message) | ||
); | ||
|
||
$mailer = $this->_createMailer($transport); | ||
$this->assertEqual(0, $mailer->send($message, $failures), '%s: Should return 0'); | ||
$this->assertEqual(array('foo&invalid', '[email protected]'), $failures, '%s: Failures should contain all addresses since the entire message failed to compile'); | ||
} | ||
|
||
public function testBatchSendRecordsRfcComplianceExceptionAsIndividualRecipientFailure() | ||
{ | ||
$failures = array(); | ||
|
||
$rfcException = new Swift_RfcComplianceException('test'); | ||
$transport = $this->_createTransport(); | ||
$message = $this->_createMessage(); | ||
$this->_checking(Expectations::create() | ||
-> one($message)->getTo() -> returns(array('foo&invalid' => 'Foo', '[email protected]' => 'Bar')) | ||
-> one($message)->setTo(array('foo&invalid' => 'Foo')) | ||
-> one($message)->getTo() -> returns(array('foo&invalid' => 'Foo')) | ||
-> one($message)->setTo(array('[email protected]' => 'Bar')) | ||
-> one($transport)->send($message, reference($failures)) -> throws($rfcException) | ||
-> one($transport)->send($message, reference($failures)) -> returns(1) | ||
-> ignoring($transport) | ||
-> ignoring($message) | ||
); | ||
|
||
$mailer = $this->_createMailer($transport); | ||
$this->assertEqual(1, $mailer->batchSend($message, $failures), '%s: Should return just 1'); | ||
$this->assertEqual(array('foo&invalid'), $failures, '%s: Failures should contain the non-compliant address'); | ||
} | ||
|
||
public function testRegisterPluginDelegatesToTransport() | ||
{ | ||
$plugin = $this->_createPlugin(); | ||
|