AbstractHandlerTest.php 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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\Handler;
  11. use Monolog\TestCase;
  12. use Monolog\Logger;
  13. use Monolog\Formatter\LineFormatter;
  14. use Monolog\Processor\WebProcessor;
  15. class AbstractHandlerTest extends TestCase
  16. {
  17. /**
  18. * @covers Monolog\Handler\AbstractHandler::__construct
  19. * @covers Monolog\Handler\AbstractHandler::getLevel
  20. * @covers Monolog\Handler\AbstractHandler::setLevel
  21. * @covers Monolog\Handler\AbstractHandler::getBubble
  22. * @covers Monolog\Handler\AbstractHandler::setBubble
  23. * @covers Monolog\Handler\AbstractHandler::getFormatter
  24. * @covers Monolog\Handler\AbstractHandler::setFormatter
  25. */
  26. public function testConstructAndGetSet()
  27. {
  28. $handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler', array(Logger::WARNING, false));
  29. $this->assertEquals(Logger::WARNING, $handler->getLevel());
  30. $this->assertEquals(false, $handler->getBubble());
  31. $handler->setLevel(Logger::ERROR);
  32. $handler->setBubble(true);
  33. $handler->setFormatter($formatter = new LineFormatter);
  34. $this->assertEquals(Logger::ERROR, $handler->getLevel());
  35. $this->assertEquals(true, $handler->getBubble());
  36. $this->assertSame($formatter, $handler->getFormatter());
  37. }
  38. /**
  39. * @covers Monolog\Handler\AbstractHandler::handleBatch
  40. */
  41. public function testHandleBatch()
  42. {
  43. $handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler');
  44. $handler->expects($this->exactly(2))
  45. ->method('handle');
  46. $handler->handleBatch(array($this->getRecord(), $this->getRecord()));
  47. }
  48. /**
  49. * @covers Monolog\Handler\AbstractHandler::isHandling
  50. */
  51. public function testIsHandling()
  52. {
  53. $handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler', array(Logger::WARNING, false));
  54. $this->assertTrue($handler->isHandling($this->getRecord()));
  55. $this->assertFalse($handler->isHandling($this->getRecord(Logger::DEBUG)));
  56. }
  57. /**
  58. * @covers Monolog\Handler\AbstractHandler::getFormatter
  59. * @covers Monolog\Handler\AbstractHandler::getDefaultFormatter
  60. */
  61. public function testGetFormatterInitializesDefault()
  62. {
  63. $handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler');
  64. $this->assertInstanceOf('Monolog\Formatter\LineFormatter', $handler->getFormatter());
  65. }
  66. /**
  67. * @covers Monolog\Handler\AbstractHandler::pushProcessor
  68. * @covers Monolog\Handler\AbstractHandler::popProcessor
  69. * @expectedException LogicException
  70. */
  71. public function testPushPopProcessor()
  72. {
  73. $logger = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler');
  74. $processor1 = new WebProcessor;
  75. $processor2 = new WebProcessor;
  76. $logger->pushProcessor($processor1);
  77. $logger->pushProcessor($processor2);
  78. $this->assertEquals($processor2, $logger->popProcessor());
  79. $this->assertEquals($processor1, $logger->popProcessor());
  80. $logger->popProcessor();
  81. }
  82. /**
  83. * @covers Monolog\Handler\AbstractHandler::pushProcessor
  84. * @expectedException InvalidArgumentException
  85. */
  86. public function testPushProcessorWithNonCallable()
  87. {
  88. $handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler');
  89. $handler->pushProcessor(new \stdClass());
  90. }
  91. }