Added tests on logs records

This commit is contained in:
Nicolas Lœuillet 2017-05-12 15:01:18 +02:00
parent 3554364bed
commit a1146b6551
No known key found for this signature in database
GPG Key ID: 7A5E5FFCBA7EF402
1 changed files with 22 additions and 3 deletions

View 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');
}
}