mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-16 10:04:14 +02:00
Add ability to use formatter in email subject lines
This commit is contained in:
@@ -96,4 +96,16 @@ class NativeMailerHandlerTest extends TestCase
|
||||
$this->assertSame("From: $from\r\nContent-type: text/plain; charset=utf-8\r\n", $params[3]);
|
||||
$this->assertSame('', $params[4]);
|
||||
}
|
||||
|
||||
public function testMessageSubjectFormatting()
|
||||
{
|
||||
$mailer = new NativeMailerHandler('to@example.org', 'Alert: %level_name% %message%', 'from@example.org');
|
||||
$mailer->handle($this->getRecord(Logger::ERROR, "Foo\nBar\r\n\r\nBaz"));
|
||||
$this->assertNotEmpty($GLOBALS['mail']);
|
||||
$this->assertInternalType('array', $GLOBALS['mail']);
|
||||
$this->assertArrayHasKey('0', $GLOBALS['mail']);
|
||||
$params = $GLOBALS['mail'][0];
|
||||
$this->assertCount(5, $params);
|
||||
$this->assertSame('Alert: ERROR Foo Bar Baz', $params[1]);
|
||||
}
|
||||
}
|
||||
|
@@ -72,6 +72,30 @@ class SwiftMailerHandlerTest extends TestCase
|
||||
$handler->handleBatch($records);
|
||||
}
|
||||
|
||||
public function testMessageSubjectFormatting()
|
||||
{
|
||||
// Wire Mailer to expect a specific Swift_Message with a customized Subject
|
||||
$messageTemplate = new \Swift_Message();
|
||||
$messageTemplate->setSubject('Alert: %level_name% %message%');
|
||||
$receivedMessage = null;
|
||||
|
||||
$this->mailer->expects($this->once())
|
||||
->method('send')
|
||||
->with($this->callback(function ($value) use (&$receivedMessage) {
|
||||
$receivedMessage = $value;
|
||||
return true;
|
||||
}));
|
||||
|
||||
$handler = new SwiftMailerHandler($this->mailer, $messageTemplate);
|
||||
|
||||
$records = array(
|
||||
$this->getRecord(Logger::EMERGENCY),
|
||||
);
|
||||
$handler->handleBatch($records);
|
||||
|
||||
$this->assertEquals('Alert: EMERGENCY test', $receivedMessage->getSubject());
|
||||
}
|
||||
|
||||
public function testMessageHaveUniqueId()
|
||||
{
|
||||
$messageTemplate = \Swift_Message::newInstance();
|
||||
|
Reference in New Issue
Block a user