mirror of
https://github.com/wallabag/wallabag.git
synced 2025-01-15 08:46:16 +01:00
Added tests on logs records
This commit is contained in:
parent
3554364bed
commit
a1146b6551
@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
namespace Tests\Wallabag\CoreBundle\Helper;
|
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\Config;
|
||||||
use Wallabag\CoreBundle\Entity\Entry;
|
use Wallabag\CoreBundle\Entity\Entry;
|
||||||
use Wallabag\CoreBundle\Entity\Tag;
|
use Wallabag\CoreBundle\Entity\Tag;
|
||||||
@ -16,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->getLogger());
|
$this->tagger = new RuleBasedTagger($this->rulerz, $this->tagRepository, $this->entryRepository, $this->logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTagWithNoRule()
|
public function testTagWithNoRule()
|
||||||
@ -33,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()
|
||||||
@ -50,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()
|
||||||
@ -71,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()
|
||||||
@ -91,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()
|
||||||
@ -119,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()
|
||||||
@ -139,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()
|
||||||
@ -213,6 +232,6 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
private function getLogger()
|
private function getLogger()
|
||||||
{
|
{
|
||||||
return new NullLogger();
|
return new Logger('foo');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user