2011-04-22 17:41:10 +02:00
|
|
|
<?php
|
|
|
|
|
2011-04-25 01:48:12 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the Monolog package.
|
|
|
|
*
|
|
|
|
* (c) Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2011-04-22 17:41:10 +02:00
|
|
|
namespace Monolog\Handler;
|
|
|
|
|
|
|
|
use Monolog\Logger;
|
|
|
|
use Monolog\TestCase;
|
|
|
|
|
|
|
|
class MailHandlerTest extends TestCase
|
|
|
|
{
|
2011-06-29 20:23:08 +02:00
|
|
|
/**
|
|
|
|
* @covers Monolog\Handler\MailHandler::handleBatch
|
|
|
|
*/
|
2011-04-22 17:41:10 +02:00
|
|
|
public function testHandleBatch()
|
|
|
|
{
|
2011-05-08 15:18:58 +02:00
|
|
|
$formatter = $this->getMock('Monolog\\Formatter\\FormatterInterface');
|
|
|
|
$formatter->expects($this->once())
|
|
|
|
->method('formatBatch'); // Each record is formatted
|
|
|
|
|
2011-04-22 17:41:10 +02:00
|
|
|
$handler = $this->getMockForAbstractClass('Monolog\\Handler\\MailHandler');
|
|
|
|
$handler->expects($this->once())
|
|
|
|
->method('send');
|
|
|
|
$handler->expects($this->never())
|
|
|
|
->method('write'); // write is for individual records
|
2011-05-08 15:18:58 +02:00
|
|
|
|
2011-04-22 17:41:10 +02:00
|
|
|
$handler->setFormatter($formatter);
|
2011-05-08 15:18:58 +02:00
|
|
|
|
|
|
|
$handler->handleBatch($this->getMultipleRecords());
|
2011-04-22 17:41:10 +02:00
|
|
|
}
|
2011-05-08 15:18:58 +02:00
|
|
|
|
2011-06-29 20:23:08 +02:00
|
|
|
/**
|
|
|
|
* @covers Monolog\Handler\MailHandler::handleBatch
|
|
|
|
*/
|
2011-04-28 18:02:38 +02:00
|
|
|
public function testHandleBatchNotSendsMailIfMessagesAreBelowLevel()
|
|
|
|
{
|
|
|
|
$records = array(
|
|
|
|
$this->getRecord(Logger::DEBUG, 'debug message 1'),
|
|
|
|
$this->getRecord(Logger::DEBUG, 'debug message 2'),
|
|
|
|
$this->getRecord(Logger::INFO, 'information'),
|
|
|
|
);
|
2011-05-08 15:18:58 +02:00
|
|
|
|
2011-04-28 18:02:38 +02:00
|
|
|
$handler = $this->getMockForAbstractClass('Monolog\\Handler\\MailHandler');
|
|
|
|
$handler->expects($this->never())
|
|
|
|
->method('send');
|
|
|
|
$handler->setLevel(Logger::ERROR);
|
2011-05-08 15:18:58 +02:00
|
|
|
|
2011-04-28 18:02:38 +02:00
|
|
|
$handler->handleBatch($records);
|
|
|
|
}
|
2011-05-08 15:18:58 +02:00
|
|
|
|
2011-06-29 20:23:08 +02:00
|
|
|
/**
|
|
|
|
* @covers Monolog\Handler\MailHandler::write
|
|
|
|
*/
|
2011-04-22 17:41:10 +02:00
|
|
|
public function testHandle()
|
|
|
|
{
|
|
|
|
$handler = $this->getMockForAbstractClass('Monolog\\Handler\\MailHandler');
|
2012-04-22 18:25:08 +02:00
|
|
|
|
|
|
|
$record = $this->getRecord();
|
|
|
|
$records = array($record);
|
|
|
|
$records[0]['formatted'] = '['.$record['datetime']->format('Y-m-d H:i:s').'] test.WARNING: test [] []'."\n";
|
|
|
|
|
2011-04-22 17:41:10 +02:00
|
|
|
$handler->expects($this->once())
|
2012-04-22 18:25:08 +02:00
|
|
|
->method('send')
|
|
|
|
->with($records[0]['formatted'], $records);
|
2011-05-08 15:18:58 +02:00
|
|
|
|
2012-04-22 18:25:08 +02:00
|
|
|
$handler->handle($record);
|
2011-04-22 17:41:10 +02:00
|
|
|
}
|
2012-06-14 15:46:17 +02:00
|
|
|
}
|