LoggerTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /*
  3. * This file is part of the Monolog package.
  4. *
  5. * (c) Jordi Boggiano <j.boggiano@seld.be>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Monolog;
  11. class LoggerTest extends \PHPUnit_Framework_TestCase
  12. {
  13. public function testLog()
  14. {
  15. $logger = new Logger(__METHOD__);
  16. $handler = $this->getMock('Monolog\Handler\NullHandler', array('handle'));
  17. $handler->expects($this->once())
  18. ->method('handle');
  19. $logger->pushHandler($handler);
  20. $this->assertTrue($logger->addWarning('test'));
  21. }
  22. public function testLogNoHandler()
  23. {
  24. $logger = new Logger(__METHOD__);
  25. $handler = $this->getMock('Monolog\Handler\NullHandler', array('handle'), array(Logger::ERROR));
  26. $handler->expects($this->never())
  27. ->method('handle');
  28. $logger->pushHandler($handler);
  29. $this->assertFalse($logger->addWarning('test'));
  30. }
  31. public function logValues()
  32. {
  33. return array(array(true), array(false));
  34. }
  35. public function testPushPopHandler()
  36. {
  37. $logger = new Logger(__METHOD__);
  38. $handler1 = $this->getMock('Monolog\Handler\NullHandler', array('handle'));
  39. $handler2 = $this->getMock('Monolog\Handler\NullHandler', array('handle'));
  40. $handler3 = $this->getMock('Monolog\Handler\NullHandler', array('handle'));
  41. $logger->pushHandler($handler1);
  42. $logger->pushHandler($handler2);
  43. $logger->pushHandler($handler3);
  44. $this->assertEquals($handler3, $logger->popHandler());
  45. $this->assertEquals($handler2, $logger->popHandler());
  46. $this->assertEquals($handler1, $logger->popHandler());
  47. }
  48. }