mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-03 11:47:38 +02:00
Merge branch '1.x'
This commit is contained in:
@@ -86,12 +86,18 @@ class TestHandler extends AbstractProcessingHandler
|
|||||||
|
|
||||||
public function hasRecord($record, $level)
|
public function hasRecord($record, $level)
|
||||||
{
|
{
|
||||||
if (is_array($record)) {
|
if (is_string($record)) {
|
||||||
$record = $record['message'];
|
$record = array('message' => $record);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->hasRecordThatPasses(function ($rec) use ($record) {
|
return $this->hasRecordThatPasses(function ($rec) use ($record) {
|
||||||
return $rec['message'] === $record;
|
if ($rec['message'] !== $record['message']) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (isset($record['context']) && $rec['context'] !== $record['context']) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}, $level);
|
}, $level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -54,6 +54,52 @@ class TestHandlerTest extends TestCase
|
|||||||
$this->assertEquals([$record], $records);
|
$this->assertEquals([$record], $records);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testHandlerAssertEmptyContext() {
|
||||||
|
$handler = new TestHandler;
|
||||||
|
$record = $this->getRecord(Logger::WARNING, 'test', []);
|
||||||
|
$this->assertFalse($handler->hasWarning([
|
||||||
|
'message' => 'test',
|
||||||
|
'context' => [],
|
||||||
|
]));
|
||||||
|
|
||||||
|
$handler->handle($record);
|
||||||
|
|
||||||
|
$this->assertTrue($handler->hasWarning([
|
||||||
|
'message' => 'test',
|
||||||
|
'context' => [],
|
||||||
|
]));
|
||||||
|
$this->assertFalse($handler->hasWarning([
|
||||||
|
'message' => 'test',
|
||||||
|
'context' => [
|
||||||
|
'foo' => 'bar'
|
||||||
|
],
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testHandlerAssertNonEmptyContext() {
|
||||||
|
$handler = new TestHandler;
|
||||||
|
$record = $this->getRecord(Logger::WARNING, 'test', ['foo' => 'bar']);
|
||||||
|
$this->assertFalse($handler->hasWarning([
|
||||||
|
'message' => 'test',
|
||||||
|
'context' => [
|
||||||
|
'foo' => 'bar'
|
||||||
|
],
|
||||||
|
]));
|
||||||
|
|
||||||
|
$handler->handle($record);
|
||||||
|
|
||||||
|
$this->assertTrue($handler->hasWarning([
|
||||||
|
'message' => 'test',
|
||||||
|
'context' => [
|
||||||
|
'foo' => 'bar'
|
||||||
|
],
|
||||||
|
]));
|
||||||
|
$this->assertFalse($handler->hasWarning([
|
||||||
|
'message' => 'test',
|
||||||
|
'context' => [],
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
public function methodProvider()
|
public function methodProvider()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
Reference in New Issue
Block a user