1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-07-30 01:40:30 +02:00
Files
php-monolog/tests/Monolog/Handler/SwiftMailerHandlerTest.php
John Kary f5eaeeb144 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
2015-03-01 20:03:39 -06:00

38 lines
954 B
PHP

<?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);
}
}