ZendMonitorHandlerTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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\Test\TestCase;
  12. class ZendMonitorHandlerTest extends TestCase
  13. {
  14. protected $zendMonitorHandler;
  15. public function setUp()
  16. {
  17. if (!function_exists('zend_monitor_custom_event')) {
  18. $this->markTestSkipped('ZendServer is not installed');
  19. }
  20. }
  21. /**
  22. * @covers Monolog\Handler\ZendMonitorHandler::write
  23. */
  24. public function testWrite()
  25. {
  26. $record = $this->getRecord();
  27. $formatterResult = [
  28. 'message' => $record['message'],
  29. ];
  30. $zendMonitor = $this->getMockBuilder('Monolog\Handler\ZendMonitorHandler')
  31. ->setMethods(['writeZendMonitorCustomEvent', 'getDefaultFormatter'])
  32. ->getMock();
  33. $formatterMock = $this->getMockBuilder('Monolog\Formatter\NormalizerFormatter')
  34. ->disableOriginalConstructor()
  35. ->getMock();
  36. $formatterMock->expects($this->once())
  37. ->method('format')
  38. ->will($this->returnValue($formatterResult));
  39. $zendMonitor->expects($this->once())
  40. ->method('getDefaultFormatter')
  41. ->will($this->returnValue($formatterMock));
  42. $levelMap = $zendMonitor->getLevelMap();
  43. $zendMonitor->expects($this->once())
  44. ->method('writeZendMonitorCustomEvent')
  45. ->with($levelMap[$record['level']], $record['message'], $formatterResult);
  46. $zendMonitor->handle($record);
  47. }
  48. /**
  49. * @covers Monolog\Handler\ZendMonitorHandler::getDefaultFormatter
  50. */
  51. public function testGetDefaultFormatterReturnsNormalizerFormatter()
  52. {
  53. $zendMonitor = new ZendMonitorHandler();
  54. $this->assertInstanceOf('Monolog\Formatter\NormalizerFormatter', $zendMonitor->getDefaultFormatter());
  55. }
  56. }