mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-09 22:56:41 +02:00
Add TestHandler::hasRecordThatMatches($regex, $level)
This commit is contained in:
@@ -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)) {
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user