mirror of
https://github.com/Seldaek/monolog.git
synced 2025-07-29 17:30:14 +02:00
Changed the tests for the abstract handlers to use a mock instead of the TestHandler
This commit is contained in:
@@ -29,7 +29,7 @@ class AbstractHandlerTest extends TestCase
|
||||
*/
|
||||
public function testConstructAndGetSet()
|
||||
{
|
||||
$handler = new TestHandler(Logger::WARNING, false);
|
||||
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler', array(Logger::WARNING, false));
|
||||
$this->assertEquals(Logger::WARNING, $handler->getLevel());
|
||||
$this->assertEquals(false, $handler->getBubble());
|
||||
|
||||
@@ -38,7 +38,7 @@ class AbstractHandlerTest extends TestCase
|
||||
$handler->setFormatter($formatter = new LineFormatter);
|
||||
$this->assertEquals(Logger::ERROR, $handler->getLevel());
|
||||
$this->assertEquals(true, $handler->getBubble());
|
||||
$this->assertEquals($formatter, $handler->getFormatter());
|
||||
$this->assertSame($formatter, $handler->getFormatter());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,9 +46,10 @@ class AbstractHandlerTest extends TestCase
|
||||
*/
|
||||
public function testHandleBatch()
|
||||
{
|
||||
$handler = new TestHandler();
|
||||
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler');
|
||||
$handler->expects($this->exactly(2))
|
||||
->method('handle');
|
||||
$handler->handleBatch(array($this->getRecord(), $this->getRecord()));
|
||||
$this->assertEquals(2, count($handler->getRecords()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,7 +57,7 @@ class AbstractHandlerTest extends TestCase
|
||||
*/
|
||||
public function testIsHandling()
|
||||
{
|
||||
$handler = new TestHandler(Logger::WARNING, false);
|
||||
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler', array(Logger::WARNING, false));
|
||||
$this->assertTrue($handler->isHandling($this->getRecord()));
|
||||
$this->assertFalse($handler->isHandling($this->getRecord(Logger::DEBUG)));
|
||||
}
|
||||
@@ -67,7 +68,7 @@ class AbstractHandlerTest extends TestCase
|
||||
*/
|
||||
public function testGetFormatterInitializesDefault()
|
||||
{
|
||||
$handler = new TestHandler();
|
||||
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler');
|
||||
$this->assertInstanceOf('Monolog\Formatter\LineFormatter', $handler->getFormatter());
|
||||
}
|
||||
|
||||
@@ -78,7 +79,7 @@ class AbstractHandlerTest extends TestCase
|
||||
*/
|
||||
public function testPushPopProcessor()
|
||||
{
|
||||
$logger = new TestHandler();
|
||||
$logger = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler');
|
||||
$processor1 = new WebProcessor;
|
||||
$processor2 = new WebProcessor;
|
||||
|
||||
@@ -90,4 +91,14 @@ class AbstractHandlerTest extends TestCase
|
||||
$logger->popProcessor();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Monolog\Handler\AbstractHandler::pushProcessor
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testPushProcessorWithNonCallable()
|
||||
{
|
||||
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler');
|
||||
|
||||
$handler->pushProcessor(new \stdClass());
|
||||
}
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ class AbstractProcessingHandlerTest extends TestCase
|
||||
*/
|
||||
public function testHandleLowerLevelMessage()
|
||||
{
|
||||
$handler = new TestHandler(Logger::WARNING, true);
|
||||
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler', array(Logger::WARNING, true));
|
||||
$this->assertFalse($handler->handle($this->getRecord(Logger::DEBUG)));
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class AbstractProcessingHandlerTest extends TestCase
|
||||
*/
|
||||
public function testHandleBubbling()
|
||||
{
|
||||
$handler = new TestHandler(Logger::DEBUG, true);
|
||||
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler', array(Logger::DEBUG, true));
|
||||
$this->assertFalse($handler->handle($this->getRecord()));
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class AbstractProcessingHandlerTest extends TestCase
|
||||
*/
|
||||
public function testHandleNotBubbling()
|
||||
{
|
||||
$handler = new TestHandler(Logger::DEBUG, false);
|
||||
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler', array(Logger::DEBUG, false));
|
||||
$this->assertTrue($handler->handle($this->getRecord()));
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ class AbstractProcessingHandlerTest extends TestCase
|
||||
*/
|
||||
public function testHandleIsFalseWhenNotHandled()
|
||||
{
|
||||
$handler = new TestHandler(Logger::WARNING, false);
|
||||
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler', array(Logger::WARNING, false));
|
||||
$this->assertTrue($handler->handle($this->getRecord()));
|
||||
$this->assertFalse($handler->handle($this->getRecord(Logger::DEBUG)));
|
||||
}
|
||||
@@ -59,14 +59,20 @@ class AbstractProcessingHandlerTest extends TestCase
|
||||
*/
|
||||
public function testProcessRecord()
|
||||
{
|
||||
$handler = new TestHandler();
|
||||
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler');
|
||||
$handler->pushProcessor(new WebProcessor(array(
|
||||
'REQUEST_URI' => '',
|
||||
'REQUEST_METHOD' => '',
|
||||
'REMOTE_ADDR' => '',
|
||||
)));
|
||||
$handledRecord = null;
|
||||
$handler->expects($this->once())
|
||||
->method('write')
|
||||
->will($this->returnCallback(function($record) use (&$handledRecord){
|
||||
$handledRecord = $record;
|
||||
}))
|
||||
;
|
||||
$handler->handle($this->getRecord());
|
||||
list($record) = $handler->getRecords();
|
||||
$this->assertEquals(3, count($record['extra']));
|
||||
$this->assertEquals(3, count($handledRecord['extra']));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user