From 6bc6fb1f60e7b81a21f844dca025671a2f4a4564 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sat, 27 May 2017 22:08:14 +0200 Subject: Move Tags assigner to a separate file Signed-off-by: Thomas Citharel --- tests/Wallabag/ImportBundle/Import/ChromeImportTest.php | 7 ++++++- tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php | 7 ++++++- tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php | 7 ++++++- tests/Wallabag/ImportBundle/Import/PocketImportTest.php | 8 +++++++- tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php | 7 ++++++- tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php | 8 +++++++- tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php | 8 +++++++- 7 files changed, 45 insertions(+), 7 deletions(-) (limited to 'tests/Wallabag/ImportBundle/Import') diff --git a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php index 6b3adda4..cec19534 100644 --- a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php @@ -17,6 +17,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase protected $em; protected $logHandler; protected $contentProxy; + protected $tagsAssigner; private function getChromeImport($unsetUser = false, $dispatched = 0) { @@ -30,6 +31,10 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); + $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') + ->disableOriginalConstructor() + ->getMock(); + $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') ->disableOriginalConstructor() ->getMock(); @@ -38,7 +43,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase ->expects($this->exactly($dispatched)) ->method('dispatch'); - $wallabag = new ChromeImport($this->em, $this->contentProxy, $dispatcher); + $wallabag = new ChromeImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); $this->logHandler = new TestHandler(); $logger = new Logger('test', [$this->logHandler]); diff --git a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php index b516fbc5..c186c820 100644 --- a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php @@ -17,6 +17,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase protected $em; protected $logHandler; protected $contentProxy; + protected $tagsAssigner; private function getFirefoxImport($unsetUser = false, $dispatched = 0) { @@ -30,6 +31,10 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); + $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') + ->disableOriginalConstructor() + ->getMock(); + $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') ->disableOriginalConstructor() ->getMock(); @@ -38,7 +43,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase ->expects($this->exactly($dispatched)) ->method('dispatch'); - $wallabag = new FirefoxImport($this->em, $this->contentProxy, $dispatcher); + $wallabag = new FirefoxImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); $this->logHandler = new TestHandler(); $logger = new Logger('test', [$this->logHandler]); diff --git a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php index e262a808..6777a02e 100644 --- a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php @@ -17,6 +17,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase protected $em; protected $logHandler; protected $contentProxy; + protected $tagsAssigner; private function getInstapaperImport($unsetUser = false, $dispatched = 0) { @@ -30,6 +31,10 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); + $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') + ->disableOriginalConstructor() + ->getMock(); + $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') ->disableOriginalConstructor() ->getMock(); @@ -38,7 +43,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase ->expects($this->exactly($dispatched)) ->method('dispatch'); - $import = new InstapaperImport($this->em, $this->contentProxy, $dispatcher); + $import = new InstapaperImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); $this->logHandler = new TestHandler(); $logger = new Logger('test', [$this->logHandler]); diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index 141ece36..b81ebe15 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -23,6 +23,8 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase protected $em; protected $contentProxy; protected $logHandler; + protected $tagsAssigner; + protected $uow; private function getPocketImport($consumerKey = 'ConsumerKey', $dispatched = 0) { @@ -37,6 +39,10 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); + $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') + ->disableOriginalConstructor() + ->getMock(); + $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') ->disableOriginalConstructor() ->getMock(); @@ -63,7 +69,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase ->expects($this->exactly($dispatched)) ->method('dispatch'); - $pocket = new PocketImport($this->em, $this->contentProxy, $dispatcher); + $pocket = new PocketImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); $pocket->setUser($this->user); $this->logHandler = new TestHandler(); diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php index d1bbe648..254f0a25 100644 --- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php @@ -17,6 +17,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase protected $em; protected $logHandler; protected $contentProxy; + protected $tagsAssigner; private function getReadabilityImport($unsetUser = false, $dispatched = 0) { @@ -30,6 +31,10 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); + $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') + ->disableOriginalConstructor() + ->getMock(); + $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') ->disableOriginalConstructor() ->getMock(); @@ -38,7 +43,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase ->expects($this->exactly($dispatched)) ->method('dispatch'); - $wallabag = new ReadabilityImport($this->em, $this->contentProxy, $dispatcher); + $wallabag = new ReadabilityImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); $this->logHandler = new TestHandler(); $logger = new Logger('test', [$this->logHandler]); diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php index 4dbced60..9f0c5bac 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php @@ -17,6 +17,8 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase protected $em; protected $logHandler; protected $contentProxy; + protected $tagsAssigner; + protected $uow; private function getWallabagV1Import($unsetUser = false, $dispatched = 0) { @@ -44,6 +46,10 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); + $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') + ->disableOriginalConstructor() + ->getMock(); + $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') ->disableOriginalConstructor() ->getMock(); @@ -52,7 +58,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase ->expects($this->exactly($dispatched)) ->method('dispatch'); - $wallabag = new WallabagV1Import($this->em, $this->contentProxy, $dispatcher); + $wallabag = new WallabagV1Import($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); $this->logHandler = new TestHandler(); $logger = new Logger('test', [$this->logHandler]); diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php index 0e50b8b2..efcaeb9e 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php @@ -17,6 +17,8 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase protected $em; protected $logHandler; protected $contentProxy; + protected $tagsAssigner; + protected $uow; private function getWallabagV2Import($unsetUser = false, $dispatched = 0) { @@ -44,6 +46,10 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); + $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') + ->disableOriginalConstructor() + ->getMock(); + $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') ->disableOriginalConstructor() ->getMock(); @@ -52,7 +58,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase ->expects($this->exactly($dispatched)) ->method('dispatch'); - $wallabag = new WallabagV2Import($this->em, $this->contentProxy, $dispatcher); + $wallabag = new WallabagV2Import($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); $this->logHandler = new TestHandler(); $logger = new Logger('test', [$this->logHandler]); -- cgit v1.2.3 From 7a8ed3cee1003aae56400e18509980e2695ea622 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 31 May 2017 10:38:00 +0200 Subject: Add support for tag in Instapaper import --- .../ImportBundle/Import/InstapaperImportTest.php | 35 +++++++++++++++------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'tests/Wallabag/ImportBundle/Import') diff --git a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php index 6777a02e..9158c8a2 100644 --- a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php @@ -18,6 +18,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase protected $logHandler; protected $contentProxy; protected $tagsAssigner; + protected $uow; private function getInstapaperImport($unsetUser = false, $dispatched = 0) { @@ -27,6 +28,20 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); + $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') + ->disableOriginalConstructor() + ->getMock(); + + $this->em + ->expects($this->any()) + ->method('getUnitOfWork') + ->willReturn($this->uow); + + $this->uow + ->expects($this->any()) + ->method('getScheduledEntityInsertions') + ->willReturn([]); + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') ->disableOriginalConstructor() ->getMock(); @@ -67,14 +82,14 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase public function testImport() { - $instapaperImport = $this->getInstapaperImport(false, 3); + $instapaperImport = $this->getInstapaperImport(false, 4); $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() ->getMock(); - $entryRepo->expects($this->exactly(3)) + $entryRepo->expects($this->exactly(4)) ->method('findByUrlAndUserId') ->willReturn(false); @@ -88,14 +103,14 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $this->contentProxy - ->expects($this->exactly(3)) + ->expects($this->exactly(4)) ->method('updateEntry') ->willReturn($entry); $res = $instapaperImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 3, 'queued' => 0], $instapaperImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $instapaperImport->getSummary()); } public function testImportAndMarkAllAsRead() @@ -107,9 +122,9 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $entryRepo->expects($this->exactly(3)) + $entryRepo->expects($this->exactly(4)) ->method('findByUrlAndUserId') - ->will($this->onConsecutiveCalls(false, true, true)); + ->will($this->onConsecutiveCalls(false, true, true, true)); $this->em ->expects($this->any()) @@ -133,7 +148,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 2, 'imported' => 1, 'queued' => 0], $instapaperImport->getSummary()); + $this->assertEquals(['skipped' => 3, 'imported' => 1, 'queued' => 0], $instapaperImport->getSummary()); } public function testImportWithRabbit() @@ -165,7 +180,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $producer - ->expects($this->exactly(3)) + ->expects($this->exactly(4)) ->method('publish'); $instapaperImport->setProducer($producer); @@ -173,7 +188,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase $res = $instapaperImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $instapaperImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $instapaperImport->getSummary()); } public function testImportWithRedis() @@ -211,7 +226,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase $res = $instapaperImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $instapaperImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $instapaperImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('instapaper')); } -- cgit v1.2.3 From e668a8124c46d47add4248963d77f3b29b37b3ce Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 11 May 2017 08:14:29 +0200 Subject: Allow other fields to be send using API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Entry API can now have these new fields: - content - language - preview_picture - published_at Re-use the ContentProxy to be able to do the same using the web UI (in the future). htmLawed is used to clean stuff from content, I hope it’ll be enough to avoid security breach. Lower content validation when we want to update an entry with content already defined. Before, language & content_type were required. If there weren’t provided, we re-fetched the content using graby. I think these fields aren’t required for an entry to be created. So I removed them. Which means some import from the v1 export won’t be re-fetched since they provide content, url & title. Also, remove liberation link from Readability import to avoid overlaping import (from wallabag v1, which had the same link) --- .../Wallabag/ImportBundle/Import/ReadabilityImportTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'tests/Wallabag/ImportBundle/Import') diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php index 254f0a25..25eedd1b 100644 --- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php @@ -67,14 +67,14 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase public function testImport() { - $readabilityImport = $this->getReadabilityImport(false, 24); + $readabilityImport = $this->getReadabilityImport(false, 23); $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() ->getMock(); - $entryRepo->expects($this->exactly(24)) + $entryRepo->expects($this->exactly(23)) ->method('findByUrlAndUserId') ->willReturn(false); @@ -88,14 +88,14 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $this->contentProxy - ->expects($this->exactly(24)) + ->expects($this->exactly(23)) ->method('updateEntry') ->willReturn($entry); $res = $readabilityImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 24, 'queued' => 0], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 23, 'queued' => 0], $readabilityImport->getSummary()); } public function testImportAndMarkAllAsRead() @@ -165,7 +165,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $producer - ->expects($this->exactly(24)) + ->expects($this->exactly(23)) ->method('publish'); $readabilityImport->setProducer($producer); @@ -173,7 +173,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $res = $readabilityImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 23], $readabilityImport->getSummary()); } public function testImportWithRedis() @@ -211,7 +211,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $res = $readabilityImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 23], $readabilityImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('readability')); } -- cgit v1.2.3 From cf05a1ae342b8f59ee0944eeba0f75aa0a1a2816 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 16 May 2017 21:17:10 +0200 Subject: Reduce imported entries Down from 2.2 minutes to 1.39 minutes --- .../Wallabag/ImportBundle/Import/ReadabilityImportTest.php | 14 +++++++------- .../Wallabag/ImportBundle/Import/WallabagV1ImportTest.php | 14 +++++++------- .../Wallabag/ImportBundle/Import/WallabagV2ImportTest.php | 14 +++++++------- 3 files changed, 21 insertions(+), 21 deletions(-) (limited to 'tests/Wallabag/ImportBundle/Import') diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php index 25eedd1b..8f466d38 100644 --- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php @@ -67,14 +67,14 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase public function testImport() { - $readabilityImport = $this->getReadabilityImport(false, 23); + $readabilityImport = $this->getReadabilityImport(false, 3); $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() ->getMock(); - $entryRepo->expects($this->exactly(23)) + $entryRepo->expects($this->exactly(3)) ->method('findByUrlAndUserId') ->willReturn(false); @@ -88,14 +88,14 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $this->contentProxy - ->expects($this->exactly(23)) + ->expects($this->exactly(3)) ->method('updateEntry') ->willReturn($entry); $res = $readabilityImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 23, 'queued' => 0], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 3, 'queued' => 0], $readabilityImport->getSummary()); } public function testImportAndMarkAllAsRead() @@ -165,7 +165,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $producer - ->expects($this->exactly(23)) + ->expects($this->exactly(3)) ->method('publish'); $readabilityImport->setProducer($producer); @@ -173,7 +173,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $res = $readabilityImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 23], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $readabilityImport->getSummary()); } public function testImportWithRedis() @@ -211,7 +211,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $res = $readabilityImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 23], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $readabilityImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('readability')); } diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php index 9f0c5bac..7cbef637 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php @@ -82,14 +82,14 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase public function testImport() { - $wallabagV1Import = $this->getWallabagV1Import(false, 3); + $wallabagV1Import = $this->getWallabagV1Import(false, 1); $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() ->getMock(); - $entryRepo->expects($this->exactly(4)) + $entryRepo->expects($this->exactly(2)) ->method('findByUrlAndUserId') ->will($this->onConsecutiveCalls(false, true, false, false)); @@ -103,14 +103,14 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $this->contentProxy - ->expects($this->exactly(3)) + ->expects($this->exactly(1)) ->method('updateEntry') ->willReturn($entry); $res = $wallabagV1Import->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 3, 'queued' => 0], $wallabagV1Import->getSummary()); + $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $wallabagV1Import->getSummary()); } public function testImportAndMarkAllAsRead() @@ -180,7 +180,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $producer - ->expects($this->exactly(4)) + ->expects($this->exactly(2)) ->method('publish'); $wallabagV1Import->setProducer($producer); @@ -188,7 +188,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV1Import->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $wallabagV1Import->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 2], $wallabagV1Import->getSummary()); } public function testImportWithRedis() @@ -226,7 +226,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV1Import->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $wallabagV1Import->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 2], $wallabagV1Import->getSummary()); $this->assertNotEmpty($redisMock->lpop('wallabag_v1')); } diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php index efcaeb9e..5cc04aa5 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php @@ -89,7 +89,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $entryRepo->expects($this->exactly(24)) + $entryRepo->expects($this->exactly(6)) ->method('findByUrlAndUserId') ->will($this->onConsecutiveCalls(false, true, false)); @@ -106,7 +106,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV2Import->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 22, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); + $this->assertEquals(['skipped' => 4, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); } public function testImportAndMarkAllAsRead() @@ -172,7 +172,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $producer - ->expects($this->exactly(24)) + ->expects($this->exactly(6)) ->method('publish'); $wallabagV2Import->setProducer($producer); @@ -180,7 +180,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV2Import->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $wallabagV2Import->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 6], $wallabagV2Import->getSummary()); } public function testImportWithRedis() @@ -214,7 +214,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV2Import->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $wallabagV2Import->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 6], $wallabagV2Import->getSummary()); $this->assertNotEmpty($redisMock->lpop('wallabag_v2')); } @@ -267,7 +267,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $entryRepo->expects($this->exactly(24)) + $entryRepo->expects($this->exactly(6)) ->method('findByUrlAndUserId') ->will($this->onConsecutiveCalls(false, true, false)); @@ -284,6 +284,6 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV2Import->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 22, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); + $this->assertEquals(['skipped' => 4, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); } } -- cgit v1.2.3 From d0e9b3d640acce49068d1a2c5603b92c1bda363e Mon Sep 17 00:00:00 2001 From: Jerome Charaoui Date: Wed, 7 Dec 2016 15:16:49 -0500 Subject: Add disableContentUpdate import option This commit also decouples the "import" and "update" functions inside ContentProxy. If a content array is available, it must be passed to the new importEntry method. --- tests/Wallabag/ImportBundle/Import/ChromeImportTest.php | 8 ++++---- tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php | 8 ++++---- tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php | 8 ++++---- tests/Wallabag/ImportBundle/Import/PocketImportTest.php | 10 +++++----- tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php | 8 ++++---- tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php | 8 ++++---- tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php | 10 +++++----- 7 files changed, 30 insertions(+), 30 deletions(-) (limited to 'tests/Wallabag/ImportBundle/Import') diff --git a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php index cec19534..7a15e918 100644 --- a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php @@ -89,7 +89,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->exactly(1)) - ->method('updateEntry') + ->method('importEntry') ->willReturn($entry); $res = $chromeImport->import(); @@ -118,7 +118,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->exactly(1)) - ->method('updateEntry') + ->method('importEntry') ->willReturn(new Entry($this->user)); // check that every entry persisted are archived @@ -158,7 +158,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->never()) - ->method('updateEntry'); + ->method('importEntry'); $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') ->disableOriginalConstructor() @@ -198,7 +198,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->never()) - ->method('updateEntry'); + ->method('importEntry'); $factory = new RedisMockFactory(); $redisMock = $factory->getAdapter('Predis\Client', true); diff --git a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php index c186c820..09abac57 100644 --- a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php @@ -89,7 +89,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->exactly(2)) - ->method('updateEntry') + ->method('importEntry') ->willReturn($entry); $res = $firefoxImport->import(); @@ -118,7 +118,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->exactly(1)) - ->method('updateEntry') + ->method('importEntry') ->willReturn(new Entry($this->user)); // check that every entry persisted are archived @@ -158,7 +158,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->never()) - ->method('updateEntry'); + ->method('importEntry'); $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') ->disableOriginalConstructor() @@ -198,7 +198,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->never()) - ->method('updateEntry'); + ->method('importEntry'); $factory = new RedisMockFactory(); $redisMock = $factory->getAdapter('Predis\Client', true); diff --git a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php index 9158c8a2..05844490 100644 --- a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php @@ -104,7 +104,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->exactly(4)) - ->method('updateEntry') + ->method('importEntry') ->willReturn($entry); $res = $instapaperImport->import(); @@ -133,7 +133,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->once()) - ->method('updateEntry') + ->method('importEntry') ->willReturn(new Entry($this->user)); // check that every entry persisted are archived @@ -173,7 +173,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->never()) - ->method('updateEntry'); + ->method('importEntry'); $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') ->disableOriginalConstructor() @@ -213,7 +213,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->never()) - ->method('updateEntry'); + ->method('importEntry'); $factory = new RedisMockFactory(); $redisMock = $factory->getAdapter('Predis\Client', true); diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index b81ebe15..f75e6bea 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -282,7 +282,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->once()) - ->method('updateEntry') + ->method('importEntry') ->willReturn($entry); $pocketImport->setClient($client); @@ -377,7 +377,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->exactly(2)) - ->method('updateEntry') + ->method('importEntry') ->willReturn($entry); $pocketImport->setClient($client); @@ -450,7 +450,7 @@ JSON; $this->contentProxy ->expects($this->never()) - ->method('updateEntry'); + ->method('importEntry'); $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') ->disableOriginalConstructor() @@ -536,7 +536,7 @@ JSON; $this->contentProxy ->expects($this->never()) - ->method('updateEntry'); + ->method('ImportEntry'); $factory = new RedisMockFactory(); $redisMock = $factory->getAdapter('Predis\Client', true); @@ -621,7 +621,7 @@ JSON; $this->contentProxy ->expects($this->once()) - ->method('updateEntry') + ->method('importEntry') ->will($this->throwException(new \Exception())); $pocketImport->setClient($client); diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php index 8f466d38..1b0daa92 100644 --- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php @@ -89,7 +89,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->exactly(3)) - ->method('updateEntry') + ->method('importEntry') ->willReturn($entry); $res = $readabilityImport->import(); @@ -118,7 +118,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->exactly(1)) - ->method('updateEntry') + ->method('importEntry') ->willReturn(new Entry($this->user)); // check that every entry persisted are archived @@ -158,7 +158,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->never()) - ->method('updateEntry'); + ->method('importEntry'); $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') ->disableOriginalConstructor() @@ -198,7 +198,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->never()) - ->method('updateEntry'); + ->method('importEntry'); $factory = new RedisMockFactory(); $redisMock = $factory->getAdapter('Predis\Client', true); diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php index 7cbef637..f23cb748 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php @@ -104,7 +104,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->exactly(1)) - ->method('updateEntry') + ->method('importEntry') ->willReturn($entry); $res = $wallabagV1Import->import(); @@ -133,7 +133,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->exactly(3)) - ->method('updateEntry') + ->method('importEntry') ->willReturn(new Entry($this->user)); // check that every entry persisted are archived @@ -173,7 +173,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->never()) - ->method('updateEntry'); + ->method('importEntry'); $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') ->disableOriginalConstructor() @@ -213,7 +213,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->never()) - ->method('updateEntry'); + ->method('importEntry'); $factory = new RedisMockFactory(); $redisMock = $factory->getAdapter('Predis\Client', true); diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php index 5cc04aa5..e1acf569 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php @@ -100,7 +100,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->exactly(2)) - ->method('updateEntry') + ->method('importEntry') ->willReturn(new Entry($this->user)); $res = $wallabagV2Import->import(); @@ -129,7 +129,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->exactly(2)) - ->method('updateEntry') + ->method('importEntry') ->willReturn(new Entry($this->user)); // check that every entry persisted are archived @@ -165,7 +165,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->never()) - ->method('updateEntry'); + ->method('importEntry'); $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') ->disableOriginalConstructor() @@ -201,7 +201,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->never()) - ->method('updateEntry'); + ->method('importEntry'); $factory = new RedisMockFactory(); $redisMock = $factory->getAdapter('Predis\Client', true); @@ -278,7 +278,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->exactly(2)) - ->method('updateEntry') + ->method('importEntry') ->will($this->throwException(new \Exception())); $res = $wallabagV2Import->import(); -- cgit v1.2.3 From 704803e182068923eba16f3dc451e9231f15ecb5 Mon Sep 17 00:00:00 2001 From: Jerome Charaoui Date: Fri, 16 Dec 2016 09:46:21 -0500 Subject: Replace Wallabag v1 error strings with v2 strings --- tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'tests/Wallabag/ImportBundle/Import') diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php index f23cb748..3b2375a1 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php @@ -19,6 +19,8 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase protected $contentProxy; protected $tagsAssigner; protected $uow; + protected $fetchingErrorMessageTitle = 'No title found'; + protected $fetchingErrorMessage = 'wallabag can\'t retrieve contents for this article. Please troubleshoot this issue.'; private function getWallabagV1Import($unsetUser = false, $dispatched = 0) { @@ -58,7 +60,14 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase ->expects($this->exactly($dispatched)) ->method('dispatch'); - $wallabag = new WallabagV1Import($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); + $wallabag = new WallabagV1Import( + $this->em, + $this->contentProxy, + $this->tagsAssigner, + $dispatcher, + $this->fetchingErrorMessageTitle, + $this->fetchingErrorMessage + ); $this->logHandler = new TestHandler(); $logger = new Logger('test', [$this->logHandler]); -- cgit v1.2.3 From 6acadf8e98cf6021a9019773df75bdb151865687 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 1 Jun 2017 11:31:45 +0200 Subject: Rewrote code & fix tests --- tests/Wallabag/ImportBundle/Import/ChromeImportTest.php | 8 ++++---- tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php | 8 ++++---- tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php | 8 ++++---- tests/Wallabag/ImportBundle/Import/PocketImportTest.php | 10 +++++----- tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php | 8 ++++---- tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php | 8 ++++---- tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php | 10 +++++----- 7 files changed, 30 insertions(+), 30 deletions(-) (limited to 'tests/Wallabag/ImportBundle/Import') diff --git a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php index 7a15e918..cec19534 100644 --- a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php @@ -89,7 +89,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->exactly(1)) - ->method('importEntry') + ->method('updateEntry') ->willReturn($entry); $res = $chromeImport->import(); @@ -118,7 +118,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->exactly(1)) - ->method('importEntry') + ->method('updateEntry') ->willReturn(new Entry($this->user)); // check that every entry persisted are archived @@ -158,7 +158,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->never()) - ->method('importEntry'); + ->method('updateEntry'); $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') ->disableOriginalConstructor() @@ -198,7 +198,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->never()) - ->method('importEntry'); + ->method('updateEntry'); $factory = new RedisMockFactory(); $redisMock = $factory->getAdapter('Predis\Client', true); diff --git a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php index 09abac57..c186c820 100644 --- a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php @@ -89,7 +89,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->exactly(2)) - ->method('importEntry') + ->method('updateEntry') ->willReturn($entry); $res = $firefoxImport->import(); @@ -118,7 +118,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->exactly(1)) - ->method('importEntry') + ->method('updateEntry') ->willReturn(new Entry($this->user)); // check that every entry persisted are archived @@ -158,7 +158,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->never()) - ->method('importEntry'); + ->method('updateEntry'); $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') ->disableOriginalConstructor() @@ -198,7 +198,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->never()) - ->method('importEntry'); + ->method('updateEntry'); $factory = new RedisMockFactory(); $redisMock = $factory->getAdapter('Predis\Client', true); diff --git a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php index 05844490..9158c8a2 100644 --- a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php @@ -104,7 +104,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->exactly(4)) - ->method('importEntry') + ->method('updateEntry') ->willReturn($entry); $res = $instapaperImport->import(); @@ -133,7 +133,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->once()) - ->method('importEntry') + ->method('updateEntry') ->willReturn(new Entry($this->user)); // check that every entry persisted are archived @@ -173,7 +173,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->never()) - ->method('importEntry'); + ->method('updateEntry'); $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') ->disableOriginalConstructor() @@ -213,7 +213,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->never()) - ->method('importEntry'); + ->method('updateEntry'); $factory = new RedisMockFactory(); $redisMock = $factory->getAdapter('Predis\Client', true); diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index f75e6bea..b81ebe15 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -282,7 +282,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->once()) - ->method('importEntry') + ->method('updateEntry') ->willReturn($entry); $pocketImport->setClient($client); @@ -377,7 +377,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->exactly(2)) - ->method('importEntry') + ->method('updateEntry') ->willReturn($entry); $pocketImport->setClient($client); @@ -450,7 +450,7 @@ JSON; $this->contentProxy ->expects($this->never()) - ->method('importEntry'); + ->method('updateEntry'); $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') ->disableOriginalConstructor() @@ -536,7 +536,7 @@ JSON; $this->contentProxy ->expects($this->never()) - ->method('ImportEntry'); + ->method('updateEntry'); $factory = new RedisMockFactory(); $redisMock = $factory->getAdapter('Predis\Client', true); @@ -621,7 +621,7 @@ JSON; $this->contentProxy ->expects($this->once()) - ->method('importEntry') + ->method('updateEntry') ->will($this->throwException(new \Exception())); $pocketImport->setClient($client); diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php index 1b0daa92..8f466d38 100644 --- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php @@ -89,7 +89,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->exactly(3)) - ->method('importEntry') + ->method('updateEntry') ->willReturn($entry); $res = $readabilityImport->import(); @@ -118,7 +118,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->exactly(1)) - ->method('importEntry') + ->method('updateEntry') ->willReturn(new Entry($this->user)); // check that every entry persisted are archived @@ -158,7 +158,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->never()) - ->method('importEntry'); + ->method('updateEntry'); $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') ->disableOriginalConstructor() @@ -198,7 +198,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->never()) - ->method('importEntry'); + ->method('updateEntry'); $factory = new RedisMockFactory(); $redisMock = $factory->getAdapter('Predis\Client', true); diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php index 3b2375a1..834b7ef5 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php @@ -113,7 +113,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->exactly(1)) - ->method('importEntry') + ->method('updateEntry') ->willReturn($entry); $res = $wallabagV1Import->import(); @@ -142,7 +142,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->exactly(3)) - ->method('importEntry') + ->method('updateEntry') ->willReturn(new Entry($this->user)); // check that every entry persisted are archived @@ -182,7 +182,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->never()) - ->method('importEntry'); + ->method('updateEntry'); $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') ->disableOriginalConstructor() @@ -222,7 +222,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->never()) - ->method('importEntry'); + ->method('updateEntry'); $factory = new RedisMockFactory(); $redisMock = $factory->getAdapter('Predis\Client', true); diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php index e1acf569..5cc04aa5 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php @@ -100,7 +100,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->exactly(2)) - ->method('importEntry') + ->method('updateEntry') ->willReturn(new Entry($this->user)); $res = $wallabagV2Import->import(); @@ -129,7 +129,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->exactly(2)) - ->method('importEntry') + ->method('updateEntry') ->willReturn(new Entry($this->user)); // check that every entry persisted are archived @@ -165,7 +165,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->never()) - ->method('importEntry'); + ->method('updateEntry'); $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') ->disableOriginalConstructor() @@ -201,7 +201,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->never()) - ->method('importEntry'); + ->method('updateEntry'); $factory = new RedisMockFactory(); $redisMock = $factory->getAdapter('Predis\Client', true); @@ -278,7 +278,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $this->contentProxy ->expects($this->exactly(2)) - ->method('importEntry') + ->method('updateEntry') ->will($this->throwException(new \Exception())); $res = $wallabagV2Import->import(); -- cgit v1.2.3 From f808b01692a835673f328d7221ba8c212caa9b61 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 1 Jul 2017 09:52:38 +0200 Subject: Add a real configuration for CS-Fixer --- .../ImportBundle/Import/ChromeImportTest.php | 114 +++++++-------- .../ImportBundle/Import/FirefoxImportTest.php | 114 +++++++-------- .../ImportBundle/Import/ImportChainTest.php | 2 +- .../ImportBundle/Import/ImportCompilerPassTest.php | 2 +- .../ImportBundle/Import/InstapaperImportTest.php | 142 +++++++++---------- .../ImportBundle/Import/PocketImportTest.php | 150 ++++++++++---------- .../ImportBundle/Import/ReadabilityImportTest.php | 114 +++++++-------- .../ImportBundle/Import/WallabagV1ImportTest.php | 156 ++++++++++----------- .../ImportBundle/Import/WallabagV2ImportTest.php | 150 ++++++++++---------- 9 files changed, 472 insertions(+), 472 deletions(-) (limited to 'tests/Wallabag/ImportBundle/Import') diff --git a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php index cec19534..5559ac7e 100644 --- a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php @@ -2,14 +2,14 @@ namespace Tests\Wallabag\ImportBundle\Import; -use Wallabag\ImportBundle\Import\ChromeImport; -use Wallabag\UserBundle\Entity\User; -use Wallabag\CoreBundle\Entity\Entry; -use Wallabag\ImportBundle\Redis\Producer; -use Monolog\Logger; +use M6Web\Component\RedisMock\RedisMockFactory; use Monolog\Handler\TestHandler; +use Monolog\Logger; use Simpleue\Queue\RedisQueue; -use M6Web\Component\RedisMock\RedisMockFactory; +use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\ImportBundle\Import\ChromeImport; +use Wallabag\ImportBundle\Redis\Producer; +use Wallabag\UserBundle\Entity\User; class ChromeImportTest extends \PHPUnit_Framework_TestCase { @@ -19,56 +19,19 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase protected $contentProxy; protected $tagsAssigner; - private function getChromeImport($unsetUser = false, $dispatched = 0) - { - $this->user = new User(); - - $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') - ->disableOriginalConstructor() - ->getMock(); - - $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher - ->expects($this->exactly($dispatched)) - ->method('dispatch'); - - $wallabag = new ChromeImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); - - $this->logHandler = new TestHandler(); - $logger = new Logger('test', [$this->logHandler]); - $wallabag->setLogger($logger); - - if (false === $unsetUser) { - $wallabag->setUser($this->user); - } - - return $wallabag; - } - public function testInit() { $chromeImport = $this->getChromeImport(); - $this->assertEquals('Chrome', $chromeImport->getName()); + $this->assertSame('Chrome', $chromeImport->getName()); $this->assertNotEmpty($chromeImport->getUrl()); - $this->assertEquals('import.chrome.description', $chromeImport->getDescription()); + $this->assertSame('import.chrome.description', $chromeImport->getDescription()); } public function testImport() { $chromeImport = $this->getChromeImport(false, 1); - $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); + $chromeImport->setFilepath(__DIR__ . '/../fixtures/chrome-bookmarks'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -95,13 +58,13 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $res = $chromeImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); } public function testImportAndMarkAllAsRead() { $chromeImport = $this->getChromeImport(false, 1); - $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); + $chromeImport->setFilepath(__DIR__ . '/../fixtures/chrome-bookmarks'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -133,13 +96,13 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); } public function testImportWithRabbit() { $chromeImport = $this->getChromeImport(); - $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); + $chromeImport->setFilepath(__DIR__ . '/../fixtures/chrome-bookmarks'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -173,13 +136,13 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $res = $chromeImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary()); } public function testImportWithRedis() { $chromeImport = $this->getChromeImport(); - $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); + $chromeImport->setFilepath(__DIR__ . '/../fixtures/chrome-bookmarks'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -211,7 +174,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $res = $chromeImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('chrome')); } @@ -219,7 +182,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase public function testImportBadFile() { $chromeImport = $this->getChromeImport(); - $chromeImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); + $chromeImport->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.jsonx'); $res = $chromeImport->import(); @@ -227,13 +190,13 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('Wallabag Browser Import: unable to read file', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); } public function testImportUserNotDefined() { $chromeImport = $this->getChromeImport(true); - $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); + $chromeImport->setFilepath(__DIR__ . '/../fixtures/chrome-bookmarks'); $res = $chromeImport->import(); @@ -241,6 +204,43 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('Wallabag Browser Import: user is not defined', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); + } + + private function getChromeImport($unsetUser = false, $dispatched = 0) + { + $this->user = new User(); + + $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') + ->disableOriginalConstructor() + ->getMock(); + + $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') + ->disableOriginalConstructor() + ->getMock(); + + $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') + ->disableOriginalConstructor() + ->getMock(); + + $dispatcher + ->expects($this->exactly($dispatched)) + ->method('dispatch'); + + $wallabag = new ChromeImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); + + $this->logHandler = new TestHandler(); + $logger = new Logger('test', [$this->logHandler]); + $wallabag->setLogger($logger); + + if (false === $unsetUser) { + $wallabag->setUser($this->user); + } + + return $wallabag; } } diff --git a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php index c186c820..a1783bfc 100644 --- a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php @@ -2,14 +2,14 @@ namespace Tests\Wallabag\ImportBundle\Import; -use Wallabag\ImportBundle\Import\FirefoxImport; -use Wallabag\UserBundle\Entity\User; -use Wallabag\CoreBundle\Entity\Entry; -use Wallabag\ImportBundle\Redis\Producer; -use Monolog\Logger; +use M6Web\Component\RedisMock\RedisMockFactory; use Monolog\Handler\TestHandler; +use Monolog\Logger; use Simpleue\Queue\RedisQueue; -use M6Web\Component\RedisMock\RedisMockFactory; +use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\ImportBundle\Import\FirefoxImport; +use Wallabag\ImportBundle\Redis\Producer; +use Wallabag\UserBundle\Entity\User; class FirefoxImportTest extends \PHPUnit_Framework_TestCase { @@ -19,56 +19,19 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase protected $contentProxy; protected $tagsAssigner; - private function getFirefoxImport($unsetUser = false, $dispatched = 0) - { - $this->user = new User(); - - $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') - ->disableOriginalConstructor() - ->getMock(); - - $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher - ->expects($this->exactly($dispatched)) - ->method('dispatch'); - - $wallabag = new FirefoxImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); - - $this->logHandler = new TestHandler(); - $logger = new Logger('test', [$this->logHandler]); - $wallabag->setLogger($logger); - - if (false === $unsetUser) { - $wallabag->setUser($this->user); - } - - return $wallabag; - } - public function testInit() { $firefoxImport = $this->getFirefoxImport(); - $this->assertEquals('Firefox', $firefoxImport->getName()); + $this->assertSame('Firefox', $firefoxImport->getName()); $this->assertNotEmpty($firefoxImport->getUrl()); - $this->assertEquals('import.firefox.description', $firefoxImport->getDescription()); + $this->assertSame('import.firefox.description', $firefoxImport->getDescription()); } public function testImport() { $firefoxImport = $this->getFirefoxImport(false, 2); - $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); + $firefoxImport->setFilepath(__DIR__ . '/../fixtures/firefox-bookmarks.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -95,13 +58,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $res = $firefoxImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 2, 'queued' => 0], $firefoxImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 2, 'queued' => 0], $firefoxImport->getSummary()); } public function testImportAndMarkAllAsRead() { $firefoxImport = $this->getFirefoxImport(false, 1); - $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); + $firefoxImport->setFilepath(__DIR__ . '/../fixtures/firefox-bookmarks.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -133,13 +96,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); + $this->assertSame(['skipped' => 1, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); } public function testImportWithRabbit() { $firefoxImport = $this->getFirefoxImport(); - $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); + $firefoxImport->setFilepath(__DIR__ . '/../fixtures/firefox-bookmarks.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -173,13 +136,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $res = $firefoxImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary()); } public function testImportWithRedis() { $firefoxImport = $this->getFirefoxImport(); - $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); + $firefoxImport->setFilepath(__DIR__ . '/../fixtures/firefox-bookmarks.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -211,7 +174,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $res = $firefoxImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('firefox')); } @@ -219,7 +182,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase public function testImportBadFile() { $firefoxImport = $this->getFirefoxImport(); - $firefoxImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); + $firefoxImport->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.jsonx'); $res = $firefoxImport->import(); @@ -227,13 +190,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('Wallabag Browser Import: unable to read file', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); } public function testImportUserNotDefined() { $firefoxImport = $this->getFirefoxImport(true); - $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); + $firefoxImport->setFilepath(__DIR__ . '/../fixtures/firefox-bookmarks.json'); $res = $firefoxImport->import(); @@ -241,6 +204,43 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('Wallabag Browser Import: user is not defined', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); + } + + private function getFirefoxImport($unsetUser = false, $dispatched = 0) + { + $this->user = new User(); + + $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') + ->disableOriginalConstructor() + ->getMock(); + + $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') + ->disableOriginalConstructor() + ->getMock(); + + $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') + ->disableOriginalConstructor() + ->getMock(); + + $dispatcher + ->expects($this->exactly($dispatched)) + ->method('dispatch'); + + $wallabag = new FirefoxImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); + + $this->logHandler = new TestHandler(); + $logger = new Logger('test', [$this->logHandler]); + $wallabag->setLogger($logger); + + if (false === $unsetUser) { + $wallabag->setUser($this->user); + } + + return $wallabag; } } diff --git a/tests/Wallabag/ImportBundle/Import/ImportChainTest.php b/tests/Wallabag/ImportBundle/Import/ImportChainTest.php index 32568ce5..a9a9915e 100644 --- a/tests/Wallabag/ImportBundle/Import/ImportChainTest.php +++ b/tests/Wallabag/ImportBundle/Import/ImportChainTest.php @@ -16,6 +16,6 @@ class ImportChainTest extends \PHPUnit_Framework_TestCase $importChain->addImport($import, 'alias'); $this->assertCount(1, $importChain->getAll()); - $this->assertEquals($import, $importChain->getAll()['alias']); + $this->assertSame($import, $importChain->getAll()['alias']); } } diff --git a/tests/Wallabag/ImportBundle/Import/ImportCompilerPassTest.php b/tests/Wallabag/ImportBundle/Import/ImportCompilerPassTest.php index 71a007a9..207054f4 100644 --- a/tests/Wallabag/ImportBundle/Import/ImportCompilerPassTest.php +++ b/tests/Wallabag/ImportBundle/Import/ImportCompilerPassTest.php @@ -36,7 +36,7 @@ class ImportCompilerPassTest extends \PHPUnit_Framework_TestCase $this->assertTrue($definition->hasMethodCall('addImport')); $calls = $definition->getMethodCalls(); - $this->assertEquals('pocket', $calls[0][1][1]); + $this->assertSame('pocket', $calls[0][1][1]); } protected function process(ContainerBuilder $container) diff --git a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php index 9158c8a2..274dc326 100644 --- a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php @@ -2,14 +2,14 @@ namespace Tests\Wallabag\ImportBundle\Import; -use Wallabag\ImportBundle\Import\InstapaperImport; -use Wallabag\UserBundle\Entity\User; -use Wallabag\CoreBundle\Entity\Entry; -use Wallabag\ImportBundle\Redis\Producer; -use Monolog\Logger; +use M6Web\Component\RedisMock\RedisMockFactory; use Monolog\Handler\TestHandler; +use Monolog\Logger; use Simpleue\Queue\RedisQueue; -use M6Web\Component\RedisMock\RedisMockFactory; +use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\ImportBundle\Import\InstapaperImport; +use Wallabag\ImportBundle\Redis\Producer; +use Wallabag\UserBundle\Entity\User; class InstapaperImportTest extends \PHPUnit_Framework_TestCase { @@ -20,70 +20,19 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase protected $tagsAssigner; protected $uow; - private function getInstapaperImport($unsetUser = false, $dispatched = 0) - { - $this->user = new User(); - - $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') - ->disableOriginalConstructor() - ->getMock(); - - $this->em - ->expects($this->any()) - ->method('getUnitOfWork') - ->willReturn($this->uow); - - $this->uow - ->expects($this->any()) - ->method('getScheduledEntityInsertions') - ->willReturn([]); - - $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') - ->disableOriginalConstructor() - ->getMock(); - - $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher - ->expects($this->exactly($dispatched)) - ->method('dispatch'); - - $import = new InstapaperImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); - - $this->logHandler = new TestHandler(); - $logger = new Logger('test', [$this->logHandler]); - $import->setLogger($logger); - - if (false === $unsetUser) { - $import->setUser($this->user); - } - - return $import; - } - public function testInit() { $instapaperImport = $this->getInstapaperImport(); - $this->assertEquals('Instapaper', $instapaperImport->getName()); + $this->assertSame('Instapaper', $instapaperImport->getName()); $this->assertNotEmpty($instapaperImport->getUrl()); - $this->assertEquals('import.instapaper.description', $instapaperImport->getDescription()); + $this->assertSame('import.instapaper.description', $instapaperImport->getDescription()); } public function testImport() { $instapaperImport = $this->getInstapaperImport(false, 4); - $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); + $instapaperImport->setFilepath(__DIR__ . '/../fixtures/instapaper-export.csv'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -110,13 +59,13 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase $res = $instapaperImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $instapaperImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 4, 'queued' => 0], $instapaperImport->getSummary()); } public function testImportAndMarkAllAsRead() { $instapaperImport = $this->getInstapaperImport(false, 1); - $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); + $instapaperImport->setFilepath(__DIR__ . '/../fixtures/instapaper-export.csv'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -148,13 +97,13 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 3, 'imported' => 1, 'queued' => 0], $instapaperImport->getSummary()); + $this->assertSame(['skipped' => 3, 'imported' => 1, 'queued' => 0], $instapaperImport->getSummary()); } public function testImportWithRabbit() { $instapaperImport = $this->getInstapaperImport(); - $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); + $instapaperImport->setFilepath(__DIR__ . '/../fixtures/instapaper-export.csv'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -188,13 +137,13 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase $res = $instapaperImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $instapaperImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 4], $instapaperImport->getSummary()); } public function testImportWithRedis() { $instapaperImport = $this->getInstapaperImport(); - $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); + $instapaperImport->setFilepath(__DIR__ . '/../fixtures/instapaper-export.csv'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -226,7 +175,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase $res = $instapaperImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $instapaperImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 4], $instapaperImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('instapaper')); } @@ -234,7 +183,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase public function testImportBadFile() { $instapaperImport = $this->getInstapaperImport(); - $instapaperImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); + $instapaperImport->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.jsonx'); $res = $instapaperImport->import(); @@ -242,13 +191,13 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('InstapaperImport: unable to read file', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); } public function testImportUserNotDefined() { $instapaperImport = $this->getInstapaperImport(true); - $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); + $instapaperImport->setFilepath(__DIR__ . '/../fixtures/instapaper-export.csv'); $res = $instapaperImport->import(); @@ -256,6 +205,57 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('InstapaperImport: user is not defined', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); + } + + private function getInstapaperImport($unsetUser = false, $dispatched = 0) + { + $this->user = new User(); + + $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') + ->disableOriginalConstructor() + ->getMock(); + + $this->em + ->expects($this->any()) + ->method('getUnitOfWork') + ->willReturn($this->uow); + + $this->uow + ->expects($this->any()) + ->method('getScheduledEntityInsertions') + ->willReturn([]); + + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') + ->disableOriginalConstructor() + ->getMock(); + + $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') + ->disableOriginalConstructor() + ->getMock(); + + $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') + ->disableOriginalConstructor() + ->getMock(); + + $dispatcher + ->expects($this->exactly($dispatched)) + ->method('dispatch'); + + $import = new InstapaperImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); + + $this->logHandler = new TestHandler(); + $logger = new Logger('test', [$this->logHandler]); + $import->setLogger($logger); + + if (false === $unsetUser) { + $import->setUser($this->user); + } + + return $import; } } diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index b81ebe15..fe59f867 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -2,19 +2,19 @@ namespace Tests\Wallabag\ImportBundle\Import; -use Wallabag\UserBundle\Entity\User; -use Wallabag\CoreBundle\Entity\Entry; -use Wallabag\CoreBundle\Entity\Config; -use Wallabag\ImportBundle\Import\PocketImport; use GuzzleHttp\Client; -use GuzzleHttp\Subscriber\Mock; use GuzzleHttp\Message\Response; use GuzzleHttp\Stream\Stream; -use Wallabag\ImportBundle\Redis\Producer; -use Monolog\Logger; +use GuzzleHttp\Subscriber\Mock; +use M6Web\Component\RedisMock\RedisMockFactory; use Monolog\Handler\TestHandler; +use Monolog\Logger; use Simpleue\Queue\RedisQueue; -use M6Web\Component\RedisMock\RedisMockFactory; +use Wallabag\CoreBundle\Entity\Config; +use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\ImportBundle\Import\PocketImport; +use Wallabag\ImportBundle\Redis\Producer; +use Wallabag\UserBundle\Entity\User; class PocketImportTest extends \PHPUnit_Framework_TestCase { @@ -26,66 +26,13 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase protected $tagsAssigner; protected $uow; - private function getPocketImport($consumerKey = 'ConsumerKey', $dispatched = 0) - { - $this->user = new User(); - - $config = new Config($this->user); - $config->setPocketConsumerKey('xxx'); - - $this->user->setConfig($config); - - $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') - ->disableOriginalConstructor() - ->getMock(); - - $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') - ->disableOriginalConstructor() - ->getMock(); - - $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') - ->disableOriginalConstructor() - ->getMock(); - - $this->em - ->expects($this->any()) - ->method('getUnitOfWork') - ->willReturn($this->uow); - - $this->uow - ->expects($this->any()) - ->method('getScheduledEntityInsertions') - ->willReturn([]); - - $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher - ->expects($this->exactly($dispatched)) - ->method('dispatch'); - - $pocket = new PocketImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); - $pocket->setUser($this->user); - - $this->logHandler = new TestHandler(); - $logger = new Logger('test', [$this->logHandler]); - $pocket->setLogger($logger); - - return $pocket; - } - public function testInit() { $pocketImport = $this->getPocketImport(); - $this->assertEquals('Pocket', $pocketImport->getName()); + $this->assertSame('Pocket', $pocketImport->getName()); $this->assertNotEmpty($pocketImport->getUrl()); - $this->assertEquals('import.pocket.description', $pocketImport->getDescription()); + $this->assertSame('import.pocket.description', $pocketImport->getDescription()); } public function testOAuthRequest() @@ -103,7 +50,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase $code = $pocketImport->getRequestToken('http://0.0.0.0/redirect'); - $this->assertEquals('wunderbar_code', $code); + $this->assertSame('wunderbar_code', $code); } public function testOAuthRequestBadResponse() @@ -125,7 +72,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('PocketImport: Failed to request token', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); } public function testOAuthAuthorize() @@ -144,7 +91,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase $res = $pocketImport->authorize('wunderbar_code'); $this->assertTrue($res); - $this->assertEquals('wunderbar_token', $pocketImport->getAccessToken()); + $this->assertSame('wunderbar_token', $pocketImport->getAccessToken()); } public function testOAuthAuthorizeBadResponse() @@ -166,7 +113,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('PocketImport: Failed to authorize client', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); } /** @@ -291,7 +238,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase $res = $pocketImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $pocketImport->getSummary()); + $this->assertSame(['skipped' => 1, 'imported' => 1, 'queued' => 0], $pocketImport->getSummary()); } /** @@ -386,7 +333,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase $res = $pocketImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 2, 'queued' => 0], $pocketImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 2, 'queued' => 0], $pocketImport->getSummary()); } /** @@ -425,7 +372,7 @@ JSON; { "status": 1, "list": { - "229279690": '.$body.' + "229279690": ' . $body . ' } } ')), @@ -472,7 +419,7 @@ JSON; $res = $pocketImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $pocketImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $pocketImport->getSummary()); } /** @@ -511,7 +458,7 @@ JSON; { "status": 1, "list": { - "229279690": '.$body.' + "229279690": ' . $body . ' } } ')), @@ -551,7 +498,7 @@ JSON; $res = $pocketImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $pocketImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $pocketImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('pocket')); } @@ -577,7 +524,7 @@ JSON; $records = $this->logHandler->getRecords(); $this->assertContains('PocketImport: Failed to import', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); } public function testImportWithExceptionFromGraby() @@ -630,6 +577,59 @@ JSON; $res = $pocketImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 1, 'queued' => 0], $pocketImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 1, 'queued' => 0], $pocketImport->getSummary()); + } + + private function getPocketImport($consumerKey = 'ConsumerKey', $dispatched = 0) + { + $this->user = new User(); + + $config = new Config($this->user); + $config->setPocketConsumerKey('xxx'); + + $this->user->setConfig($config); + + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') + ->disableOriginalConstructor() + ->getMock(); + + $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') + ->disableOriginalConstructor() + ->getMock(); + + $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') + ->disableOriginalConstructor() + ->getMock(); + + $this->em + ->expects($this->any()) + ->method('getUnitOfWork') + ->willReturn($this->uow); + + $this->uow + ->expects($this->any()) + ->method('getScheduledEntityInsertions') + ->willReturn([]); + + $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') + ->disableOriginalConstructor() + ->getMock(); + + $dispatcher + ->expects($this->exactly($dispatched)) + ->method('dispatch'); + + $pocket = new PocketImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); + $pocket->setUser($this->user); + + $this->logHandler = new TestHandler(); + $logger = new Logger('test', [$this->logHandler]); + $pocket->setLogger($logger); + + return $pocket; } } diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php index 8f466d38..1822cdaa 100644 --- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php @@ -2,14 +2,14 @@ namespace Tests\Wallabag\ImportBundle\Import; -use Wallabag\ImportBundle\Import\ReadabilityImport; -use Wallabag\UserBundle\Entity\User; -use Wallabag\CoreBundle\Entity\Entry; -use Wallabag\ImportBundle\Redis\Producer; -use Monolog\Logger; +use M6Web\Component\RedisMock\RedisMockFactory; use Monolog\Handler\TestHandler; +use Monolog\Logger; use Simpleue\Queue\RedisQueue; -use M6Web\Component\RedisMock\RedisMockFactory; +use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\ImportBundle\Import\ReadabilityImport; +use Wallabag\ImportBundle\Redis\Producer; +use Wallabag\UserBundle\Entity\User; class ReadabilityImportTest extends \PHPUnit_Framework_TestCase { @@ -19,56 +19,19 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase protected $contentProxy; protected $tagsAssigner; - private function getReadabilityImport($unsetUser = false, $dispatched = 0) - { - $this->user = new User(); - - $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') - ->disableOriginalConstructor() - ->getMock(); - - $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher - ->expects($this->exactly($dispatched)) - ->method('dispatch'); - - $wallabag = new ReadabilityImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); - - $this->logHandler = new TestHandler(); - $logger = new Logger('test', [$this->logHandler]); - $wallabag->setLogger($logger); - - if (false === $unsetUser) { - $wallabag->setUser($this->user); - } - - return $wallabag; - } - public function testInit() { $readabilityImport = $this->getReadabilityImport(); - $this->assertEquals('Readability', $readabilityImport->getName()); + $this->assertSame('Readability', $readabilityImport->getName()); $this->assertNotEmpty($readabilityImport->getUrl()); - $this->assertEquals('import.readability.description', $readabilityImport->getDescription()); + $this->assertSame('import.readability.description', $readabilityImport->getDescription()); } public function testImport() { $readabilityImport = $this->getReadabilityImport(false, 3); - $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + $readabilityImport->setFilepath(__DIR__ . '/../fixtures/readability.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -95,13 +58,13 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $res = $readabilityImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 3, 'queued' => 0], $readabilityImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 3, 'queued' => 0], $readabilityImport->getSummary()); } public function testImportAndMarkAllAsRead() { $readabilityImport = $this->getReadabilityImport(false, 1); - $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability-read.json'); + $readabilityImport->setFilepath(__DIR__ . '/../fixtures/readability-read.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -133,13 +96,13 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $readabilityImport->getSummary()); + $this->assertSame(['skipped' => 1, 'imported' => 1, 'queued' => 0], $readabilityImport->getSummary()); } public function testImportWithRabbit() { $readabilityImport = $this->getReadabilityImport(); - $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + $readabilityImport->setFilepath(__DIR__ . '/../fixtures/readability.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -173,13 +136,13 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $res = $readabilityImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $readabilityImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 3], $readabilityImport->getSummary()); } public function testImportWithRedis() { $readabilityImport = $this->getReadabilityImport(); - $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + $readabilityImport->setFilepath(__DIR__ . '/../fixtures/readability.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -211,7 +174,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $res = $readabilityImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $readabilityImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 3], $readabilityImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('readability')); } @@ -219,7 +182,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase public function testImportBadFile() { $readabilityImport = $this->getReadabilityImport(); - $readabilityImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); + $readabilityImport->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.jsonx'); $res = $readabilityImport->import(); @@ -227,13 +190,13 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('ReadabilityImport: unable to read file', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); } public function testImportUserNotDefined() { $readabilityImport = $this->getReadabilityImport(true); - $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + $readabilityImport->setFilepath(__DIR__ . '/../fixtures/readability.json'); $res = $readabilityImport->import(); @@ -241,6 +204,43 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('ReadabilityImport: user is not defined', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); + } + + private function getReadabilityImport($unsetUser = false, $dispatched = 0) + { + $this->user = new User(); + + $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') + ->disableOriginalConstructor() + ->getMock(); + + $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') + ->disableOriginalConstructor() + ->getMock(); + + $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') + ->disableOriginalConstructor() + ->getMock(); + + $dispatcher + ->expects($this->exactly($dispatched)) + ->method('dispatch'); + + $wallabag = new ReadabilityImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); + + $this->logHandler = new TestHandler(); + $logger = new Logger('test', [$this->logHandler]); + $wallabag->setLogger($logger); + + if (false === $unsetUser) { + $wallabag->setUser($this->user); + } + + return $wallabag; } } diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php index 834b7ef5..822ad694 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php @@ -2,14 +2,14 @@ namespace Tests\Wallabag\ImportBundle\Import; -use Wallabag\ImportBundle\Import\WallabagV1Import; -use Wallabag\UserBundle\Entity\User; -use Wallabag\CoreBundle\Entity\Entry; -use Wallabag\ImportBundle\Redis\Producer; -use Monolog\Logger; +use M6Web\Component\RedisMock\RedisMockFactory; use Monolog\Handler\TestHandler; +use Monolog\Logger; use Simpleue\Queue\RedisQueue; -use M6Web\Component\RedisMock\RedisMockFactory; +use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\ImportBundle\Import\WallabagV1Import; +use Wallabag\ImportBundle\Redis\Producer; +use Wallabag\UserBundle\Entity\User; class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase { @@ -22,77 +22,19 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase protected $fetchingErrorMessageTitle = 'No title found'; protected $fetchingErrorMessage = 'wallabag can\'t retrieve contents for this article. Please troubleshoot this issue.'; - private function getWallabagV1Import($unsetUser = false, $dispatched = 0) - { - $this->user = new User(); - - $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') - ->disableOriginalConstructor() - ->getMock(); - - $this->em - ->expects($this->any()) - ->method('getUnitOfWork') - ->willReturn($this->uow); - - $this->uow - ->expects($this->any()) - ->method('getScheduledEntityInsertions') - ->willReturn([]); - - $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') - ->disableOriginalConstructor() - ->getMock(); - - $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher - ->expects($this->exactly($dispatched)) - ->method('dispatch'); - - $wallabag = new WallabagV1Import( - $this->em, - $this->contentProxy, - $this->tagsAssigner, - $dispatcher, - $this->fetchingErrorMessageTitle, - $this->fetchingErrorMessage - ); - - $this->logHandler = new TestHandler(); - $logger = new Logger('test', [$this->logHandler]); - $wallabag->setLogger($logger); - - if (false === $unsetUser) { - $wallabag->setUser($this->user); - } - - return $wallabag; - } - public function testInit() { $wallabagV1Import = $this->getWallabagV1Import(); - $this->assertEquals('wallabag v1', $wallabagV1Import->getName()); + $this->assertSame('wallabag v1', $wallabagV1Import->getName()); $this->assertNotEmpty($wallabagV1Import->getUrl()); - $this->assertEquals('import.wallabag_v1.description', $wallabagV1Import->getDescription()); + $this->assertSame('import.wallabag_v1.description', $wallabagV1Import->getDescription()); } public function testImport() { $wallabagV1Import = $this->getWallabagV1Import(false, 1); - $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); + $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -119,13 +61,13 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV1Import->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $wallabagV1Import->getSummary()); + $this->assertSame(['skipped' => 1, 'imported' => 1, 'queued' => 0], $wallabagV1Import->getSummary()); } public function testImportAndMarkAllAsRead() { $wallabagV1Import = $this->getWallabagV1Import(false, 3); - $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1-read.json'); + $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v1-read.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -157,13 +99,13 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 3, 'queued' => 0], $wallabagV1Import->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 3, 'queued' => 0], $wallabagV1Import->getSummary()); } public function testImportWithRabbit() { $wallabagV1Import = $this->getWallabagV1Import(); - $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); + $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -197,13 +139,13 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV1Import->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 2], $wallabagV1Import->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 2], $wallabagV1Import->getSummary()); } public function testImportWithRedis() { $wallabagV1Import = $this->getWallabagV1Import(); - $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); + $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -235,7 +177,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV1Import->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 2], $wallabagV1Import->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 2], $wallabagV1Import->getSummary()); $this->assertNotEmpty($redisMock->lpop('wallabag_v1')); } @@ -243,7 +185,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase public function testImportBadFile() { $wallabagV1Import = $this->getWallabagV1Import(); - $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); + $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.jsonx'); $res = $wallabagV1Import->import(); @@ -251,13 +193,13 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('WallabagImport: unable to read file', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); } public function testImportUserNotDefined() { $wallabagV1Import = $this->getWallabagV1Import(true); - $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); + $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.json'); $res = $wallabagV1Import->import(); @@ -265,6 +207,64 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('WallabagImport: user is not defined', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); + } + + private function getWallabagV1Import($unsetUser = false, $dispatched = 0) + { + $this->user = new User(); + + $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') + ->disableOriginalConstructor() + ->getMock(); + + $this->em + ->expects($this->any()) + ->method('getUnitOfWork') + ->willReturn($this->uow); + + $this->uow + ->expects($this->any()) + ->method('getScheduledEntityInsertions') + ->willReturn([]); + + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') + ->disableOriginalConstructor() + ->getMock(); + + $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') + ->disableOriginalConstructor() + ->getMock(); + + $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') + ->disableOriginalConstructor() + ->getMock(); + + $dispatcher + ->expects($this->exactly($dispatched)) + ->method('dispatch'); + + $wallabag = new WallabagV1Import( + $this->em, + $this->contentProxy, + $this->tagsAssigner, + $dispatcher, + $this->fetchingErrorMessageTitle, + $this->fetchingErrorMessage + ); + + $this->logHandler = new TestHandler(); + $logger = new Logger('test', [$this->logHandler]); + $wallabag->setLogger($logger); + + if (false === $unsetUser) { + $wallabag->setUser($this->user); + } + + return $wallabag; } } diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php index 5cc04aa5..fab50a45 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php @@ -2,14 +2,14 @@ namespace Tests\Wallabag\ImportBundle\Import; -use Wallabag\ImportBundle\Import\WallabagV2Import; -use Wallabag\UserBundle\Entity\User; -use Wallabag\CoreBundle\Entity\Entry; -use Wallabag\ImportBundle\Redis\Producer; -use Monolog\Logger; +use M6Web\Component\RedisMock\RedisMockFactory; use Monolog\Handler\TestHandler; +use Monolog\Logger; use Simpleue\Queue\RedisQueue; -use M6Web\Component\RedisMock\RedisMockFactory; +use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\ImportBundle\Import\WallabagV2Import; +use Wallabag\ImportBundle\Redis\Producer; +use Wallabag\UserBundle\Entity\User; class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase { @@ -20,70 +20,19 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase protected $tagsAssigner; protected $uow; - private function getWallabagV2Import($unsetUser = false, $dispatched = 0) - { - $this->user = new User(); - - $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') - ->disableOriginalConstructor() - ->getMock(); - - $this->em - ->expects($this->any()) - ->method('getUnitOfWork') - ->willReturn($this->uow); - - $this->uow - ->expects($this->any()) - ->method('getScheduledEntityInsertions') - ->willReturn([]); - - $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') - ->disableOriginalConstructor() - ->getMock(); - - $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher - ->expects($this->exactly($dispatched)) - ->method('dispatch'); - - $wallabag = new WallabagV2Import($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); - - $this->logHandler = new TestHandler(); - $logger = new Logger('test', [$this->logHandler]); - $wallabag->setLogger($logger); - - if (false === $unsetUser) { - $wallabag->setUser($this->user); - } - - return $wallabag; - } - public function testInit() { $wallabagV2Import = $this->getWallabagV2Import(); - $this->assertEquals('wallabag v2', $wallabagV2Import->getName()); + $this->assertSame('wallabag v2', $wallabagV2Import->getName()); $this->assertNotEmpty($wallabagV2Import->getUrl()); - $this->assertEquals('import.wallabag_v2.description', $wallabagV2Import->getDescription()); + $this->assertSame('import.wallabag_v2.description', $wallabagV2Import->getDescription()); } public function testImport() { $wallabagV2Import = $this->getWallabagV2Import(false, 2); - $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); + $wallabagV2Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -106,13 +55,13 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV2Import->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 4, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); + $this->assertSame(['skipped' => 4, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); } public function testImportAndMarkAllAsRead() { $wallabagV2Import = $this->getWallabagV2Import(false, 2); - $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2-read.json'); + $wallabagV2Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2-read.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -144,13 +93,13 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); } public function testImportWithRabbit() { $wallabagV2Import = $this->getWallabagV2Import(); - $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); + $wallabagV2Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -180,13 +129,13 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV2Import->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 6], $wallabagV2Import->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 6], $wallabagV2Import->getSummary()); } public function testImportWithRedis() { $wallabagV2Import = $this->getWallabagV2Import(); - $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); + $wallabagV2Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -214,7 +163,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV2Import->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 6], $wallabagV2Import->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 6], $wallabagV2Import->getSummary()); $this->assertNotEmpty($redisMock->lpop('wallabag_v2')); } @@ -222,7 +171,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase public function testImportBadFile() { $wallabagV1Import = $this->getWallabagV2Import(); - $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.jsonx'); + $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2.jsonx'); $res = $wallabagV1Import->import(); @@ -230,13 +179,13 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('WallabagImport: unable to read file', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); } public function testImportUserNotDefined() { $wallabagV1Import = $this->getWallabagV2Import(true); - $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); + $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2.json'); $res = $wallabagV1Import->import(); @@ -244,24 +193,24 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('WallabagImport: user is not defined', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); } public function testImportEmptyFile() { $wallabagV2Import = $this->getWallabagV2Import(); - $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2-empty.json'); + $wallabagV2Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2-empty.json'); $res = $wallabagV2Import->import(); $this->assertFalse($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 0], $wallabagV2Import->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 0], $wallabagV2Import->getSummary()); } public function testImportWithExceptionFromGraby() { $wallabagV2Import = $this->getWallabagV2Import(false, 2); - $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); + $wallabagV2Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -284,6 +233,57 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV2Import->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 4, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); + $this->assertSame(['skipped' => 4, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); + } + + private function getWallabagV2Import($unsetUser = false, $dispatched = 0) + { + $this->user = new User(); + + $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') + ->disableOriginalConstructor() + ->getMock(); + + $this->em + ->expects($this->any()) + ->method('getUnitOfWork') + ->willReturn($this->uow); + + $this->uow + ->expects($this->any()) + ->method('getScheduledEntityInsertions') + ->willReturn([]); + + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') + ->disableOriginalConstructor() + ->getMock(); + + $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') + ->disableOriginalConstructor() + ->getMock(); + + $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') + ->disableOriginalConstructor() + ->getMock(); + + $dispatcher + ->expects($this->exactly($dispatched)) + ->method('dispatch'); + + $wallabag = new WallabagV2Import($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); + + $this->logHandler = new TestHandler(); + $logger = new Logger('test', [$this->logHandler]); + $wallabag->setLogger($logger); + + if (false === $unsetUser) { + $wallabag->setUser($this->user); + } + + return $wallabag; } } -- cgit v1.2.3