From: Nicolas LÅ“uillet Date: Fri, 12 May 2017 13:01:18 +0000 (+0200) Subject: Added tests on logs records X-Git-Tag: 2.3.0~31^2~96^2 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=refs%2Fpull%2F3110%2Fhead;p=github%2Fwallabag%2Fwallabag.git Added tests on logs records --- diff --git a/tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php b/tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php index 522cf3b3..1e21f400 100644 --- a/tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php +++ b/tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php @@ -2,7 +2,8 @@ namespace Tests\Wallabag\CoreBundle\Helper; -use Psr\Log\NullLogger; +use Monolog\Handler\TestHandler; +use Monolog\Logger; use Wallabag\CoreBundle\Entity\Config; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; @@ -16,14 +17,19 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase private $tagRepository; private $entryRepository; private $tagger; + private $logger; + private $handler; public function setUp() { $this->rulerz = $this->getRulerZMock(); $this->tagRepository = $this->getTagRepositoryMock(); $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->getLogger()); + $this->tagger = new RuleBasedTagger($this->rulerz, $this->tagRepository, $this->entryRepository, $this->logger); } public function testTagWithNoRule() @@ -33,6 +39,8 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase $this->tagger->tag($entry); $this->assertTrue($entry->getTags()->isEmpty()); + $records = $this->handler->getRecords(); + $this->assertCount(0, $records); } public function testTagWithNoMatchingRule() @@ -50,6 +58,8 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase $this->tagger->tag($entry); $this->assertTrue($entry->getTags()->isEmpty()); + $records = $this->handler->getRecords(); + $this->assertCount(0, $records); } public function testTagWithAMatchingRule() @@ -71,6 +81,9 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase $tags = $entry->getTags(); $this->assertSame('foo', $tags[0]->getLabel()); $this->assertSame('bar', $tags[1]->getLabel()); + + $records = $this->handler->getRecords(); + $this->assertCount(1, $records); } public function testTagWithAMixOfMatchingRules() @@ -91,6 +104,8 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase $tags = $entry->getTags(); $this->assertSame('foo', $tags[0]->getLabel()); + $records = $this->handler->getRecords(); + $this->assertCount(1, $records); } public function testWhenTheTagExists() @@ -119,6 +134,8 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase $tags = $entry->getTags(); $this->assertSame($tag, $tags[0]); + $records = $this->handler->getRecords(); + $this->assertCount(1, $records); } public function testSameTagWithDifferentfMatchingRules() @@ -139,6 +156,8 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase $tags = $entry->getTags(); $this->assertCount(1, $tags); + $records = $this->handler->getRecords(); + $this->assertCount(2, $records); } public function testTagAllEntriesForAUser() @@ -213,6 +232,6 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase private function getLogger() { - return new NullLogger(); + return new Logger('foo'); } }