1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-02-21 13:33:52 +01:00

Add TagProcessor::addTags and TagProcessor::setTags, fixes #588

This commit is contained in:
Jordi Boggiano 2015-07-12 11:55:38 +01:00
parent b941eac988
commit 66532794b0
2 changed files with 30 additions and 0 deletions

View File

@ -21,6 +21,16 @@ class TagProcessor
private $tags;
public function __construct(array $tags = array())
{
$this->setTags($tags);
}
public function addTags(array $tags = array())
{
$this->tags = array_values(array_unique(array_merge($this->tags, $tags)));
}
public function setTags(array $tags = array())
{
$this->tags = $tags;
}

View File

@ -26,4 +26,24 @@ class TagProcessorTest extends TestCase
$this->assertEquals($tags, $record['extra']['tags']);
}
/**
* @covers Monolog\Processor\TagProcessor::__invoke
*/
public function testProcessorTagModification()
{
$tags = array(1, 2, 3);
$processor = new TagProcessor($tags);
$record = $processor($this->getRecord());
$this->assertEquals($tags, $record['extra']['tags']);
$processor->setTags(array('a', 'b'));
$record = $processor($this->getRecord());
$this->assertEquals(array('a', 'b'), $record['extra']['tags']);
$processor->addTags(array('a', 'c'));
$record = $processor($this->getRecord());
$this->assertEquals(array('a', 'b', 'c'), $record['extra']['tags']);
}
}