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

Changed the tests for the abstract handlers to use a mock instead of the TestHandler

This commit is contained in:
Christophe Coevoet
2011-08-29 15:00:42 +02:00
parent 10e5ecd409
commit 8c094aa3b3
2 changed files with 31 additions and 14 deletions

View File

@@ -29,7 +29,7 @@ class AbstractHandlerTest extends TestCase
*/ */
public function testConstructAndGetSet() 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(Logger::WARNING, $handler->getLevel());
$this->assertEquals(false, $handler->getBubble()); $this->assertEquals(false, $handler->getBubble());
@@ -38,7 +38,7 @@ class AbstractHandlerTest extends TestCase
$handler->setFormatter($formatter = new LineFormatter); $handler->setFormatter($formatter = new LineFormatter);
$this->assertEquals(Logger::ERROR, $handler->getLevel()); $this->assertEquals(Logger::ERROR, $handler->getLevel());
$this->assertEquals(true, $handler->getBubble()); $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() 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())); $handler->handleBatch(array($this->getRecord(), $this->getRecord()));
$this->assertEquals(2, count($handler->getRecords()));
} }
/** /**
@@ -56,7 +57,7 @@ class AbstractHandlerTest extends TestCase
*/ */
public function testIsHandling() 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->assertTrue($handler->isHandling($this->getRecord()));
$this->assertFalse($handler->isHandling($this->getRecord(Logger::DEBUG))); $this->assertFalse($handler->isHandling($this->getRecord(Logger::DEBUG)));
} }
@@ -67,7 +68,7 @@ class AbstractHandlerTest extends TestCase
*/ */
public function testGetFormatterInitializesDefault() public function testGetFormatterInitializesDefault()
{ {
$handler = new TestHandler(); $handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler');
$this->assertInstanceOf('Monolog\Formatter\LineFormatter', $handler->getFormatter()); $this->assertInstanceOf('Monolog\Formatter\LineFormatter', $handler->getFormatter());
} }
@@ -78,7 +79,7 @@ class AbstractHandlerTest extends TestCase
*/ */
public function testPushPopProcessor() public function testPushPopProcessor()
{ {
$logger = new TestHandler(); $logger = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler');
$processor1 = new WebProcessor; $processor1 = new WebProcessor;
$processor2 = new WebProcessor; $processor2 = new WebProcessor;
@@ -90,4 +91,14 @@ class AbstractHandlerTest extends TestCase
$logger->popProcessor(); $logger->popProcessor();
} }
/**
* @covers Monolog\Handler\AbstractHandler::pushProcessor
* @expectedException InvalidArgumentException
*/
public function testPushProcessorWithNonCallable()
{
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler');
$handler->pushProcessor(new \stdClass());
}
} }

View File

@@ -22,7 +22,7 @@ class AbstractProcessingHandlerTest extends TestCase
*/ */
public function testHandleLowerLevelMessage() 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))); $this->assertFalse($handler->handle($this->getRecord(Logger::DEBUG)));
} }
@@ -31,7 +31,7 @@ class AbstractProcessingHandlerTest extends TestCase
*/ */
public function testHandleBubbling() 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())); $this->assertFalse($handler->handle($this->getRecord()));
} }
@@ -40,7 +40,7 @@ class AbstractProcessingHandlerTest extends TestCase
*/ */
public function testHandleNotBubbling() 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())); $this->assertTrue($handler->handle($this->getRecord()));
} }
@@ -49,7 +49,7 @@ class AbstractProcessingHandlerTest extends TestCase
*/ */
public function testHandleIsFalseWhenNotHandled() 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->assertTrue($handler->handle($this->getRecord()));
$this->assertFalse($handler->handle($this->getRecord(Logger::DEBUG))); $this->assertFalse($handler->handle($this->getRecord(Logger::DEBUG)));
} }
@@ -59,14 +59,20 @@ class AbstractProcessingHandlerTest extends TestCase
*/ */
public function testProcessRecord() public function testProcessRecord()
{ {
$handler = new TestHandler(); $handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler');
$handler->pushProcessor(new WebProcessor(array( $handler->pushProcessor(new WebProcessor(array(
'REQUEST_URI' => '', 'REQUEST_URI' => '',
'REQUEST_METHOD' => '', 'REQUEST_METHOD' => '',
'REMOTE_ADDR' => '', 'REMOTE_ADDR' => '',
))); )));
$handledRecord = null;
$handler->expects($this->once())
->method('write')
->will($this->returnCallback(function($record) use (&$handledRecord){
$handledRecord = $record;
}))
;
$handler->handle($this->getRecord()); $handler->handle($this->getRecord());
list($record) = $handler->getRecords(); $this->assertEquals(3, count($handledRecord['extra']));
$this->assertEquals(3, count($record['extra']));
} }
} }