2
0

ZendMonitorHandlerTest.php 2.1 KB

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