NewRelicHandlerTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. class NewRelicHandlerTest extends TestCase
  14. {
  15. /**
  16. * @expectedException Monolog\Handler\MissingExtensionException
  17. */
  18. public function testThehandlerThrowsAnExceptionIfTheNRExtensionIsNotLoaded()
  19. {
  20. $handler = new StubNewRelicHandlerWithoutExtension();
  21. $handler->handle($this->getRecord(Logger::ERROR));
  22. }
  23. public function testThehandlerCanHandleTheRecord()
  24. {
  25. $handler = new StubNewRelicHandler();
  26. $handler->handle($this->getRecord(Logger::ERROR));
  27. }
  28. public function testThehandlerCanAddParamsToTheNewRelicTrace()
  29. {
  30. $handler = new StubNewRelicHandler();
  31. $handler->handle($this->getRecord(Logger::ERROR, 'log message', array('a' => 'b')));
  32. }
  33. public function testThehandlerCanAddTheAppName()
  34. {
  35. $handler = new StubNewRelicHandler();
  36. $handler->handle($this->getRecord(Logger::ERROR, 'log message', array('appname' => 'myApp')));
  37. }
  38. }
  39. class StubNewRelicHandlerWithoutExtension extends NewRelicHandler
  40. {
  41. protected function isNewRelicEnabled()
  42. {
  43. return false;
  44. }
  45. }
  46. class StubNewRelicHandler extends NewRelicHandler
  47. {
  48. protected function isNewRelicEnabled()
  49. {
  50. return true;
  51. }
  52. }
  53. function newrelic_notice_error()
  54. {
  55. return true;
  56. }
  57. function newrelic_set_appname()
  58. {
  59. return true;
  60. }
  61. function newrelic_add_custom_parameter()
  62. {
  63. return true;
  64. }