mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-03 19:57:41 +02:00
Make context optional in hasRecord to not break backwards compatibility
This commit is contained in:
committed by
Jordi Boggiano
parent
b381a973bc
commit
f753c68a73
@@ -86,19 +86,17 @@ class TestHandler extends AbstractProcessingHandler
|
|||||||
|
|
||||||
public function hasRecord($record, $level)
|
public function hasRecord($record, $level)
|
||||||
{
|
{
|
||||||
|
if (is_string($record)) {
|
||||||
|
$record = array('message' => $record);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->hasRecordThatPasses(function ($rec) use ($record) {
|
return $this->hasRecordThatPasses(function ($rec) use ($record) {
|
||||||
if (is_array($record)) {
|
|
||||||
if ($rec['message'] !== $record['message']) {
|
if ($rec['message'] !== $record['message']) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($rec['context'] !== $record['context']) {
|
if (isset($record['context']) && $rec['context'] !== $record['context']) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if ($rec['message'] !== $record) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}, $level);
|
}, $level);
|
||||||
}
|
}
|
||||||
|
@@ -56,48 +56,48 @@ class TestHandlerTest extends TestCase
|
|||||||
|
|
||||||
public function testHandlerAssertEmptyContext() {
|
public function testHandlerAssertEmptyContext() {
|
||||||
$handler = new TestHandler;
|
$handler = new TestHandler;
|
||||||
$record = $this->getRecord(Logger::WARNING, 'test', []);
|
$record = $this->getRecord(Logger::WARNING, 'test', array());
|
||||||
$this->assertFalse($handler->hasWarning([
|
$this->assertFalse($handler->hasWarning(array(
|
||||||
'message' => 'test',
|
'message' => 'test',
|
||||||
'context' => [],
|
'context' => array(),
|
||||||
]));
|
)));
|
||||||
|
|
||||||
$handler->handle($record);
|
$handler->handle($record);
|
||||||
|
|
||||||
$this->assertTrue($handler->hasWarning([
|
$this->assertTrue($handler->hasWarning(array(
|
||||||
'message' => 'test',
|
'message' => 'test',
|
||||||
'context' => [],
|
'context' => array(),
|
||||||
]));
|
)));
|
||||||
$this->assertFalse($handler->hasWarning([
|
$this->assertFalse($handler->hasWarning(array(
|
||||||
'message' => 'test',
|
'message' => 'test',
|
||||||
'context' => [
|
'context' => array(
|
||||||
'foo' => 'bar'
|
'foo' => 'bar'
|
||||||
],
|
),
|
||||||
]));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHandlerAssertNonEmptyContext() {
|
public function testHandlerAssertNonEmptyContext() {
|
||||||
$handler = new TestHandler;
|
$handler = new TestHandler;
|
||||||
$record = $this->getRecord(Logger::WARNING, 'test', ['foo' => 'bar']);
|
$record = $this->getRecord(Logger::WARNING, 'test', array('foo' => 'bar'));
|
||||||
$this->assertFalse($handler->hasWarning([
|
$this->assertFalse($handler->hasWarning(array(
|
||||||
'message' => 'test',
|
'message' => 'test',
|
||||||
'context' => [
|
'context' => array(
|
||||||
'foo' => 'bar'
|
'foo' => 'bar'
|
||||||
],
|
),
|
||||||
]));
|
)));
|
||||||
|
|
||||||
$handler->handle($record);
|
$handler->handle($record);
|
||||||
|
|
||||||
$this->assertTrue($handler->hasWarning([
|
$this->assertTrue($handler->hasWarning(array(
|
||||||
'message' => 'test',
|
'message' => 'test',
|
||||||
'context' => [
|
'context' => array(
|
||||||
'foo' => 'bar'
|
'foo' => 'bar'
|
||||||
],
|
),
|
||||||
]));
|
)));
|
||||||
$this->assertFalse($handler->hasWarning([
|
$this->assertFalse($handler->hasWarning(array(
|
||||||
'message' => 'test',
|
'message' => 'test',
|
||||||
'context' => [],
|
'context' => array(),
|
||||||
]));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function methodProvider()
|
public function methodProvider()
|
||||||
|
Reference in New Issue
Block a user