1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-08 06:06:40 +02:00

Swift_Message creation is now lazy when using callback

Swift_Message object is not created until right before the message is
sent, if it is sent at all. This prevents the expensive Swift_Mailer
autoloader from being invoked.

Swift_Mailer is now also required to run test suite
This commit is contained in:
John Kary
2015-03-01 19:25:14 -06:00
parent 1b34cd4d88
commit f5eaeeb144
3 changed files with 64 additions and 10 deletions

View File

@@ -0,0 +1,37 @@
<?php
namespace Monolog\Handler;
use Monolog\Logger;
use Monolog\TestCase;
class SwiftMailerHandlerTest extends TestCase
{
/** @var \Swift_Mailer|\PHPUnit_Framework_MockObject_MockObject */
private $mailer;
public function setUp()
{
$this->mailer = $this
->getMockBuilder('Swift_Mailer')
->disableOriginalConstructor()
->getMock();
}
public function testMessageCreationIsLazyWhenUsingCallback()
{
$this->mailer->expects($this->never())
->method('send');
$callback = function () {
throw new \RuntimeException('Swift_Message creation callback should not have been called in this test');
};
$handler = new SwiftMailerHandler($this->mailer, $callback);
$records = [
$this->getRecord(Logger::DEBUG),
$this->getRecord(Logger::INFO),
];
$handler->handleBatch($records);
}
}