Explorar el Código

Add TestHandler::hasRecordThatMatches($regex, $level)

Austin Hyde hace 10 años
padre
commit
f2fea2c3f5
Se han modificado 2 ficheros con 18 adiciones y 0 borrados
  1. 16 0
      src/Monolog/Handler/TestHandler.php
  2. 2 0
      tests/Monolog/Handler/TestHandlerTest.php

+ 16 - 0
src/Monolog/Handler/TestHandler.php

@@ -47,6 +47,15 @@ use Monolog\Logger;
  * @method boolean hasInfoThatContains($message)
  * @method boolean hasDebugThatContains($message)
  * 
+ * @method boolean hasEmergencyThatMatches($message)
+ * @method boolean hasAlertThatMatches($message)
+ * @method boolean hasCriticalThatMatches($message)
+ * @method boolean hasErrorThatMatches($message)
+ * @method boolean hasWarningThatMatches($message)
+ * @method boolean hasNoticeThatMatches($message)
+ * @method boolean hasInfoThatMatches($message)
+ * @method boolean hasDebugThatMatches($message)
+ * 
  * @method boolean hasEmergencyThatPasses($message)
  * @method boolean hasAlertThatPasses($message)
  * @method boolean hasCriticalThatPasses($message)
@@ -89,6 +98,13 @@ class TestHandler extends AbstractProcessingHandler
         }, $level);
     }
 
+    public function hasRecordThatMatches($regex, $level)
+    {
+        return $this->hasRecordThatPasses(function($rec) use ($regex) {
+            return preg_match($regex, $rec['message']) > 0;
+        }, $level);
+    }
+
     public function hasRecordThatPasses($predicate, $level)
     {
         if (!is_callable($predicate)) {

+ 2 - 0
tests/Monolog/Handler/TestHandlerTest.php

@@ -31,6 +31,7 @@ class TestHandlerTest extends TestCase
         $this->assertFalse($handler->{'has'.$method.'ThatPasses'}(function($rec){
             return true;
         }), 'has'.$method.'ThatPasses');
+        $this->assertFalse($handler->{'has'.$method.'ThatMatches'}('/test\w+/'));
         $this->assertFalse($handler->{'has'.$method.'Records'}(), 'has'.$method.'Records');
         $handler->handle($record);
 
@@ -41,6 +42,7 @@ class TestHandlerTest extends TestCase
         $this->assertTrue($handler->{'has'.$method.'ThatPasses'}(function($rec){
             return true;
         }), 'has'.$method.'ThatPasses');
+        $this->assertTrue($handler->{'has'.$method.'ThatMatches'}('/test\w+/'));
         $this->assertTrue($handler->{'has'.$method.'Records'}(), 'has'.$method.'Records');
 
         $records = $handler->getRecords();