1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-09 06:36:46 +02:00

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

This commit is contained in:
Austin Hyde
2015-06-20 19:41:17 -04:00
parent 3e8f0ecb36
commit f2fea2c3f5
2 changed files with 18 additions and 0 deletions

View File

@@ -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)) {

View File

@@ -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();