2
0

AbstractHandlerTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php declare(strict_types=1);
  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\Level;
  12. class AbstractHandlerTest extends \Monolog\Test\MonologTestCase
  13. {
  14. /**
  15. * @covers Monolog\Handler\AbstractHandler::__construct
  16. * @covers Monolog\Handler\AbstractHandler::getLevel
  17. * @covers Monolog\Handler\AbstractHandler::setLevel
  18. * @covers Monolog\Handler\AbstractHandler::getBubble
  19. * @covers Monolog\Handler\AbstractHandler::setBubble
  20. */
  21. public function testConstructAndGetSet()
  22. {
  23. $handler = $this->getMockBuilder('Monolog\Handler\AbstractHandler')->setConstructorArgs([Level::Warning, false])->onlyMethods(['handle'])->getMock();
  24. $this->assertEquals(Level::Warning, $handler->getLevel());
  25. $this->assertEquals(false, $handler->getBubble());
  26. $handler->setLevel(Level::Error);
  27. $handler->setBubble(true);
  28. $this->assertEquals(Level::Error, $handler->getLevel());
  29. $this->assertEquals(true, $handler->getBubble());
  30. }
  31. /**
  32. * @covers Monolog\Handler\AbstractHandler::handleBatch
  33. */
  34. public function testHandleBatch()
  35. {
  36. $handler = $this->createPartialMock('Monolog\Handler\AbstractHandler', ['handle']);
  37. $handler->expects($this->exactly(2))
  38. ->method('handle');
  39. $handler->handleBatch([$this->getRecord(), $this->getRecord()]);
  40. }
  41. /**
  42. * @covers Monolog\Handler\AbstractHandler::isHandling
  43. */
  44. public function testIsHandling()
  45. {
  46. $handler = $this->getMockBuilder('Monolog\Handler\AbstractHandler')->setConstructorArgs([Level::Warning, false])->onlyMethods(['handle'])->getMock();
  47. $this->assertTrue($handler->isHandling($this->getRecord()));
  48. $this->assertFalse($handler->isHandling($this->getRecord(Level::Debug)));
  49. }
  50. /**
  51. * @covers Monolog\Handler\AbstractHandler::__construct
  52. */
  53. public function testHandlesPsrStyleLevels()
  54. {
  55. $handler = $this->getMockBuilder('Monolog\Handler\AbstractHandler')->setConstructorArgs(['warning', false])->onlyMethods(['handle'])->getMock();
  56. $this->assertFalse($handler->isHandling($this->getRecord(Level::Debug)));
  57. $handler->setLevel('debug');
  58. $this->assertTrue($handler->isHandling($this->getRecord(Level::Debug)));
  59. }
  60. }