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:
parent
b941eac988
commit
66532794b0
@ -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;
|
||||
}
|
||||
|
@ -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']);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user