ZendMonitorHandlerTest.php 2.1 KB

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