MonologHandlerChromePHPHandlerTest

The Gravity PDF Monolog Handler ChromePHPHandlerTest class.

Defined (1)

The class is defined in the following location(s).

/vendor/monolog/monolog/tests/Monolog/Handler/ChromePHPHandlerTest.php  
  1. class ChromePHPHandlerTest extends TestCase 
  2. protected function setUp() 
  3. TestChromePHPHandler::reset(); 
  4. $_SERVER['HTTP_USER_AGENT'] = 'Monolog Test; Chrome/1.0'; 
  5.  
  6. public function testHeaders() 
  7. $handler = new TestChromePHPHandler(); 
  8. $handler->setFormatter($this->getIdentityFormatter()); 
  9. $handler->handle($this->getRecord(Logger::DEBUG)); 
  10. $handler->handle($this->getRecord(Logger::WARNING)); 
  11.  
  12. $expected = array( 
  13. 'X-ChromeLogger-Data' => base64_encode(utf8_encode(json_encode(array( 
  14. 'version' => ChromePHPHandler::VERSION,  
  15. 'columns' => array('label', 'log', 'backtrace', 'type'),  
  16. 'rows' => array( 
  17. 'test',  
  18. 'test',  
  19. ),  
  20. 'request_uri' => '',  
  21. )))) 
  22. ); 
  23.  
  24. $this->assertEquals($expected, $handler->getHeaders()); 
  25.  
  26. public function testHeadersOverflow() 
  27. $handler = new TestChromePHPHandler(); 
  28. $handler->handle($this->getRecord(Logger::DEBUG)); 
  29. $handler->handle($this->getRecord(Logger::WARNING, str_repeat('a', 150 * 1024))); 
  30.  
  31. // overflow chrome headers limit 
  32. $handler->handle($this->getRecord(Logger::WARNING, str_repeat('a', 100 * 1024))); 
  33.  
  34. $expected = array( 
  35. 'X-ChromeLogger-Data' => base64_encode(utf8_encode(json_encode(array( 
  36. 'version' => ChromePHPHandler::VERSION,  
  37. 'columns' => array('label', 'log', 'backtrace', 'type'),  
  38. 'rows' => array( 
  39. array( 
  40. 'test',  
  41. 'test',  
  42. 'unknown',  
  43. 'log',  
  44. ),  
  45. array( 
  46. 'test',  
  47. str_repeat('a', 150 * 1024),  
  48. 'unknown',  
  49. 'warn',  
  50. ),  
  51. array( 
  52. 'monolog',  
  53. 'Incomplete logs, chrome header size limit reached',  
  54. 'unknown',  
  55. 'warn',  
  56. ),  
  57. ),  
  58. 'request_uri' => '',  
  59. )))) 
  60. ); 
  61.  
  62. $this->assertEquals($expected, $handler->getHeaders()); 
  63.  
  64. public function testConcurrentHandlers() 
  65. $handler = new TestChromePHPHandler(); 
  66. $handler->setFormatter($this->getIdentityFormatter()); 
  67. $handler->handle($this->getRecord(Logger::DEBUG)); 
  68. $handler->handle($this->getRecord(Logger::WARNING)); 
  69.  
  70. $handler2 = new TestChromePHPHandler(); 
  71. $handler2->setFormatter($this->getIdentityFormatter()); 
  72. $handler2->handle($this->getRecord(Logger::DEBUG)); 
  73. $handler2->handle($this->getRecord(Logger::WARNING)); 
  74.  
  75. $expected = array( 
  76. 'X-ChromeLogger-Data' => base64_encode(utf8_encode(json_encode(array( 
  77. 'version' => ChromePHPHandler::VERSION,  
  78. 'columns' => array('label', 'log', 'backtrace', 'type'),  
  79. 'rows' => array( 
  80. 'test',  
  81. 'test',  
  82. 'test',  
  83. 'test',  
  84. ),  
  85. 'request_uri' => '',  
  86. )))) 
  87. ); 
  88.  
  89. $this->assertEquals($expected, $handler2->getHeaders());