ChromePHPHandlerTest.php 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. /**
  14. * @covers Monolog\Handler\ChromePHPHandler
  15. */
  16. class ChromePHPHandlerTest extends TestCase
  17. {
  18. protected function setUp()
  19. {
  20. TestChromePHPHandler::reset();
  21. }
  22. public function testHeaders()
  23. {
  24. $handler = new TestChromePHPHandler();
  25. $handler->setFormatter($this->getIdentityFormatter());
  26. $handler->handle($this->getRecord(Logger::DEBUG));
  27. $handler->handle($this->getRecord(Logger::WARNING));
  28. $expected = array(
  29. 'X-ChromePhp-Data' => base64_encode(utf8_encode(json_encode(array(
  30. 'version' => ChromePHPHandler::VERSION,
  31. 'columns' => array('label', 'log', 'backtrace', 'type'),
  32. 'rows' => array(
  33. 'test',
  34. 'test',
  35. ),
  36. 'request_uri' => '',
  37. ))))
  38. );
  39. $this->assertEquals($expected, $handler->getHeaders());
  40. }
  41. public function testConcurrentHandlers()
  42. {
  43. $handler = new TestChromePHPHandler();
  44. $handler->setFormatter($this->getIdentityFormatter());
  45. $handler->handle($this->getRecord(Logger::DEBUG));
  46. $handler->handle($this->getRecord(Logger::WARNING));
  47. $handler2 = new TestChromePHPHandler();
  48. $handler2->setFormatter($this->getIdentityFormatter());
  49. $handler2->handle($this->getRecord(Logger::DEBUG));
  50. $handler2->handle($this->getRecord(Logger::WARNING));
  51. $expected = array(
  52. 'X-ChromePhp-Data' => base64_encode(utf8_encode(json_encode(array(
  53. 'version' => ChromePHPHandler::VERSION,
  54. 'columns' => array('label', 'log', 'backtrace', 'type'),
  55. 'rows' => array(
  56. 'test',
  57. 'test',
  58. 'test',
  59. 'test',
  60. ),
  61. 'request_uri' => '',
  62. ))))
  63. );
  64. $this->assertEquals($expected, $handler2->getHeaders());
  65. }
  66. }
  67. class TestChromePHPHandler extends ChromePHPHandler
  68. {
  69. protected $headers = array();
  70. public static function reset()
  71. {
  72. self::$initialized = false;
  73. self::$json['rows'] = array();
  74. }
  75. protected function sendHeader($header, $content)
  76. {
  77. $this->headers[$header] = $content;
  78. }
  79. public function getHeaders()
  80. {
  81. return $this->headers;
  82. }
  83. }