1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-04 20:27:31 +02:00

Fix WhatFailureGroupHandler::handleBatch when the handler has processors

This commit is contained in:
Chris Wilkinson
2017-07-12 07:45:50 +01:00
committed by Jordi Boggiano
parent 22b92c7c00
commit 3035d4a251
2 changed files with 33 additions and 0 deletions

View File

@@ -48,6 +48,16 @@ class WhatFailureGroupHandler extends GroupHandler
*/ */
public function handleBatch(array $records) public function handleBatch(array $records)
{ {
if ($this->processors) {
$processed = array();
foreach ($records as $record) {
foreach ($this->processors as $processor) {
$processed[] = call_user_func($processor, $record);
}
}
$records = $processed;
}
foreach ($this->handlers as $handler) { foreach ($this->handlers as $handler) {
try { try {
$handler->handleBatch($records); $handler->handleBatch($records);

View File

@@ -87,6 +87,29 @@ class WhatFailureGroupHandlerTest extends TestCase
$this->assertTrue($records[0]['extra']['foo']); $this->assertTrue($records[0]['extra']['foo']);
} }
/**
* @covers Monolog\Handler\WhatFailureGroupHandler::handleBatch
*/
public function testHandleBatchUsesProcessors()
{
$testHandlers = array(new TestHandler(), new TestHandler());
$handler = new WhatFailureGroupHandler($testHandlers);
$handler->pushProcessor(function ($record) {
$record['extra']['foo'] = true;
return $record;
});
$handler->handleBatch(array($this->getRecord(Logger::DEBUG), $this->getRecord(Logger::INFO)));
foreach ($testHandlers as $test) {
$this->assertTrue($test->hasDebugRecords());
$this->assertTrue($test->hasInfoRecords());
$this->assertTrue(count($test->getRecords()) === 2);
$records = $test->getRecords();
$this->assertTrue($records[0]['extra']['foo']);
$this->assertTrue($records[1]['extra']['foo']);
}
}
/** /**
* @covers Monolog\Handler\WhatFailureGroupHandler::handle * @covers Monolog\Handler\WhatFailureGroupHandler::handle
*/ */