123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- <?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.
- */
-
- namespace Monolog;
-
- use Monolog\Processor\WebProcessor;
- use Monolog\Handler\TestHandler;
-
- class LoggerTest extends \PHPUnit_Framework_TestCase
- {
-
- /**
- * @covers Monolog\Logger::getName()
- */
- public function testGetName()
- {
- $logger = new Logger('foo');
- $this->assertEquals('foo', $logger->getName());
- }
-
- /**
- * @covers Monolog\Logger::__construct
- */
- public function testChannel()
- {
- $logger = new Logger('foo');
- $handler = new TestHandler;
- $logger->pushHandler($handler);
- $logger->addWarning('test');
- list($record) = $handler->getRecords();
- $this->assertEquals('foo', $record['channel']);
- }
-
- /**
- * @covers Monolog\Logger::addRecord
- */
- public function testLog()
- {
- $logger = new Logger(__METHOD__);
-
- $handler = $this->getMock('Monolog\Handler\NullHandler', array('handle'));
- $handler->expects($this->once())
- ->method('handle');
- $logger->pushHandler($handler);
-
- $this->assertTrue($logger->addWarning('test'));
- }
-
- /**
- * @covers Monolog\Logger::addRecord
- */
- public function testLogNotHandled()
- {
- $logger = new Logger(__METHOD__);
-
- $handler = $this->getMock('Monolog\Handler\NullHandler', array('handle'), array(Logger::ERROR));
- $handler->expects($this->never())
- ->method('handle');
- $logger->pushHandler($handler);
-
- $this->assertFalse($logger->addWarning('test'));
- }
-
- /**
- * @covers Monolog\Logger::pushHandler
- * @covers Monolog\Logger::popHandler
- * @expectedException LogicException
- */
- public function testPushPopHandler()
- {
- $logger = new Logger(__METHOD__);
- $handler1 = new TestHandler;
- $handler2 = new TestHandler;
-
- $logger->pushHandler($handler1);
- $logger->pushHandler($handler2);
-
- $this->assertEquals($handler2, $logger->popHandler());
- $this->assertEquals($handler1, $logger->popHandler());
- $logger->popHandler();
- }
-
- /**
- * @covers Monolog\Logger::pushProcessor
- * @covers Monolog\Logger::popProcessor
- * @expectedException LogicException
- */
- public function testPushPopProcessor()
- {
- $logger = new Logger(__METHOD__);
- $processor1 = new WebProcessor;
- $processor2 = new WebProcessor;
-
- $logger->pushProcessor($processor1);
- $logger->pushProcessor($processor2);
-
- $this->assertEquals($processor2, $logger->popProcessor());
- $this->assertEquals($processor1, $logger->popProcessor());
- $logger->popProcessor();
- }
-
- /**
- * @covers Monolog\Logger::addRecord
- */
- public function testProcessorsAreExecuted()
- {
- $logger = new Logger(__METHOD__);
- $handler = new TestHandler;
- $logger->pushHandler($handler);
- $logger->pushProcessor(function($record) {
- $record['extra']['win'] = true;
- return $record;
- });
- $logger->addError('test');
- list($record) = $handler->getRecords();
- $this->assertTrue($record['extra']['win']);
- }
-
- /**
- * @dataProvider logMethodProvider
- * @covers Monolog\Logger::addDebug
- * @covers Monolog\Logger::addInfo
- * @covers Monolog\Logger::addWarning
- * @covers Monolog\Logger::addError
- * @covers Monolog\Logger::addCritical
- * @covers Monolog\Logger::addAlert
- * @covers Monolog\Logger::debug
- * @covers Monolog\Logger::info
- * @covers Monolog\Logger::notice
- * @covers Monolog\Logger::warn
- * @covers Monolog\Logger::err
- * @covers Monolog\Logger::crit
- * @covers Monolog\Logger::alert
- * @covers Monolog\Logger::emerg
- */
- public function testLogMethods($method, $expectedLevel)
- {
- $logger = new Logger('foo');
- $handler = new TestHandler;
- $logger->pushHandler($handler);
- $logger->{$method}('test');
- list($record) = $handler->getRecords();
- $this->assertEquals($expectedLevel, $record['level']);
- }
-
- public function logMethodProvider()
- {
- return array(
- // monolog methods
- array('addDebug', Logger::DEBUG),
- array('addInfo', Logger::INFO),
- array('addWarning', Logger::WARNING),
- array('addError', Logger::ERROR),
- array('addCritical', Logger::CRITICAL),
- array('addAlert', Logger::ALERT),
-
- // ZF/Sf2 compat methods
- array('debug', Logger::DEBUG),
- array('info', Logger::INFO),
- array('notice', Logger::INFO),
- array('warn', Logger::WARNING),
- array('err', Logger::ERROR),
- array('crit', Logger::CRITICAL),
- array('alert', Logger::ALERT),
- array('emerg', Logger::ALERT),
- );
- }
- }
|