]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php
Merge pull request #3165 from wallabag/it-translation-update
[github/wallabag/wallabag.git] / tests / Wallabag / ImportBundle / Import / WallabagV2ImportTest.php
index bea89efbde0c6135bdfb8736c8df78030cb334a6..5cc04aa5929385506cc89758e5ea6275245b6ee8 100644 (file)
@@ -17,8 +17,10 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
     protected $em;
     protected $logHandler;
     protected $contentProxy;
+    protected $tagsAssigner;
+    protected $uow;
 
-    private function getWallabagV2Import($unsetUser = false)
+    private function getWallabagV2Import($unsetUser = false, $dispatched = 0)
     {
         $this->user = new User();
 
@@ -44,7 +46,19 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
             ->disableOriginalConstructor()
             ->getMock();
 
-        $wallabag = new WallabagV2Import($this->em, $this->contentProxy);
+        $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]);
@@ -68,14 +82,14 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
 
     public function testImport()
     {
-        $wallabagV2Import = $this->getWallabagV2Import();
+        $wallabagV2Import = $this->getWallabagV2Import(false, 2);
         $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json');
 
         $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
             ->disableOriginalConstructor()
             ->getMock();
 
-        $entryRepo->expects($this->exactly(24))
+        $entryRepo->expects($this->exactly(6))
             ->method('findByUrlAndUserId')
             ->will($this->onConsecutiveCalls(false, true, false));
 
@@ -92,12 +106,12 @@ 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()
     {
-        $wallabagV2Import = $this->getWallabagV2Import();
+        $wallabagV2Import = $this->getWallabagV2Import(false, 2);
         $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2-read.json');
 
         $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@@ -158,7 +172,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
             ->getMock();
 
         $producer
-            ->expects($this->exactly(24))
+            ->expects($this->exactly(6))
             ->method('publish');
 
         $wallabagV2Import->setProducer($producer);
@@ -166,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()
@@ -200,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'));
     }
@@ -246,14 +260,14 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
 
     public function testImportWithExceptionFromGraby()
     {
-        $wallabagV2Import = $this->getWallabagV2Import();
+        $wallabagV2Import = $this->getWallabagV2Import(false, 2);
         $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json');
 
         $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
             ->disableOriginalConstructor()
             ->getMock();
 
-        $entryRepo->expects($this->exactly(24))
+        $entryRepo->expects($this->exactly(6))
             ->method('findByUrlAndUserId')
             ->will($this->onConsecutiveCalls(false, true, false));
 
@@ -270,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());
     }
 }