mirror of
https://github.com/wallabag/wallabag.git
synced 2024-09-29 23:01:54 +00:00
Merge pull request #3110 from wallabag/add-logger-matching-rules
Added logger when we match Tagging rules
This commit is contained in:
commit
75045d6462
3 changed files with 35 additions and 2 deletions
|
@ -8,6 +8,7 @@ use Wallabag\CoreBundle\Entity\Tag;
|
||||||
use Wallabag\CoreBundle\Repository\EntryRepository;
|
use Wallabag\CoreBundle\Repository\EntryRepository;
|
||||||
use Wallabag\CoreBundle\Repository\TagRepository;
|
use Wallabag\CoreBundle\Repository\TagRepository;
|
||||||
use Wallabag\UserBundle\Entity\User;
|
use Wallabag\UserBundle\Entity\User;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class RuleBasedTagger
|
class RuleBasedTagger
|
||||||
{
|
{
|
||||||
|
@ -15,11 +16,12 @@ class RuleBasedTagger
|
||||||
private $tagRepository;
|
private $tagRepository;
|
||||||
private $entryRepository;
|
private $entryRepository;
|
||||||
|
|
||||||
public function __construct(RulerZ $rulerz, TagRepository $tagRepository, EntryRepository $entryRepository)
|
public function __construct(RulerZ $rulerz, TagRepository $tagRepository, EntryRepository $entryRepository, LoggerInterface $logger)
|
||||||
{
|
{
|
||||||
$this->rulerz = $rulerz;
|
$this->rulerz = $rulerz;
|
||||||
$this->tagRepository = $tagRepository;
|
$this->tagRepository = $tagRepository;
|
||||||
$this->entryRepository = $entryRepository;
|
$this->entryRepository = $entryRepository;
|
||||||
|
$this->logger = $logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,6 +38,11 @@ class RuleBasedTagger
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->logger->info('Matching rule.', [
|
||||||
|
'rule' => $rule->getRule(),
|
||||||
|
'tags' => $rule->getTags(),
|
||||||
|
]);
|
||||||
|
|
||||||
foreach ($rule->getTags() as $label) {
|
foreach ($rule->getTags() as $label) {
|
||||||
$tag = $this->getTag($label);
|
$tag = $this->getTag($label);
|
||||||
|
|
||||||
|
|
|
@ -99,6 +99,7 @@ services:
|
||||||
- "@rulerz"
|
- "@rulerz"
|
||||||
- "@wallabag_core.tag_repository"
|
- "@wallabag_core.tag_repository"
|
||||||
- "@wallabag_core.entry_repository"
|
- "@wallabag_core.entry_repository"
|
||||||
|
- "@logger"
|
||||||
|
|
||||||
# repository as a service
|
# repository as a service
|
||||||
wallabag_core.entry_repository:
|
wallabag_core.entry_repository:
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace Tests\Wallabag\CoreBundle\Helper;
|
namespace Tests\Wallabag\CoreBundle\Helper;
|
||||||
|
|
||||||
|
use Monolog\Handler\TestHandler;
|
||||||
|
use Monolog\Logger;
|
||||||
use Wallabag\CoreBundle\Entity\Config;
|
use Wallabag\CoreBundle\Entity\Config;
|
||||||
use Wallabag\CoreBundle\Entity\Entry;
|
use Wallabag\CoreBundle\Entity\Entry;
|
||||||
use Wallabag\CoreBundle\Entity\Tag;
|
use Wallabag\CoreBundle\Entity\Tag;
|
||||||
|
@ -15,14 +17,19 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase
|
||||||
private $tagRepository;
|
private $tagRepository;
|
||||||
private $entryRepository;
|
private $entryRepository;
|
||||||
private $tagger;
|
private $tagger;
|
||||||
|
private $logger;
|
||||||
|
private $handler;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->rulerz = $this->getRulerZMock();
|
$this->rulerz = $this->getRulerZMock();
|
||||||
$this->tagRepository = $this->getTagRepositoryMock();
|
$this->tagRepository = $this->getTagRepositoryMock();
|
||||||
$this->entryRepository = $this->getEntryRepositoryMock();
|
$this->entryRepository = $this->getEntryRepositoryMock();
|
||||||
|
$this->logger = $this->getLogger();
|
||||||
|
$this->handler = new TestHandler();
|
||||||
|
$this->logger->pushHandler($this->handler);
|
||||||
|
|
||||||
$this->tagger = new RuleBasedTagger($this->rulerz, $this->tagRepository, $this->entryRepository);
|
$this->tagger = new RuleBasedTagger($this->rulerz, $this->tagRepository, $this->entryRepository, $this->logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTagWithNoRule()
|
public function testTagWithNoRule()
|
||||||
|
@ -32,6 +39,8 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->tagger->tag($entry);
|
$this->tagger->tag($entry);
|
||||||
|
|
||||||
$this->assertTrue($entry->getTags()->isEmpty());
|
$this->assertTrue($entry->getTags()->isEmpty());
|
||||||
|
$records = $this->handler->getRecords();
|
||||||
|
$this->assertCount(0, $records);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTagWithNoMatchingRule()
|
public function testTagWithNoMatchingRule()
|
||||||
|
@ -49,6 +58,8 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->tagger->tag($entry);
|
$this->tagger->tag($entry);
|
||||||
|
|
||||||
$this->assertTrue($entry->getTags()->isEmpty());
|
$this->assertTrue($entry->getTags()->isEmpty());
|
||||||
|
$records = $this->handler->getRecords();
|
||||||
|
$this->assertCount(0, $records);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTagWithAMatchingRule()
|
public function testTagWithAMatchingRule()
|
||||||
|
@ -70,6 +81,9 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase
|
||||||
$tags = $entry->getTags();
|
$tags = $entry->getTags();
|
||||||
$this->assertSame('foo', $tags[0]->getLabel());
|
$this->assertSame('foo', $tags[0]->getLabel());
|
||||||
$this->assertSame('bar', $tags[1]->getLabel());
|
$this->assertSame('bar', $tags[1]->getLabel());
|
||||||
|
|
||||||
|
$records = $this->handler->getRecords();
|
||||||
|
$this->assertCount(1, $records);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTagWithAMixOfMatchingRules()
|
public function testTagWithAMixOfMatchingRules()
|
||||||
|
@ -90,6 +104,8 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$tags = $entry->getTags();
|
$tags = $entry->getTags();
|
||||||
$this->assertSame('foo', $tags[0]->getLabel());
|
$this->assertSame('foo', $tags[0]->getLabel());
|
||||||
|
$records = $this->handler->getRecords();
|
||||||
|
$this->assertCount(1, $records);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWhenTheTagExists()
|
public function testWhenTheTagExists()
|
||||||
|
@ -118,6 +134,8 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$tags = $entry->getTags();
|
$tags = $entry->getTags();
|
||||||
$this->assertSame($tag, $tags[0]);
|
$this->assertSame($tag, $tags[0]);
|
||||||
|
$records = $this->handler->getRecords();
|
||||||
|
$this->assertCount(1, $records);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSameTagWithDifferentfMatchingRules()
|
public function testSameTagWithDifferentfMatchingRules()
|
||||||
|
@ -138,6 +156,8 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$tags = $entry->getTags();
|
$tags = $entry->getTags();
|
||||||
$this->assertCount(1, $tags);
|
$this->assertCount(1, $tags);
|
||||||
|
$records = $this->handler->getRecords();
|
||||||
|
$this->assertCount(2, $records);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTagAllEntriesForAUser()
|
public function testTagAllEntriesForAUser()
|
||||||
|
@ -209,4 +229,9 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getLogger()
|
||||||
|
{
|
||||||
|
return new Logger('foo');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue