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:
37
tests/Monolog/Handler/SwiftMailerHandlerTest.php
Normal file
37
tests/Monolog/Handler/SwiftMailerHandlerTest.php
Normal 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user