mirror of
https://github.com/Seldaek/monolog.git
synced 2025-07-30 18:00:17 +02:00
More testing coverage
This commit is contained in:
@@ -81,6 +81,9 @@ abstract class AbstractHandler implements HandlerInterface
|
|||||||
*/
|
*/
|
||||||
public function popProcessor()
|
public function popProcessor()
|
||||||
{
|
{
|
||||||
|
if (!$this->processors) {
|
||||||
|
throw new \LogicException('You tried to pop from an empty processor stack.');
|
||||||
|
}
|
||||||
return array_shift($this->processors);
|
return array_shift($this->processors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -43,16 +43,6 @@ abstract class AbstractProcessingHandler extends AbstractHandler
|
|||||||
return false === $this->bubble;
|
return false === $this->bubble;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function handleBatch(array $records)
|
|
||||||
{
|
|
||||||
foreach ($records as $record) {
|
|
||||||
$this->handle($record);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the record down to the log of the implementing handler
|
* Writes the record down to the log of the implementing handler
|
||||||
*
|
*
|
||||||
|
@@ -13,9 +13,44 @@ namespace Monolog\Handler;
|
|||||||
|
|
||||||
use Monolog\TestCase;
|
use Monolog\TestCase;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
|
use Monolog\Formatter\LineFormatter;
|
||||||
|
use Monolog\Processor\WebProcessor;
|
||||||
|
|
||||||
class AbstractHandlerTest extends TestCase
|
class AbstractHandlerTest extends TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @covers Monolog\Handler\AbstractHandler::__construct
|
||||||
|
* @covers Monolog\Handler\AbstractHandler::getLevel
|
||||||
|
* @covers Monolog\Handler\AbstractHandler::setLevel
|
||||||
|
* @covers Monolog\Handler\AbstractHandler::getBubble
|
||||||
|
* @covers Monolog\Handler\AbstractHandler::setBubble
|
||||||
|
* @covers Monolog\Handler\AbstractHandler::getFormatter
|
||||||
|
* @covers Monolog\Handler\AbstractHandler::setFormatter
|
||||||
|
*/
|
||||||
|
public function testConstructAndGetSet()
|
||||||
|
{
|
||||||
|
$handler = new TestHandler(Logger::WARNING, false);
|
||||||
|
$this->assertEquals(Logger::WARNING, $handler->getLevel());
|
||||||
|
$this->assertEquals(false, $handler->getBubble());
|
||||||
|
|
||||||
|
$handler->setLevel(Logger::ERROR);
|
||||||
|
$handler->setBubble(true);
|
||||||
|
$handler->setFormatter($formatter = new LineFormatter);
|
||||||
|
$this->assertEquals(Logger::ERROR, $handler->getLevel());
|
||||||
|
$this->assertEquals(true, $handler->getBubble());
|
||||||
|
$this->assertEquals($formatter, $handler->getFormatter());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Monolog\Handler\AbstractHandler::handleBatch
|
||||||
|
*/
|
||||||
|
public function testHandleBatch()
|
||||||
|
{
|
||||||
|
$handler = new TestHandler();
|
||||||
|
$handler->handleBatch(array($this->getRecord(), $this->getRecord()));
|
||||||
|
$this->assertEquals(2, count($handler->getRecords()));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Monolog\Handler\AbstractHandler::isHandling
|
* @covers Monolog\Handler\AbstractHandler::isHandling
|
||||||
*/
|
*/
|
||||||
@@ -25,4 +60,34 @@ class AbstractHandlerTest extends TestCase
|
|||||||
$this->assertTrue($handler->isHandling($this->getRecord()));
|
$this->assertTrue($handler->isHandling($this->getRecord()));
|
||||||
$this->assertFalse($handler->isHandling($this->getRecord(Logger::DEBUG)));
|
$this->assertFalse($handler->isHandling($this->getRecord(Logger::DEBUG)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Monolog\Handler\AbstractHandler::getFormatter
|
||||||
|
* @covers Monolog\Handler\AbstractHandler::getDefaultFormatter
|
||||||
|
*/
|
||||||
|
public function testGetFormatterInitializesDefault()
|
||||||
|
{
|
||||||
|
$handler = new TestHandler();
|
||||||
|
$this->assertInstanceOf('Monolog\Formatter\LineFormatter', $handler->getFormatter());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Monolog\Handler\AbstractHandler::pushProcessor
|
||||||
|
* @covers Monolog\Handler\AbstractHandler::popProcessor
|
||||||
|
* @expectedException LogicException
|
||||||
|
*/
|
||||||
|
public function testPushPopProcessor()
|
||||||
|
{
|
||||||
|
$logger = new TestHandler();
|
||||||
|
$processor1 = new WebProcessor;
|
||||||
|
$processor2 = new WebProcessor;
|
||||||
|
|
||||||
|
$logger->pushProcessor($processor1);
|
||||||
|
$logger->pushProcessor($processor2);
|
||||||
|
|
||||||
|
$this->assertEquals($processor2, $logger->popProcessor());
|
||||||
|
$this->assertEquals($processor1, $logger->popProcessor());
|
||||||
|
$logger->popProcessor();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -13,6 +13,7 @@ namespace Monolog\Handler;
|
|||||||
|
|
||||||
use Monolog\TestCase;
|
use Monolog\TestCase;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
|
use Monolog\Processor\WebProcessor;
|
||||||
|
|
||||||
class AbstractProcessingHandlerTest extends TestCase
|
class AbstractProcessingHandlerTest extends TestCase
|
||||||
{
|
{
|
||||||
@@ -52,4 +53,20 @@ class AbstractProcessingHandlerTest extends TestCase
|
|||||||
$this->assertTrue($handler->handle($this->getRecord()));
|
$this->assertTrue($handler->handle($this->getRecord()));
|
||||||
$this->assertFalse($handler->handle($this->getRecord(Logger::DEBUG)));
|
$this->assertFalse($handler->handle($this->getRecord(Logger::DEBUG)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Monolog\Handler\AbstractProcessingHandler::processRecord
|
||||||
|
*/
|
||||||
|
public function testProcessRecord()
|
||||||
|
{
|
||||||
|
$handler = new TestHandler();
|
||||||
|
$handler->pushProcessor(new WebProcessor(array(
|
||||||
|
'REQUEST_URI' => '',
|
||||||
|
'REQUEST_METHOD' => '',
|
||||||
|
'REMOTE_ADDR' => '',
|
||||||
|
)));
|
||||||
|
$handler->handle($this->getRecord());
|
||||||
|
list($record) = $handler->getRecords();
|
||||||
|
$this->assertEquals(3, count($record['extra']));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -67,8 +67,8 @@ class LoggerTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testPushPopHandler()
|
public function testPushPopHandler()
|
||||||
{
|
{
|
||||||
$logger = new Logger(__METHOD__);
|
$logger = new Logger(__METHOD__);
|
||||||
$handler1 = $this->getMock('Monolog\Handler\NullHandler', array('handle'));
|
$handler1 = new TestHandler;
|
||||||
$handler2 = $this->getMock('Monolog\Handler\NullHandler', array('handle'));
|
$handler2 = new TestHandler;
|
||||||
|
|
||||||
$logger->pushHandler($handler1);
|
$logger->pushHandler($handler1);
|
||||||
$logger->pushHandler($handler2);
|
$logger->pushHandler($handler2);
|
||||||
|
Reference in New Issue
Block a user