1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-02-23 22:42:38 +01:00
php-monolog/tests/Monolog/Handler/MailHandlerTest.php

76 lines
2.2 KiB
PHP
Raw Normal View History

2011-04-22 17:41:10 +02:00
<?php
/*
* 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
{
/**
* @covers Monolog\Handler\MailHandler::handleBatch
*/
2011-04-22 17:41:10 +02:00
public function testHandleBatch()
{
$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-04-22 17:41:10 +02:00
$handler->setFormatter($formatter);
$handler->handleBatch($this->getMultipleRecords());
2011-04-22 17:41:10 +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-04-28 18:02:38 +02:00
$handler = $this->getMockForAbstractClass('Monolog\\Handler\\MailHandler');
$handler->expects($this->never())
->method('send');
$handler->setLevel(Logger::ERROR);
2011-04-28 18:02:38 +02:00
$handler->handleBatch($records);
}
/**
* @covers Monolog\Handler\MailHandler::write
*/
2011-04-22 17:41:10 +02:00
public function testHandle()
{
$handler = $this->getMockForAbstractClass('Monolog\\Handler\\MailHandler');
$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())
->method('send')
->with($records[0]['formatted'], $records);
$handler->handle($record);
2011-04-22 17:41:10 +02:00
}
2012-06-14 15:46:17 +02:00
}