]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Added tests on logs records 3110/head
authorNicolas Lœuillet <nicolas@loeuillet.org>
Fri, 12 May 2017 13:01:18 +0000 (15:01 +0200)
committerNicolas Lœuillet <nicolas@loeuillet.org>
Fri, 12 May 2017 13:01:18 +0000 (15:01 +0200)
tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php

index 522cf3b36c397a378eeaf0539c9185d35927d5f5..1e21f4004d8448ea6dbe8e83834a7cb45351c4c9 100644 (file)
@@ -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');
     }
 }