AbstractProcessingHandlerTest.php 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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\Processor\WebProcessor;
  14. class AbstractProcessingHandlerTest extends TestCase
  15. {
  16. /**
  17. * @covers Monolog\Handler\AbstractProcessingHandler::handle
  18. */
  19. public function testHandleLowerLevelMessage()
  20. {
  21. $handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler', array(Logger::WARNING, true));
  22. $this->assertFalse($handler->handle($this->getRecord(Logger::DEBUG)));
  23. }
  24. /**
  25. * @covers Monolog\Handler\AbstractProcessingHandler::handle
  26. */
  27. public function testHandleBubbling()
  28. {
  29. $handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler', array(Logger::DEBUG, true));
  30. $this->assertFalse($handler->handle($this->getRecord()));
  31. }
  32. /**
  33. * @covers Monolog\Handler\AbstractProcessingHandler::handle
  34. */
  35. public function testHandleNotBubbling()
  36. {
  37. $handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler', array(Logger::DEBUG, false));
  38. $this->assertTrue($handler->handle($this->getRecord()));
  39. }
  40. /**
  41. * @covers Monolog\Handler\AbstractProcessingHandler::handle
  42. */
  43. public function testHandleIsFalseWhenNotHandled()
  44. {
  45. $handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler', array(Logger::WARNING, false));
  46. $this->assertTrue($handler->handle($this->getRecord()));
  47. $this->assertFalse($handler->handle($this->getRecord(Logger::DEBUG)));
  48. }
  49. /**
  50. * @covers Monolog\Handler\AbstractProcessingHandler::processRecord
  51. */
  52. public function testProcessRecord()
  53. {
  54. $handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler');
  55. $handler->pushProcessor(new WebProcessor(array(
  56. 'REQUEST_URI' => '',
  57. 'REQUEST_METHOD' => '',
  58. 'REMOTE_ADDR' => '',
  59. )));
  60. $handledRecord = null;
  61. $handler->expects($this->once())
  62. ->method('write')
  63. ->will($this->returnCallback(function($record) use (&$handledRecord){
  64. $handledRecord = $record;
  65. }))
  66. ;
  67. $handler->handle($this->getRecord());
  68. $this->assertEquals(3, count($handledRecord['extra']));
  69. }
  70. }