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

Added a Processor stack to the Logger class, added getHandler() to check if any handler is going to handle the message before processing it, handlers are now calling their parent in a chain

This commit is contained in:
Jordi Boggiano
2011-02-21 20:38:18 +01:00
parent 8d27400122
commit a426ce2815
5 changed files with 93 additions and 52 deletions

View File

@@ -29,8 +29,36 @@ class AbstractHandlerTest extends \PHPUnit_Framework_TestCase
public function testHandleBubbling()
{
$handler = new TestHandler(Logger::DEBUG, true);
$this->assertFalse($handler->handle($this->getMessage()));
$topHandler = new TestHandler(Logger::DEBUG, true);
$bottomHandler = new TestHandler(Logger::INFO);
$topHandler->setParent($bottomHandler);
$this->assertTrue($topHandler->handle($this->getMessage()));
$this->assertTrue($bottomHandler->hasWarningMessages());
}
public function testHandleNotBubbling()
{
$topHandler = new TestHandler(Logger::DEBUG);
$bottomHandler = new TestHandler(Logger::INFO);
$topHandler->setParent($bottomHandler);
$this->assertTrue($topHandler->handle($this->getMessage()));
$this->assertFalse($bottomHandler->hasWarningMessages());
}
public function testGetHandlerReturnEarly()
{
$topHandler = new TestHandler(Logger::DEBUG);
$bottomHandler = new TestHandler(Logger::INFO);
$topHandler->setParent($bottomHandler);
$this->assertEquals($topHandler, $topHandler->getHandler($this->getMessage()));
}
public function testGetHandlerReturnsParent()
{
$topHandler = new TestHandler(Logger::ERROR);
$bottomHandler = new TestHandler(Logger::INFO);
$topHandler->setParent($bottomHandler);
$this->assertEquals($bottomHandler, $topHandler->getHandler($this->getMessage()));
}
protected function getMessage($level = Logger::WARNING)

View File

@@ -22,28 +22,19 @@ class LoggerTest extends \PHPUnit_Framework_TestCase
->method('handle');
$logger->pushHandler($handler);
$logger->addWarning('test');
$this->assertTrue($logger->addWarning('test'));
}
/**
* @dataProvider logValues
*/
public function testLogUntilHandled($bubble)
public function testLogNoHandler()
{
$logger = new Logger(__METHOD__);
$bottomHandler = $this->getMock('Monolog\Handler\NullHandler', array('handle'));
$bottomHandler->expects($bubble ? $this->once() : $this->never())
$handler = $this->getMock('Monolog\Handler\NullHandler', array('handle'), array(Logger::ERROR));
$handler->expects($this->never())
->method('handle');
$logger->pushHandler($bottomHandler);
$logger->pushHandler($handler);
$topHandler = $this->getMock('Monolog\Handler\NullHandler', array('handle'));
$topHandler->expects($this->once())
->method('handle')
->will($this->returnValue(!$bubble));
$logger->pushHandler($topHandler);
$logger->addWarning('test');
$this->assertFalse($logger->addWarning('test'));
}
public function logValues()