ZendMonitorHandlerTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. /**
  21. * @covers Monolog\Handler\ZendMonitorHandler::write
  22. */
  23. public function testWrite()
  24. {
  25. $record = $this->getRecord();
  26. $formatterResult = [
  27. 'message' => $record->message,
  28. ];
  29. $zendMonitor = $this->getMockBuilder('Monolog\Handler\ZendMonitorHandler')
  30. ->onlyMethods(['writeZendMonitorCustomEvent', 'getDefaultFormatter'])
  31. ->getMock();
  32. $formatterMock = $this->getMockBuilder('Monolog\Formatter\NormalizerFormatter')
  33. ->disableOriginalConstructor()
  34. ->getMock();
  35. $formatterMock->expects($this->once())
  36. ->method('format')
  37. ->will($this->returnValue($formatterResult));
  38. $zendMonitor->expects($this->once())
  39. ->method('getDefaultFormatter')
  40. ->will($this->returnValue($formatterMock));
  41. $zendMonitor->expects($this->once())
  42. ->method('writeZendMonitorCustomEvent')
  43. ->with(
  44. $record->levelName->value,
  45. $record->message,
  46. $formatterResult,
  47. \ZEND_MONITOR_EVENT_SEVERITY_WARNING
  48. );
  49. $zendMonitor->handle($record);
  50. }
  51. /**
  52. * @covers Monolog\Handler\ZendMonitorHandler::getDefaultFormatter
  53. */
  54. public function testGetDefaultFormatterReturnsNormalizerFormatter()
  55. {
  56. $zendMonitor = new ZendMonitorHandler();
  57. $this->assertInstanceOf('Monolog\Formatter\NormalizerFormatter', $zendMonitor->getDefaultFormatter());
  58. }
  59. }