FirePHPHandlerTest.php 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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\FirePHPHandler
  15. */
  16. class FirePHPHandlerTest extends TestCase
  17. {
  18. public function setUp()
  19. {
  20. TestFirePHPHandler::reset();
  21. }
  22. public function testHeaders()
  23. {
  24. $handler = new TestFirePHPHandler;
  25. $handler->setFormatter($this->getIdentityFormatter());
  26. $handler->handle($this->getRecord(Logger::DEBUG));
  27. $handler->handle($this->getRecord(Logger::WARNING));
  28. $expected = array(
  29. 'X-Wf-Protocol-1' => 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2',
  30. 'X-Wf-1-Structure-1' => 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1',
  31. 'X-Wf-1-Plugin-1' => 'http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3',
  32. 'X-Wf-1-1-1-1' => 'test',
  33. 'X-Wf-1-1-1-2' => 'test',
  34. );
  35. $this->assertEquals($expected, $handler->getHeaders());
  36. }
  37. public function testConcurrentHandlers()
  38. {
  39. $handler = new TestFirePHPHandler;
  40. $handler->setFormatter($this->getIdentityFormatter());
  41. $handler->handle($this->getRecord(Logger::DEBUG));
  42. $handler->handle($this->getRecord(Logger::WARNING));
  43. $handler2 = new TestFirePHPHandler;
  44. $handler2->setFormatter($this->getIdentityFormatter());
  45. $handler2->handle($this->getRecord(Logger::DEBUG));
  46. $handler2->handle($this->getRecord(Logger::WARNING));
  47. $expected = array(
  48. 'X-Wf-Protocol-1' => 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2',
  49. 'X-Wf-1-Structure-1' => 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1',
  50. 'X-Wf-1-Plugin-1' => 'http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3',
  51. 'X-Wf-1-1-1-1' => 'test',
  52. 'X-Wf-1-1-1-2' => 'test',
  53. );
  54. $expected2 = array(
  55. 'X-Wf-1-1-1-3' => 'test',
  56. 'X-Wf-1-1-1-4' => 'test',
  57. );
  58. $this->assertEquals($expected, $handler->getHeaders());
  59. $this->assertEquals($expected2, $handler2->getHeaders());
  60. }
  61. }
  62. class TestFirePHPHandler extends FirePHPHandler
  63. {
  64. protected $headers = array();
  65. public static function reset()
  66. {
  67. self::$initialized = false;
  68. self::$messageIndex = 1;
  69. }
  70. protected function sendHeader($header, $content)
  71. {
  72. $this->headers[$header] = $content;
  73. }
  74. public function getHeaders()
  75. {
  76. return $this->headers;
  77. }
  78. }