MonologHandlerFingersCrossedHandlerTest

The Gravity PDF Monolog Handler FingersCrossedHandlerTest class.

Defined (1)

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

/vendor/monolog/monolog/tests/Monolog/Handler/FingersCrossedHandlerTest.php  
  1. class FingersCrossedHandlerTest extends TestCase 
  2. /** 
  3. * @covers Monolog\Handler\FingersCrossedHandler::__construct 
  4. * @covers Monolog\Handler\FingersCrossedHandler::handle 
  5. */ 
  6. public function testHandleBuffers() 
  7. $test = new TestHandler(); 
  8. $handler = new FingersCrossedHandler($test); 
  9. $handler->handle($this->getRecord(Logger::DEBUG)); 
  10. $handler->handle($this->getRecord(Logger::INFO)); 
  11. $this->assertFalse($test->hasDebugRecords()); 
  12. $this->assertFalse($test->hasInfoRecords()); 
  13. $handler->handle($this->getRecord(Logger::WARNING)); 
  14. $handler->close(); 
  15. $this->assertTrue($test->hasInfoRecords()); 
  16. $this->assertTrue(count($test->getRecords()) === 3); 
  17.  
  18. /** 
  19. * @covers Monolog\Handler\FingersCrossedHandler::handle 
  20. */ 
  21. public function testHandleStopsBufferingAfterTrigger() 
  22. $test = new TestHandler(); 
  23. $handler = new FingersCrossedHandler($test); 
  24. $handler->handle($this->getRecord(Logger::WARNING)); 
  25. $handler->handle($this->getRecord(Logger::DEBUG)); 
  26. $handler->close(); 
  27. $this->assertTrue($test->hasWarningRecords()); 
  28. $this->assertTrue($test->hasDebugRecords()); 
  29.  
  30. /** 
  31. * @covers Monolog\Handler\FingersCrossedHandler::handle 
  32. * @covers Monolog\Handler\FingersCrossedHandler::reset 
  33. */ 
  34. public function testHandleRestartBufferingAfterReset() 
  35. $test = new TestHandler(); 
  36. $handler = new FingersCrossedHandler($test); 
  37. $handler->handle($this->getRecord(Logger::WARNING)); 
  38. $handler->handle($this->getRecord(Logger::DEBUG)); 
  39. $handler->reset(); 
  40. $handler->handle($this->getRecord(Logger::INFO)); 
  41. $handler->close(); 
  42. $this->assertTrue($test->hasWarningRecords()); 
  43. $this->assertTrue($test->hasDebugRecords()); 
  44. $this->assertFalse($test->hasInfoRecords()); 
  45.  
  46. /** 
  47. * @covers Monolog\Handler\FingersCrossedHandler::handle 
  48. */ 
  49. public function testHandleRestartBufferingAfterBeingTriggeredWhenStopBufferingIsDisabled() 
  50. $test = new TestHandler(); 
  51. $handler = new FingersCrossedHandler($test, Logger::WARNING, 0, false, false); 
  52. $handler->handle($this->getRecord(Logger::DEBUG)); 
  53. $handler->handle($this->getRecord(Logger::WARNING)); 
  54. $handler->handle($this->getRecord(Logger::INFO)); 
  55. $handler->close(); 
  56. $this->assertTrue($test->hasWarningRecords()); 
  57. $this->assertTrue($test->hasDebugRecords()); 
  58. $this->assertFalse($test->hasInfoRecords()); 
  59.  
  60. /** 
  61. * @covers Monolog\Handler\FingersCrossedHandler::handle 
  62. */ 
  63. public function testHandleBufferLimit() 
  64. $test = new TestHandler(); 
  65. $handler = new FingersCrossedHandler($test, Logger::WARNING, 2); 
  66. $handler->handle($this->getRecord(Logger::DEBUG)); 
  67. $handler->handle($this->getRecord(Logger::DEBUG)); 
  68. $handler->handle($this->getRecord(Logger::INFO)); 
  69. $handler->handle($this->getRecord(Logger::WARNING)); 
  70. $this->assertTrue($test->hasWarningRecords()); 
  71. $this->assertTrue($test->hasInfoRecords()); 
  72. $this->assertFalse($test->hasDebugRecords()); 
  73.  
  74. /** 
  75. * @covers Monolog\Handler\FingersCrossedHandler::handle 
  76. */ 
  77. public function testHandleWithCallback() 
  78. $test = new TestHandler(); 
  79. $handler = new FingersCrossedHandler(function ($record, $handler) use ($test) { 
  80. return $test; 
  81. }); 
  82. $handler->handle($this->getRecord(Logger::DEBUG)); 
  83. $handler->handle($this->getRecord(Logger::INFO)); 
  84. $this->assertFalse($test->hasDebugRecords()); 
  85. $this->assertFalse($test->hasInfoRecords()); 
  86. $handler->handle($this->getRecord(Logger::WARNING)); 
  87. $this->assertTrue($test->hasInfoRecords()); 
  88. $this->assertTrue(count($test->getRecords()) === 3); 
  89.  
  90. /** 
  91. * @covers Monolog\Handler\FingersCrossedHandler::handle 
  92. * @expectedException RuntimeException 
  93. */ 
  94. public function testHandleWithBadCallbackThrowsException() 
  95. $handler = new FingersCrossedHandler(function ($record, $handler) { 
  96. return 'foo'; 
  97. }); 
  98. $handler->handle($this->getRecord(Logger::WARNING)); 
  99.  
  100. /** 
  101. * @covers Monolog\Handler\FingersCrossedHandler::isHandling 
  102. */ 
  103. public function testIsHandlingAlways() 
  104. $test = new TestHandler(); 
  105. $handler = new FingersCrossedHandler($test, Logger::ERROR); 
  106. $this->assertTrue($handler->isHandling($this->getRecord(Logger::DEBUG))); 
  107.  
  108. /** 
  109. * @covers Monolog\Handler\FingersCrossedHandler::__construct 
  110. * @covers Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy::__construct 
  111. * @covers Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy::isHandlerActivated 
  112. */ 
  113. public function testErrorLevelActivationStrategy() 
  114. $test = new TestHandler(); 
  115. $handler = new FingersCrossedHandler($test, new ErrorLevelActivationStrategy(Logger::WARNING)); 
  116. $handler->handle($this->getRecord(Logger::DEBUG)); 
  117. $this->assertFalse($test->hasDebugRecords()); 
  118. $handler->handle($this->getRecord(Logger::WARNING)); 
  119. $this->assertTrue($test->hasDebugRecords()); 
  120. $this->assertTrue($test->hasWarningRecords()); 
  121.  
  122. /** 
  123. * @covers Monolog\Handler\FingersCrossedHandler::__construct 
  124. * @covers Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy::__construct 
  125. * @covers Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy::isHandlerActivated 
  126. */ 
  127. public function testErrorLevelActivationStrategyWithPsrLevel() 
  128. $test = new TestHandler(); 
  129. $handler = new FingersCrossedHandler($test, new ErrorLevelActivationStrategy('warning')); 
  130. $handler->handle($this->getRecord(Logger::DEBUG)); 
  131. $this->assertFalse($test->hasDebugRecords()); 
  132. $handler->handle($this->getRecord(Logger::WARNING)); 
  133. $this->assertTrue($test->hasDebugRecords()); 
  134. $this->assertTrue($test->hasWarningRecords()); 
  135.  
  136. /** 
  137. * @covers Monolog\Handler\FingersCrossed\ChannelLevelActivationStrategy::__construct 
  138. * @covers Monolog\Handler\FingersCrossed\ChannelLevelActivationStrategy::isHandlerActivated 
  139. */ 
  140. public function testChannelLevelActivationStrategy() 
  141. $test = new TestHandler(); 
  142. $handler = new FingersCrossedHandler($test, new ChannelLevelActivationStrategy(Logger::ERROR, array('othertest' => Logger::DEBUG))); 
  143. $handler->handle($this->getRecord(Logger::WARNING)); 
  144. $this->assertFalse($test->hasWarningRecords()); 
  145. $record = $this->getRecord(Logger::DEBUG); 
  146. $record['channel'] = 'othertest'; 
  147. $handler->handle($record); 
  148. $this->assertTrue($test->hasDebugRecords()); 
  149. $this->assertTrue($test->hasWarningRecords()); 
  150.  
  151. /** 
  152. * @covers Monolog\Handler\FingersCrossed\ChannelLevelActivationStrategy::__construct 
  153. * @covers Monolog\Handler\FingersCrossed\ChannelLevelActivationStrategy::isHandlerActivated 
  154. */ 
  155. public function testChannelLevelActivationStrategyWithPsrLevels() 
  156. $test = new TestHandler(); 
  157. $handler = new FingersCrossedHandler($test, new ChannelLevelActivationStrategy('error', array('othertest' => 'debug'))); 
  158. $handler->handle($this->getRecord(Logger::WARNING)); 
  159. $this->assertFalse($test->hasWarningRecords()); 
  160. $record = $this->getRecord(Logger::DEBUG); 
  161. $record['channel'] = 'othertest'; 
  162. $handler->handle($record); 
  163. $this->assertTrue($test->hasDebugRecords()); 
  164. $this->assertTrue($test->hasWarningRecords()); 
  165.  
  166. /** 
  167. * @covers Monolog\Handler\FingersCrossedHandler::handle 
  168. */ 
  169. public function testHandleUsesProcessors() 
  170. $test = new TestHandler(); 
  171. $handler = new FingersCrossedHandler($test, Logger::INFO); 
  172. $handler->pushProcessor(function ($record) { 
  173. $record['extra']['foo'] = true; 
  174.  
  175. return $record; 
  176. }); 
  177. $handler->handle($this->getRecord(Logger::WARNING)); 
  178. $this->assertTrue($test->hasWarningRecords()); 
  179. $records = $test->getRecords(); 
  180. $this->assertTrue($records[0]['extra']['foo']); 
  181.  
  182. /** 
  183. * @covers Monolog\Handler\FingersCrossedHandler::close 
  184. */ 
  185. public function testPassthruOnClose() 
  186. $test = new TestHandler(); 
  187. $handler = new FingersCrossedHandler($test, new ErrorLevelActivationStrategy(Logger::WARNING), 0, true, true, Logger::INFO); 
  188. $handler->handle($this->getRecord(Logger::DEBUG)); 
  189. $handler->handle($this->getRecord(Logger::INFO)); 
  190. $handler->close(); 
  191. $this->assertFalse($test->hasDebugRecords()); 
  192. $this->assertTrue($test->hasInfoRecords()); 
  193.  
  194. /** 
  195. * @covers Monolog\Handler\FingersCrossedHandler::close 
  196. */ 
  197. public function testPsrLevelPassthruOnClose() 
  198. $test = new TestHandler(); 
  199. $handler = new FingersCrossedHandler($test, new ErrorLevelActivationStrategy(Logger::WARNING), 0, true, true, LogLevel::INFO); 
  200. $handler->handle($this->getRecord(Logger::DEBUG)); 
  201. $handler->handle($this->getRecord(Logger::INFO)); 
  202. $handler->close(); 
  203. $this->assertFalse($test->hasDebugRecords()); 
  204. $this->assertTrue($test->hasInfoRecords());