Skip to content
Permalink
Browse files

Add test for mailers not being reset on error.

Refs #10059
Refs #10070
  • Loading branch information...
markstory committed Jan 22, 2017
1 parent e1164a7 commit 0ab2d073ee2c73233f156337fd3c2e33488d587d
Showing with 28 additions and 0 deletions.
  1. +28 −0 tests/TestCase/Mailer/MailerTest.php
@@ -13,6 +13,7 @@
namespace Cake\Test\TestCase\Mailer;
use Cake\TestSuite\TestCase;
use RuntimeException;
use TestApp\Mailer\TestMailer;
class MailerTest extends TestCase
@@ -138,6 +139,33 @@ public function testSendWithUnsetTemplateDefaultsToActionName()
$this->assertEquals($mailer->template, 'test');
}
/**
* Test that mailers call reset() when send fails
*/
public function testSendFailsEmailIsReset()
{
$email = $this->getMockForEmail(['send', 'reset']);
$email->expects($this->once())
->method('send')
->will($this->throwException(new RuntimeException('kaboom')));
$mailer = $this->getMockBuilder('TestApp\Mailer\TestMailer')
->setMethods(['welcome', 'reset'])
->setConstructorArgs([$email])
->getMock();
// Mailer should be reset even if sending fails.
$mailer->expects($this->once())
->method('reset');
try {
$mailer->send('welcome', ['foo', 'bar']);
$this->fail('Exception should bubble up.');
} catch (RuntimeException $e) {
$this->assertTrue(true, 'Exception was raised');
}
}
/**
* test that initial email instance config is restored after email is sent.
*

0 comments on commit 0ab2d07

Please sign in to comment.
You can’t perform that action at this time.