diff --git a/src/Monolog/Handler/TestHandler.php b/src/Monolog/Handler/TestHandler.php index fc2a5e3a..24c025a0 100644 --- a/src/Monolog/Handler/TestHandler.php +++ b/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)) { diff --git a/tests/Monolog/Handler/TestHandlerTest.php b/tests/Monolog/Handler/TestHandlerTest.php index 3ff3d62c..de3ae4b6 100644 --- a/tests/Monolog/Handler/TestHandlerTest.php +++ b/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();