aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/ImportBundle/Import
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/ImportBundle/Import')
-rw-r--r--tests/Wallabag/ImportBundle/Import/ChromeImportTest.php111
-rw-r--r--tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php111
-rw-r--r--tests/Wallabag/ImportBundle/Import/ImportChainTest.php2
-rw-r--r--tests/Wallabag/ImportBundle/Import/ImportCompilerPassTest.php2
-rw-r--r--tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php138
-rw-r--r--tests/Wallabag/ImportBundle/Import/PocketImportTest.php148
-rw-r--r--tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php119
-rw-r--r--tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php157
-rw-r--r--tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php154
9 files changed, 502 insertions, 440 deletions
diff --git a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php
index 6b3adda4..5559ac7e 100644
--- a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php
@@ -2,14 +2,14 @@
2 2
3namespace Tests\Wallabag\ImportBundle\Import; 3namespace Tests\Wallabag\ImportBundle\Import;
4 4
5use Wallabag\ImportBundle\Import\ChromeImport; 5use M6Web\Component\RedisMock\RedisMockFactory;
6use Wallabag\UserBundle\Entity\User;
7use Wallabag\CoreBundle\Entity\Entry;
8use Wallabag\ImportBundle\Redis\Producer;
9use Monolog\Logger;
10use Monolog\Handler\TestHandler; 6use Monolog\Handler\TestHandler;
7use Monolog\Logger;
11use Simpleue\Queue\RedisQueue; 8use Simpleue\Queue\RedisQueue;
12use M6Web\Component\RedisMock\RedisMockFactory; 9use Wallabag\CoreBundle\Entity\Entry;
10use Wallabag\ImportBundle\Import\ChromeImport;
11use Wallabag\ImportBundle\Redis\Producer;
12use Wallabag\UserBundle\Entity\User;
13 13
14class ChromeImportTest extends \PHPUnit_Framework_TestCase 14class ChromeImportTest extends \PHPUnit_Framework_TestCase
15{ 15{
@@ -17,53 +17,21 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
17 protected $em; 17 protected $em;
18 protected $logHandler; 18 protected $logHandler;
19 protected $contentProxy; 19 protected $contentProxy;
20 20 protected $tagsAssigner;
21 private function getChromeImport($unsetUser = false, $dispatched = 0)
22 {
23 $this->user = new User();
24
25 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
26 ->disableOriginalConstructor()
27 ->getMock();
28
29 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
30 ->disableOriginalConstructor()
31 ->getMock();
32
33 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
34 ->disableOriginalConstructor()
35 ->getMock();
36
37 $dispatcher
38 ->expects($this->exactly($dispatched))
39 ->method('dispatch');
40
41 $wallabag = new ChromeImport($this->em, $this->contentProxy, $dispatcher);
42
43 $this->logHandler = new TestHandler();
44 $logger = new Logger('test', [$this->logHandler]);
45 $wallabag->setLogger($logger);
46
47 if (false === $unsetUser) {
48 $wallabag->setUser($this->user);
49 }
50
51 return $wallabag;
52 }
53 21
54 public function testInit() 22 public function testInit()
55 { 23 {
56 $chromeImport = $this->getChromeImport(); 24 $chromeImport = $this->getChromeImport();
57 25
58 $this->assertEquals('Chrome', $chromeImport->getName()); 26 $this->assertSame('Chrome', $chromeImport->getName());
59 $this->assertNotEmpty($chromeImport->getUrl()); 27 $this->assertNotEmpty($chromeImport->getUrl());
60 $this->assertEquals('import.chrome.description', $chromeImport->getDescription()); 28 $this->assertSame('import.chrome.description', $chromeImport->getDescription());
61 } 29 }
62 30
63 public function testImport() 31 public function testImport()
64 { 32 {
65 $chromeImport = $this->getChromeImport(false, 1); 33 $chromeImport = $this->getChromeImport(false, 1);
66 $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); 34 $chromeImport->setFilepath(__DIR__ . '/../fixtures/chrome-bookmarks');
67 35
68 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 36 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
69 ->disableOriginalConstructor() 37 ->disableOriginalConstructor()
@@ -90,13 +58,13 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
90 $res = $chromeImport->import(); 58 $res = $chromeImport->import();
91 59
92 $this->assertTrue($res); 60 $this->assertTrue($res);
93 $this->assertEquals(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); 61 $this->assertSame(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary());
94 } 62 }
95 63
96 public function testImportAndMarkAllAsRead() 64 public function testImportAndMarkAllAsRead()
97 { 65 {
98 $chromeImport = $this->getChromeImport(false, 1); 66 $chromeImport = $this->getChromeImport(false, 1);
99 $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); 67 $chromeImport->setFilepath(__DIR__ . '/../fixtures/chrome-bookmarks');
100 68
101 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 69 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
102 ->disableOriginalConstructor() 70 ->disableOriginalConstructor()
@@ -128,13 +96,13 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
128 96
129 $this->assertTrue($res); 97 $this->assertTrue($res);
130 98
131 $this->assertEquals(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); 99 $this->assertSame(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary());
132 } 100 }
133 101
134 public function testImportWithRabbit() 102 public function testImportWithRabbit()
135 { 103 {
136 $chromeImport = $this->getChromeImport(); 104 $chromeImport = $this->getChromeImport();
137 $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); 105 $chromeImport->setFilepath(__DIR__ . '/../fixtures/chrome-bookmarks');
138 106
139 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 107 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
140 ->disableOriginalConstructor() 108 ->disableOriginalConstructor()
@@ -168,13 +136,13 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
168 $res = $chromeImport->setMarkAsRead(true)->import(); 136 $res = $chromeImport->setMarkAsRead(true)->import();
169 137
170 $this->assertTrue($res); 138 $this->assertTrue($res);
171 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary()); 139 $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary());
172 } 140 }
173 141
174 public function testImportWithRedis() 142 public function testImportWithRedis()
175 { 143 {
176 $chromeImport = $this->getChromeImport(); 144 $chromeImport = $this->getChromeImport();
177 $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); 145 $chromeImport->setFilepath(__DIR__ . '/../fixtures/chrome-bookmarks');
178 146
179 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 147 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
180 ->disableOriginalConstructor() 148 ->disableOriginalConstructor()
@@ -206,7 +174,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
206 $res = $chromeImport->setMarkAsRead(true)->import(); 174 $res = $chromeImport->setMarkAsRead(true)->import();
207 175
208 $this->assertTrue($res); 176 $this->assertTrue($res);
209 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary()); 177 $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary());
210 178
211 $this->assertNotEmpty($redisMock->lpop('chrome')); 179 $this->assertNotEmpty($redisMock->lpop('chrome'));
212 } 180 }
@@ -214,7 +182,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
214 public function testImportBadFile() 182 public function testImportBadFile()
215 { 183 {
216 $chromeImport = $this->getChromeImport(); 184 $chromeImport = $this->getChromeImport();
217 $chromeImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); 185 $chromeImport->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.jsonx');
218 186
219 $res = $chromeImport->import(); 187 $res = $chromeImport->import();
220 188
@@ -222,13 +190,13 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
222 190
223 $records = $this->logHandler->getRecords(); 191 $records = $this->logHandler->getRecords();
224 $this->assertContains('Wallabag Browser Import: unable to read file', $records[0]['message']); 192 $this->assertContains('Wallabag Browser Import: unable to read file', $records[0]['message']);
225 $this->assertEquals('ERROR', $records[0]['level_name']); 193 $this->assertSame('ERROR', $records[0]['level_name']);
226 } 194 }
227 195
228 public function testImportUserNotDefined() 196 public function testImportUserNotDefined()
229 { 197 {
230 $chromeImport = $this->getChromeImport(true); 198 $chromeImport = $this->getChromeImport(true);
231 $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); 199 $chromeImport->setFilepath(__DIR__ . '/../fixtures/chrome-bookmarks');
232 200
233 $res = $chromeImport->import(); 201 $res = $chromeImport->import();
234 202
@@ -236,6 +204,43 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
236 204
237 $records = $this->logHandler->getRecords(); 205 $records = $this->logHandler->getRecords();
238 $this->assertContains('Wallabag Browser Import: user is not defined', $records[0]['message']); 206 $this->assertContains('Wallabag Browser Import: user is not defined', $records[0]['message']);
239 $this->assertEquals('ERROR', $records[0]['level_name']); 207 $this->assertSame('ERROR', $records[0]['level_name']);
208 }
209
210 private function getChromeImport($unsetUser = false, $dispatched = 0)
211 {
212 $this->user = new User();
213
214 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
215 ->disableOriginalConstructor()
216 ->getMock();
217
218 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
219 ->disableOriginalConstructor()
220 ->getMock();
221
222 $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner')
223 ->disableOriginalConstructor()
224 ->getMock();
225
226 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
227 ->disableOriginalConstructor()
228 ->getMock();
229
230 $dispatcher
231 ->expects($this->exactly($dispatched))
232 ->method('dispatch');
233
234 $wallabag = new ChromeImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher);
235
236 $this->logHandler = new TestHandler();
237 $logger = new Logger('test', [$this->logHandler]);
238 $wallabag->setLogger($logger);
239
240 if (false === $unsetUser) {
241 $wallabag->setUser($this->user);
242 }
243
244 return $wallabag;
240 } 245 }
241} 246}
diff --git a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php
index b516fbc5..a1783bfc 100644
--- a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php
@@ -2,14 +2,14 @@
2 2
3namespace Tests\Wallabag\ImportBundle\Import; 3namespace Tests\Wallabag\ImportBundle\Import;
4 4
5use Wallabag\ImportBundle\Import\FirefoxImport; 5use M6Web\Component\RedisMock\RedisMockFactory;
6use Wallabag\UserBundle\Entity\User;
7use Wallabag\CoreBundle\Entity\Entry;
8use Wallabag\ImportBundle\Redis\Producer;
9use Monolog\Logger;
10use Monolog\Handler\TestHandler; 6use Monolog\Handler\TestHandler;
7use Monolog\Logger;
11use Simpleue\Queue\RedisQueue; 8use Simpleue\Queue\RedisQueue;
12use M6Web\Component\RedisMock\RedisMockFactory; 9use Wallabag\CoreBundle\Entity\Entry;
10use Wallabag\ImportBundle\Import\FirefoxImport;
11use Wallabag\ImportBundle\Redis\Producer;
12use Wallabag\UserBundle\Entity\User;
13 13
14class FirefoxImportTest extends \PHPUnit_Framework_TestCase 14class FirefoxImportTest extends \PHPUnit_Framework_TestCase
15{ 15{
@@ -17,53 +17,21 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
17 protected $em; 17 protected $em;
18 protected $logHandler; 18 protected $logHandler;
19 protected $contentProxy; 19 protected $contentProxy;
20 20 protected $tagsAssigner;
21 private function getFirefoxImport($unsetUser = false, $dispatched = 0)
22 {
23 $this->user = new User();
24
25 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
26 ->disableOriginalConstructor()
27 ->getMock();
28
29 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
30 ->disableOriginalConstructor()
31 ->getMock();
32
33 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
34 ->disableOriginalConstructor()
35 ->getMock();
36
37 $dispatcher
38 ->expects($this->exactly($dispatched))
39 ->method('dispatch');
40
41 $wallabag = new FirefoxImport($this->em, $this->contentProxy, $dispatcher);
42
43 $this->logHandler = new TestHandler();
44 $logger = new Logger('test', [$this->logHandler]);
45 $wallabag->setLogger($logger);
46
47 if (false === $unsetUser) {
48 $wallabag->setUser($this->user);
49 }
50
51 return $wallabag;
52 }
53 21
54 public function testInit() 22 public function testInit()
55 { 23 {
56 $firefoxImport = $this->getFirefoxImport(); 24 $firefoxImport = $this->getFirefoxImport();
57 25
58 $this->assertEquals('Firefox', $firefoxImport->getName()); 26 $this->assertSame('Firefox', $firefoxImport->getName());
59 $this->assertNotEmpty($firefoxImport->getUrl()); 27 $this->assertNotEmpty($firefoxImport->getUrl());
60 $this->assertEquals('import.firefox.description', $firefoxImport->getDescription()); 28 $this->assertSame('import.firefox.description', $firefoxImport->getDescription());
61 } 29 }
62 30
63 public function testImport() 31 public function testImport()
64 { 32 {
65 $firefoxImport = $this->getFirefoxImport(false, 2); 33 $firefoxImport = $this->getFirefoxImport(false, 2);
66 $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); 34 $firefoxImport->setFilepath(__DIR__ . '/../fixtures/firefox-bookmarks.json');
67 35
68 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 36 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
69 ->disableOriginalConstructor() 37 ->disableOriginalConstructor()
@@ -90,13 +58,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
90 $res = $firefoxImport->import(); 58 $res = $firefoxImport->import();
91 59
92 $this->assertTrue($res); 60 $this->assertTrue($res);
93 $this->assertEquals(['skipped' => 0, 'imported' => 2, 'queued' => 0], $firefoxImport->getSummary()); 61 $this->assertSame(['skipped' => 0, 'imported' => 2, 'queued' => 0], $firefoxImport->getSummary());
94 } 62 }
95 63
96 public function testImportAndMarkAllAsRead() 64 public function testImportAndMarkAllAsRead()
97 { 65 {
98 $firefoxImport = $this->getFirefoxImport(false, 1); 66 $firefoxImport = $this->getFirefoxImport(false, 1);
99 $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); 67 $firefoxImport->setFilepath(__DIR__ . '/../fixtures/firefox-bookmarks.json');
100 68
101 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 69 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
102 ->disableOriginalConstructor() 70 ->disableOriginalConstructor()
@@ -128,13 +96,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
128 96
129 $this->assertTrue($res); 97 $this->assertTrue($res);
130 98
131 $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); 99 $this->assertSame(['skipped' => 1, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary());
132 } 100 }
133 101
134 public function testImportWithRabbit() 102 public function testImportWithRabbit()
135 { 103 {
136 $firefoxImport = $this->getFirefoxImport(); 104 $firefoxImport = $this->getFirefoxImport();
137 $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); 105 $firefoxImport->setFilepath(__DIR__ . '/../fixtures/firefox-bookmarks.json');
138 106
139 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 107 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
140 ->disableOriginalConstructor() 108 ->disableOriginalConstructor()
@@ -168,13 +136,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
168 $res = $firefoxImport->setMarkAsRead(true)->import(); 136 $res = $firefoxImport->setMarkAsRead(true)->import();
169 137
170 $this->assertTrue($res); 138 $this->assertTrue($res);
171 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary()); 139 $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary());
172 } 140 }
173 141
174 public function testImportWithRedis() 142 public function testImportWithRedis()
175 { 143 {
176 $firefoxImport = $this->getFirefoxImport(); 144 $firefoxImport = $this->getFirefoxImport();
177 $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); 145 $firefoxImport->setFilepath(__DIR__ . '/../fixtures/firefox-bookmarks.json');
178 146
179 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 147 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
180 ->disableOriginalConstructor() 148 ->disableOriginalConstructor()
@@ -206,7 +174,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
206 $res = $firefoxImport->setMarkAsRead(true)->import(); 174 $res = $firefoxImport->setMarkAsRead(true)->import();
207 175
208 $this->assertTrue($res); 176 $this->assertTrue($res);
209 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary()); 177 $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary());
210 178
211 $this->assertNotEmpty($redisMock->lpop('firefox')); 179 $this->assertNotEmpty($redisMock->lpop('firefox'));
212 } 180 }
@@ -214,7 +182,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
214 public function testImportBadFile() 182 public function testImportBadFile()
215 { 183 {
216 $firefoxImport = $this->getFirefoxImport(); 184 $firefoxImport = $this->getFirefoxImport();
217 $firefoxImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); 185 $firefoxImport->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.jsonx');
218 186
219 $res = $firefoxImport->import(); 187 $res = $firefoxImport->import();
220 188
@@ -222,13 +190,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
222 190
223 $records = $this->logHandler->getRecords(); 191 $records = $this->logHandler->getRecords();
224 $this->assertContains('Wallabag Browser Import: unable to read file', $records[0]['message']); 192 $this->assertContains('Wallabag Browser Import: unable to read file', $records[0]['message']);
225 $this->assertEquals('ERROR', $records[0]['level_name']); 193 $this->assertSame('ERROR', $records[0]['level_name']);
226 } 194 }
227 195
228 public function testImportUserNotDefined() 196 public function testImportUserNotDefined()
229 { 197 {
230 $firefoxImport = $this->getFirefoxImport(true); 198 $firefoxImport = $this->getFirefoxImport(true);
231 $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); 199 $firefoxImport->setFilepath(__DIR__ . '/../fixtures/firefox-bookmarks.json');
232 200
233 $res = $firefoxImport->import(); 201 $res = $firefoxImport->import();
234 202
@@ -236,6 +204,43 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
236 204
237 $records = $this->logHandler->getRecords(); 205 $records = $this->logHandler->getRecords();
238 $this->assertContains('Wallabag Browser Import: user is not defined', $records[0]['message']); 206 $this->assertContains('Wallabag Browser Import: user is not defined', $records[0]['message']);
239 $this->assertEquals('ERROR', $records[0]['level_name']); 207 $this->assertSame('ERROR', $records[0]['level_name']);
208 }
209
210 private function getFirefoxImport($unsetUser = false, $dispatched = 0)
211 {
212 $this->user = new User();
213
214 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
215 ->disableOriginalConstructor()
216 ->getMock();
217
218 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
219 ->disableOriginalConstructor()
220 ->getMock();
221
222 $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner')
223 ->disableOriginalConstructor()
224 ->getMock();
225
226 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
227 ->disableOriginalConstructor()
228 ->getMock();
229
230 $dispatcher
231 ->expects($this->exactly($dispatched))
232 ->method('dispatch');
233
234 $wallabag = new FirefoxImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher);
235
236 $this->logHandler = new TestHandler();
237 $logger = new Logger('test', [$this->logHandler]);
238 $wallabag->setLogger($logger);
239
240 if (false === $unsetUser) {
241 $wallabag->setUser($this->user);
242 }
243
244 return $wallabag;
240 } 245 }
241} 246}
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
16 $importChain->addImport($import, 'alias'); 16 $importChain->addImport($import, 'alias');
17 17
18 $this->assertCount(1, $importChain->getAll()); 18 $this->assertCount(1, $importChain->getAll());
19 $this->assertEquals($import, $importChain->getAll()['alias']); 19 $this->assertSame($import, $importChain->getAll()['alias']);
20 } 20 }
21} 21}
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
36 $this->assertTrue($definition->hasMethodCall('addImport')); 36 $this->assertTrue($definition->hasMethodCall('addImport'));
37 37
38 $calls = $definition->getMethodCalls(); 38 $calls = $definition->getMethodCalls();
39 $this->assertEquals('pocket', $calls[0][1][1]); 39 $this->assertSame('pocket', $calls[0][1][1]);
40 } 40 }
41 41
42 protected function process(ContainerBuilder $container) 42 protected function process(ContainerBuilder $container)
diff --git a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php
index e262a808..274dc326 100644
--- a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php
@@ -2,14 +2,14 @@
2 2
3namespace Tests\Wallabag\ImportBundle\Import; 3namespace Tests\Wallabag\ImportBundle\Import;
4 4
5use Wallabag\ImportBundle\Import\InstapaperImport; 5use M6Web\Component\RedisMock\RedisMockFactory;
6use Wallabag\UserBundle\Entity\User;
7use Wallabag\CoreBundle\Entity\Entry;
8use Wallabag\ImportBundle\Redis\Producer;
9use Monolog\Logger;
10use Monolog\Handler\TestHandler; 6use Monolog\Handler\TestHandler;
7use Monolog\Logger;
11use Simpleue\Queue\RedisQueue; 8use Simpleue\Queue\RedisQueue;
12use M6Web\Component\RedisMock\RedisMockFactory; 9use Wallabag\CoreBundle\Entity\Entry;
10use Wallabag\ImportBundle\Import\InstapaperImport;
11use Wallabag\ImportBundle\Redis\Producer;
12use Wallabag\UserBundle\Entity\User;
13 13
14class InstapaperImportTest extends \PHPUnit_Framework_TestCase 14class InstapaperImportTest extends \PHPUnit_Framework_TestCase
15{ 15{
@@ -17,59 +17,28 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
17 protected $em; 17 protected $em;
18 protected $logHandler; 18 protected $logHandler;
19 protected $contentProxy; 19 protected $contentProxy;
20 20 protected $tagsAssigner;
21 private function getInstapaperImport($unsetUser = false, $dispatched = 0) 21 protected $uow;
22 {
23 $this->user = new User();
24
25 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
26 ->disableOriginalConstructor()
27 ->getMock();
28
29 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
30 ->disableOriginalConstructor()
31 ->getMock();
32
33 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
34 ->disableOriginalConstructor()
35 ->getMock();
36
37 $dispatcher
38 ->expects($this->exactly($dispatched))
39 ->method('dispatch');
40
41 $import = new InstapaperImport($this->em, $this->contentProxy, $dispatcher);
42
43 $this->logHandler = new TestHandler();
44 $logger = new Logger('test', [$this->logHandler]);
45 $import->setLogger($logger);
46
47 if (false === $unsetUser) {
48 $import->setUser($this->user);
49 }
50
51 return $import;
52 }
53 22
54 public function testInit() 23 public function testInit()
55 { 24 {
56 $instapaperImport = $this->getInstapaperImport(); 25 $instapaperImport = $this->getInstapaperImport();
57 26
58 $this->assertEquals('Instapaper', $instapaperImport->getName()); 27 $this->assertSame('Instapaper', $instapaperImport->getName());
59 $this->assertNotEmpty($instapaperImport->getUrl()); 28 $this->assertNotEmpty($instapaperImport->getUrl());
60 $this->assertEquals('import.instapaper.description', $instapaperImport->getDescription()); 29 $this->assertSame('import.instapaper.description', $instapaperImport->getDescription());
61 } 30 }
62 31
63 public function testImport() 32 public function testImport()
64 { 33 {
65 $instapaperImport = $this->getInstapaperImport(false, 3); 34 $instapaperImport = $this->getInstapaperImport(false, 4);
66 $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); 35 $instapaperImport->setFilepath(__DIR__ . '/../fixtures/instapaper-export.csv');
67 36
68 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 37 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
69 ->disableOriginalConstructor() 38 ->disableOriginalConstructor()
70 ->getMock(); 39 ->getMock();
71 40
72 $entryRepo->expects($this->exactly(3)) 41 $entryRepo->expects($this->exactly(4))
73 ->method('findByUrlAndUserId') 42 ->method('findByUrlAndUserId')
74 ->willReturn(false); 43 ->willReturn(false);
75 44
@@ -83,28 +52,28 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
83 ->getMock(); 52 ->getMock();
84 53
85 $this->contentProxy 54 $this->contentProxy
86 ->expects($this->exactly(3)) 55 ->expects($this->exactly(4))
87 ->method('updateEntry') 56 ->method('updateEntry')
88 ->willReturn($entry); 57 ->willReturn($entry);
89 58
90 $res = $instapaperImport->import(); 59 $res = $instapaperImport->import();
91 60
92 $this->assertTrue($res); 61 $this->assertTrue($res);
93 $this->assertEquals(['skipped' => 0, 'imported' => 3, 'queued' => 0], $instapaperImport->getSummary()); 62 $this->assertSame(['skipped' => 0, 'imported' => 4, 'queued' => 0], $instapaperImport->getSummary());
94 } 63 }
95 64
96 public function testImportAndMarkAllAsRead() 65 public function testImportAndMarkAllAsRead()
97 { 66 {
98 $instapaperImport = $this->getInstapaperImport(false, 1); 67 $instapaperImport = $this->getInstapaperImport(false, 1);
99 $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); 68 $instapaperImport->setFilepath(__DIR__ . '/../fixtures/instapaper-export.csv');
100 69
101 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 70 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
102 ->disableOriginalConstructor() 71 ->disableOriginalConstructor()
103 ->getMock(); 72 ->getMock();
104 73
105 $entryRepo->expects($this->exactly(3)) 74 $entryRepo->expects($this->exactly(4))
106 ->method('findByUrlAndUserId') 75 ->method('findByUrlAndUserId')
107 ->will($this->onConsecutiveCalls(false, true, true)); 76 ->will($this->onConsecutiveCalls(false, true, true, true));
108 77
109 $this->em 78 $this->em
110 ->expects($this->any()) 79 ->expects($this->any())
@@ -128,13 +97,13 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
128 97
129 $this->assertTrue($res); 98 $this->assertTrue($res);
130 99
131 $this->assertEquals(['skipped' => 2, 'imported' => 1, 'queued' => 0], $instapaperImport->getSummary()); 100 $this->assertSame(['skipped' => 3, 'imported' => 1, 'queued' => 0], $instapaperImport->getSummary());
132 } 101 }
133 102
134 public function testImportWithRabbit() 103 public function testImportWithRabbit()
135 { 104 {
136 $instapaperImport = $this->getInstapaperImport(); 105 $instapaperImport = $this->getInstapaperImport();
137 $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); 106 $instapaperImport->setFilepath(__DIR__ . '/../fixtures/instapaper-export.csv');
138 107
139 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 108 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
140 ->disableOriginalConstructor() 109 ->disableOriginalConstructor()
@@ -160,7 +129,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
160 ->getMock(); 129 ->getMock();
161 130
162 $producer 131 $producer
163 ->expects($this->exactly(3)) 132 ->expects($this->exactly(4))
164 ->method('publish'); 133 ->method('publish');
165 134
166 $instapaperImport->setProducer($producer); 135 $instapaperImport->setProducer($producer);
@@ -168,13 +137,13 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
168 $res = $instapaperImport->setMarkAsRead(true)->import(); 137 $res = $instapaperImport->setMarkAsRead(true)->import();
169 138
170 $this->assertTrue($res); 139 $this->assertTrue($res);
171 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $instapaperImport->getSummary()); 140 $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 4], $instapaperImport->getSummary());
172 } 141 }
173 142
174 public function testImportWithRedis() 143 public function testImportWithRedis()
175 { 144 {
176 $instapaperImport = $this->getInstapaperImport(); 145 $instapaperImport = $this->getInstapaperImport();
177 $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); 146 $instapaperImport->setFilepath(__DIR__ . '/../fixtures/instapaper-export.csv');
178 147
179 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 148 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
180 ->disableOriginalConstructor() 149 ->disableOriginalConstructor()
@@ -206,7 +175,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
206 $res = $instapaperImport->setMarkAsRead(true)->import(); 175 $res = $instapaperImport->setMarkAsRead(true)->import();
207 176
208 $this->assertTrue($res); 177 $this->assertTrue($res);
209 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $instapaperImport->getSummary()); 178 $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 4], $instapaperImport->getSummary());
210 179
211 $this->assertNotEmpty($redisMock->lpop('instapaper')); 180 $this->assertNotEmpty($redisMock->lpop('instapaper'));
212 } 181 }
@@ -214,7 +183,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
214 public function testImportBadFile() 183 public function testImportBadFile()
215 { 184 {
216 $instapaperImport = $this->getInstapaperImport(); 185 $instapaperImport = $this->getInstapaperImport();
217 $instapaperImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); 186 $instapaperImport->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.jsonx');
218 187
219 $res = $instapaperImport->import(); 188 $res = $instapaperImport->import();
220 189
@@ -222,13 +191,13 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
222 191
223 $records = $this->logHandler->getRecords(); 192 $records = $this->logHandler->getRecords();
224 $this->assertContains('InstapaperImport: unable to read file', $records[0]['message']); 193 $this->assertContains('InstapaperImport: unable to read file', $records[0]['message']);
225 $this->assertEquals('ERROR', $records[0]['level_name']); 194 $this->assertSame('ERROR', $records[0]['level_name']);
226 } 195 }
227 196
228 public function testImportUserNotDefined() 197 public function testImportUserNotDefined()
229 { 198 {
230 $instapaperImport = $this->getInstapaperImport(true); 199 $instapaperImport = $this->getInstapaperImport(true);
231 $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); 200 $instapaperImport->setFilepath(__DIR__ . '/../fixtures/instapaper-export.csv');
232 201
233 $res = $instapaperImport->import(); 202 $res = $instapaperImport->import();
234 203
@@ -236,6 +205,57 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
236 205
237 $records = $this->logHandler->getRecords(); 206 $records = $this->logHandler->getRecords();
238 $this->assertContains('InstapaperImport: user is not defined', $records[0]['message']); 207 $this->assertContains('InstapaperImport: user is not defined', $records[0]['message']);
239 $this->assertEquals('ERROR', $records[0]['level_name']); 208 $this->assertSame('ERROR', $records[0]['level_name']);
209 }
210
211 private function getInstapaperImport($unsetUser = false, $dispatched = 0)
212 {
213 $this->user = new User();
214
215 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
216 ->disableOriginalConstructor()
217 ->getMock();
218
219 $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork')
220 ->disableOriginalConstructor()
221 ->getMock();
222
223 $this->em
224 ->expects($this->any())
225 ->method('getUnitOfWork')
226 ->willReturn($this->uow);
227
228 $this->uow
229 ->expects($this->any())
230 ->method('getScheduledEntityInsertions')
231 ->willReturn([]);
232
233 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
234 ->disableOriginalConstructor()
235 ->getMock();
236
237 $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner')
238 ->disableOriginalConstructor()
239 ->getMock();
240
241 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
242 ->disableOriginalConstructor()
243 ->getMock();
244
245 $dispatcher
246 ->expects($this->exactly($dispatched))
247 ->method('dispatch');
248
249 $import = new InstapaperImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher);
250
251 $this->logHandler = new TestHandler();
252 $logger = new Logger('test', [$this->logHandler]);
253 $import->setLogger($logger);
254
255 if (false === $unsetUser) {
256 $import->setUser($this->user);
257 }
258
259 return $import;
240 } 260 }
241} 261}
diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php
index 141ece36..fe59f867 100644
--- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php
@@ -2,19 +2,19 @@
2 2
3namespace Tests\Wallabag\ImportBundle\Import; 3namespace Tests\Wallabag\ImportBundle\Import;
4 4
5use Wallabag\UserBundle\Entity\User;
6use Wallabag\CoreBundle\Entity\Entry;
7use Wallabag\CoreBundle\Entity\Config;
8use Wallabag\ImportBundle\Import\PocketImport;
9use GuzzleHttp\Client; 5use GuzzleHttp\Client;
10use GuzzleHttp\Subscriber\Mock;
11use GuzzleHttp\Message\Response; 6use GuzzleHttp\Message\Response;
12use GuzzleHttp\Stream\Stream; 7use GuzzleHttp\Stream\Stream;
13use Wallabag\ImportBundle\Redis\Producer; 8use GuzzleHttp\Subscriber\Mock;
14use Monolog\Logger; 9use M6Web\Component\RedisMock\RedisMockFactory;
15use Monolog\Handler\TestHandler; 10use Monolog\Handler\TestHandler;
11use Monolog\Logger;
16use Simpleue\Queue\RedisQueue; 12use Simpleue\Queue\RedisQueue;
17use M6Web\Component\RedisMock\RedisMockFactory; 13use Wallabag\CoreBundle\Entity\Config;
14use Wallabag\CoreBundle\Entity\Entry;
15use Wallabag\ImportBundle\Import\PocketImport;
16use Wallabag\ImportBundle\Redis\Producer;
17use Wallabag\UserBundle\Entity\User;
18 18
19class PocketImportTest extends \PHPUnit_Framework_TestCase 19class PocketImportTest extends \PHPUnit_Framework_TestCase
20{ 20{
@@ -23,63 +23,16 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
23 protected $em; 23 protected $em;
24 protected $contentProxy; 24 protected $contentProxy;
25 protected $logHandler; 25 protected $logHandler;
26 26 protected $tagsAssigner;
27 private function getPocketImport($consumerKey = 'ConsumerKey', $dispatched = 0) 27 protected $uow;
28 {
29 $this->user = new User();
30
31 $config = new Config($this->user);
32 $config->setPocketConsumerKey('xxx');
33
34 $this->user->setConfig($config);
35
36 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
37 ->disableOriginalConstructor()
38 ->getMock();
39
40 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
41 ->disableOriginalConstructor()
42 ->getMock();
43
44 $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork')
45 ->disableOriginalConstructor()
46 ->getMock();
47
48 $this->em
49 ->expects($this->any())
50 ->method('getUnitOfWork')
51 ->willReturn($this->uow);
52
53 $this->uow
54 ->expects($this->any())
55 ->method('getScheduledEntityInsertions')
56 ->willReturn([]);
57
58 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
59 ->disableOriginalConstructor()
60 ->getMock();
61
62 $dispatcher
63 ->expects($this->exactly($dispatched))
64 ->method('dispatch');
65
66 $pocket = new PocketImport($this->em, $this->contentProxy, $dispatcher);
67 $pocket->setUser($this->user);
68
69 $this->logHandler = new TestHandler();
70 $logger = new Logger('test', [$this->logHandler]);
71 $pocket->setLogger($logger);
72
73 return $pocket;
74 }
75 28
76 public function testInit() 29 public function testInit()
77 { 30 {
78 $pocketImport = $this->getPocketImport(); 31 $pocketImport = $this->getPocketImport();
79 32
80 $this->assertEquals('Pocket', $pocketImport->getName()); 33 $this->assertSame('Pocket', $pocketImport->getName());
81 $this->assertNotEmpty($pocketImport->getUrl()); 34 $this->assertNotEmpty($pocketImport->getUrl());
82 $this->assertEquals('import.pocket.description', $pocketImport->getDescription()); 35 $this->assertSame('import.pocket.description', $pocketImport->getDescription());
83 } 36 }
84 37
85 public function testOAuthRequest() 38 public function testOAuthRequest()
@@ -97,7 +50,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
97 50
98 $code = $pocketImport->getRequestToken('http://0.0.0.0/redirect'); 51 $code = $pocketImport->getRequestToken('http://0.0.0.0/redirect');
99 52
100 $this->assertEquals('wunderbar_code', $code); 53 $this->assertSame('wunderbar_code', $code);
101 } 54 }
102 55
103 public function testOAuthRequestBadResponse() 56 public function testOAuthRequestBadResponse()
@@ -119,7 +72,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
119 72
120 $records = $this->logHandler->getRecords(); 73 $records = $this->logHandler->getRecords();
121 $this->assertContains('PocketImport: Failed to request token', $records[0]['message']); 74 $this->assertContains('PocketImport: Failed to request token', $records[0]['message']);
122 $this->assertEquals('ERROR', $records[0]['level_name']); 75 $this->assertSame('ERROR', $records[0]['level_name']);
123 } 76 }
124 77
125 public function testOAuthAuthorize() 78 public function testOAuthAuthorize()
@@ -138,7 +91,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
138 $res = $pocketImport->authorize('wunderbar_code'); 91 $res = $pocketImport->authorize('wunderbar_code');
139 92
140 $this->assertTrue($res); 93 $this->assertTrue($res);
141 $this->assertEquals('wunderbar_token', $pocketImport->getAccessToken()); 94 $this->assertSame('wunderbar_token', $pocketImport->getAccessToken());
142 } 95 }
143 96
144 public function testOAuthAuthorizeBadResponse() 97 public function testOAuthAuthorizeBadResponse()
@@ -160,7 +113,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
160 113
161 $records = $this->logHandler->getRecords(); 114 $records = $this->logHandler->getRecords();
162 $this->assertContains('PocketImport: Failed to authorize client', $records[0]['message']); 115 $this->assertContains('PocketImport: Failed to authorize client', $records[0]['message']);
163 $this->assertEquals('ERROR', $records[0]['level_name']); 116 $this->assertSame('ERROR', $records[0]['level_name']);
164 } 117 }
165 118
166 /** 119 /**
@@ -285,7 +238,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
285 $res = $pocketImport->import(); 238 $res = $pocketImport->import();
286 239
287 $this->assertTrue($res); 240 $this->assertTrue($res);
288 $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $pocketImport->getSummary()); 241 $this->assertSame(['skipped' => 1, 'imported' => 1, 'queued' => 0], $pocketImport->getSummary());
289 } 242 }
290 243
291 /** 244 /**
@@ -380,7 +333,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
380 $res = $pocketImport->setMarkAsRead(true)->import(); 333 $res = $pocketImport->setMarkAsRead(true)->import();
381 334
382 $this->assertTrue($res); 335 $this->assertTrue($res);
383 $this->assertEquals(['skipped' => 0, 'imported' => 2, 'queued' => 0], $pocketImport->getSummary()); 336 $this->assertSame(['skipped' => 0, 'imported' => 2, 'queued' => 0], $pocketImport->getSummary());
384 } 337 }
385 338
386 /** 339 /**
@@ -419,7 +372,7 @@ JSON;
419 { 372 {
420 "status": 1, 373 "status": 1,
421 "list": { 374 "list": {
422 "229279690": '.$body.' 375 "229279690": ' . $body . '
423 } 376 }
424 } 377 }
425 ')), 378 ')),
@@ -466,7 +419,7 @@ JSON;
466 $res = $pocketImport->setMarkAsRead(true)->import(); 419 $res = $pocketImport->setMarkAsRead(true)->import();
467 420
468 $this->assertTrue($res); 421 $this->assertTrue($res);
469 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $pocketImport->getSummary()); 422 $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $pocketImport->getSummary());
470 } 423 }
471 424
472 /** 425 /**
@@ -505,7 +458,7 @@ JSON;
505 { 458 {
506 "status": 1, 459 "status": 1,
507 "list": { 460 "list": {
508 "229279690": '.$body.' 461 "229279690": ' . $body . '
509 } 462 }
510 } 463 }
511 ')), 464 ')),
@@ -545,7 +498,7 @@ JSON;
545 $res = $pocketImport->setMarkAsRead(true)->import(); 498 $res = $pocketImport->setMarkAsRead(true)->import();
546 499
547 $this->assertTrue($res); 500 $this->assertTrue($res);
548 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $pocketImport->getSummary()); 501 $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $pocketImport->getSummary());
549 502
550 $this->assertNotEmpty($redisMock->lpop('pocket')); 503 $this->assertNotEmpty($redisMock->lpop('pocket'));
551 } 504 }
@@ -571,7 +524,7 @@ JSON;
571 524
572 $records = $this->logHandler->getRecords(); 525 $records = $this->logHandler->getRecords();
573 $this->assertContains('PocketImport: Failed to import', $records[0]['message']); 526 $this->assertContains('PocketImport: Failed to import', $records[0]['message']);
574 $this->assertEquals('ERROR', $records[0]['level_name']); 527 $this->assertSame('ERROR', $records[0]['level_name']);
575 } 528 }
576 529
577 public function testImportWithExceptionFromGraby() 530 public function testImportWithExceptionFromGraby()
@@ -624,6 +577,59 @@ JSON;
624 $res = $pocketImport->import(); 577 $res = $pocketImport->import();
625 578
626 $this->assertTrue($res); 579 $this->assertTrue($res);
627 $this->assertEquals(['skipped' => 0, 'imported' => 1, 'queued' => 0], $pocketImport->getSummary()); 580 $this->assertSame(['skipped' => 0, 'imported' => 1, 'queued' => 0], $pocketImport->getSummary());
581 }
582
583 private function getPocketImport($consumerKey = 'ConsumerKey', $dispatched = 0)
584 {
585 $this->user = new User();
586
587 $config = new Config($this->user);
588 $config->setPocketConsumerKey('xxx');
589
590 $this->user->setConfig($config);
591
592 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
593 ->disableOriginalConstructor()
594 ->getMock();
595
596 $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner')
597 ->disableOriginalConstructor()
598 ->getMock();
599
600 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
601 ->disableOriginalConstructor()
602 ->getMock();
603
604 $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork')
605 ->disableOriginalConstructor()
606 ->getMock();
607
608 $this->em
609 ->expects($this->any())
610 ->method('getUnitOfWork')
611 ->willReturn($this->uow);
612
613 $this->uow
614 ->expects($this->any())
615 ->method('getScheduledEntityInsertions')
616 ->willReturn([]);
617
618 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
619 ->disableOriginalConstructor()
620 ->getMock();
621
622 $dispatcher
623 ->expects($this->exactly($dispatched))
624 ->method('dispatch');
625
626 $pocket = new PocketImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher);
627 $pocket->setUser($this->user);
628
629 $this->logHandler = new TestHandler();
630 $logger = new Logger('test', [$this->logHandler]);
631 $pocket->setLogger($logger);
632
633 return $pocket;
628 } 634 }
629} 635}
diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php
index d1bbe648..1822cdaa 100644
--- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php
@@ -2,14 +2,14 @@
2 2
3namespace Tests\Wallabag\ImportBundle\Import; 3namespace Tests\Wallabag\ImportBundle\Import;
4 4
5use Wallabag\ImportBundle\Import\ReadabilityImport; 5use M6Web\Component\RedisMock\RedisMockFactory;
6use Wallabag\UserBundle\Entity\User;
7use Wallabag\CoreBundle\Entity\Entry;
8use Wallabag\ImportBundle\Redis\Producer;
9use Monolog\Logger;
10use Monolog\Handler\TestHandler; 6use Monolog\Handler\TestHandler;
7use Monolog\Logger;
11use Simpleue\Queue\RedisQueue; 8use Simpleue\Queue\RedisQueue;
12use M6Web\Component\RedisMock\RedisMockFactory; 9use Wallabag\CoreBundle\Entity\Entry;
10use Wallabag\ImportBundle\Import\ReadabilityImport;
11use Wallabag\ImportBundle\Redis\Producer;
12use Wallabag\UserBundle\Entity\User;
13 13
14class ReadabilityImportTest extends \PHPUnit_Framework_TestCase 14class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
15{ 15{
@@ -17,59 +17,27 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
17 protected $em; 17 protected $em;
18 protected $logHandler; 18 protected $logHandler;
19 protected $contentProxy; 19 protected $contentProxy;
20 20 protected $tagsAssigner;
21 private function getReadabilityImport($unsetUser = false, $dispatched = 0)
22 {
23 $this->user = new User();
24
25 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
26 ->disableOriginalConstructor()
27 ->getMock();
28
29 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
30 ->disableOriginalConstructor()
31 ->getMock();
32
33 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
34 ->disableOriginalConstructor()
35 ->getMock();
36
37 $dispatcher
38 ->expects($this->exactly($dispatched))
39 ->method('dispatch');
40
41 $wallabag = new ReadabilityImport($this->em, $this->contentProxy, $dispatcher);
42
43 $this->logHandler = new TestHandler();
44 $logger = new Logger('test', [$this->logHandler]);
45 $wallabag->setLogger($logger);
46
47 if (false === $unsetUser) {
48 $wallabag->setUser($this->user);
49 }
50
51 return $wallabag;
52 }
53 21
54 public function testInit() 22 public function testInit()
55 { 23 {
56 $readabilityImport = $this->getReadabilityImport(); 24 $readabilityImport = $this->getReadabilityImport();
57 25
58 $this->assertEquals('Readability', $readabilityImport->getName()); 26 $this->assertSame('Readability', $readabilityImport->getName());
59 $this->assertNotEmpty($readabilityImport->getUrl()); 27 $this->assertNotEmpty($readabilityImport->getUrl());
60 $this->assertEquals('import.readability.description', $readabilityImport->getDescription()); 28 $this->assertSame('import.readability.description', $readabilityImport->getDescription());
61 } 29 }
62 30
63 public function testImport() 31 public function testImport()
64 { 32 {
65 $readabilityImport = $this->getReadabilityImport(false, 24); 33 $readabilityImport = $this->getReadabilityImport(false, 3);
66 $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); 34 $readabilityImport->setFilepath(__DIR__ . '/../fixtures/readability.json');
67 35
68 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 36 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
69 ->disableOriginalConstructor() 37 ->disableOriginalConstructor()
70 ->getMock(); 38 ->getMock();
71 39
72 $entryRepo->expects($this->exactly(24)) 40 $entryRepo->expects($this->exactly(3))
73 ->method('findByUrlAndUserId') 41 ->method('findByUrlAndUserId')
74 ->willReturn(false); 42 ->willReturn(false);
75 43
@@ -83,20 +51,20 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
83 ->getMock(); 51 ->getMock();
84 52
85 $this->contentProxy 53 $this->contentProxy
86 ->expects($this->exactly(24)) 54 ->expects($this->exactly(3))
87 ->method('updateEntry') 55 ->method('updateEntry')
88 ->willReturn($entry); 56 ->willReturn($entry);
89 57
90 $res = $readabilityImport->import(); 58 $res = $readabilityImport->import();
91 59
92 $this->assertTrue($res); 60 $this->assertTrue($res);
93 $this->assertEquals(['skipped' => 0, 'imported' => 24, 'queued' => 0], $readabilityImport->getSummary()); 61 $this->assertSame(['skipped' => 0, 'imported' => 3, 'queued' => 0], $readabilityImport->getSummary());
94 } 62 }
95 63
96 public function testImportAndMarkAllAsRead() 64 public function testImportAndMarkAllAsRead()
97 { 65 {
98 $readabilityImport = $this->getReadabilityImport(false, 1); 66 $readabilityImport = $this->getReadabilityImport(false, 1);
99 $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability-read.json'); 67 $readabilityImport->setFilepath(__DIR__ . '/../fixtures/readability-read.json');
100 68
101 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 69 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
102 ->disableOriginalConstructor() 70 ->disableOriginalConstructor()
@@ -128,13 +96,13 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
128 96
129 $this->assertTrue($res); 97 $this->assertTrue($res);
130 98
131 $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $readabilityImport->getSummary()); 99 $this->assertSame(['skipped' => 1, 'imported' => 1, 'queued' => 0], $readabilityImport->getSummary());
132 } 100 }
133 101
134 public function testImportWithRabbit() 102 public function testImportWithRabbit()
135 { 103 {
136 $readabilityImport = $this->getReadabilityImport(); 104 $readabilityImport = $this->getReadabilityImport();
137 $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); 105 $readabilityImport->setFilepath(__DIR__ . '/../fixtures/readability.json');
138 106
139 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 107 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
140 ->disableOriginalConstructor() 108 ->disableOriginalConstructor()
@@ -160,7 +128,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
160 ->getMock(); 128 ->getMock();
161 129
162 $producer 130 $producer
163 ->expects($this->exactly(24)) 131 ->expects($this->exactly(3))
164 ->method('publish'); 132 ->method('publish');
165 133
166 $readabilityImport->setProducer($producer); 134 $readabilityImport->setProducer($producer);
@@ -168,13 +136,13 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
168 $res = $readabilityImport->setMarkAsRead(true)->import(); 136 $res = $readabilityImport->setMarkAsRead(true)->import();
169 137
170 $this->assertTrue($res); 138 $this->assertTrue($res);
171 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $readabilityImport->getSummary()); 139 $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 3], $readabilityImport->getSummary());
172 } 140 }
173 141
174 public function testImportWithRedis() 142 public function testImportWithRedis()
175 { 143 {
176 $readabilityImport = $this->getReadabilityImport(); 144 $readabilityImport = $this->getReadabilityImport();
177 $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); 145 $readabilityImport->setFilepath(__DIR__ . '/../fixtures/readability.json');
178 146
179 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 147 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
180 ->disableOriginalConstructor() 148 ->disableOriginalConstructor()
@@ -206,7 +174,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
206 $res = $readabilityImport->setMarkAsRead(true)->import(); 174 $res = $readabilityImport->setMarkAsRead(true)->import();
207 175
208 $this->assertTrue($res); 176 $this->assertTrue($res);
209 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $readabilityImport->getSummary()); 177 $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 3], $readabilityImport->getSummary());
210 178
211 $this->assertNotEmpty($redisMock->lpop('readability')); 179 $this->assertNotEmpty($redisMock->lpop('readability'));
212 } 180 }
@@ -214,7 +182,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
214 public function testImportBadFile() 182 public function testImportBadFile()
215 { 183 {
216 $readabilityImport = $this->getReadabilityImport(); 184 $readabilityImport = $this->getReadabilityImport();
217 $readabilityImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); 185 $readabilityImport->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.jsonx');
218 186
219 $res = $readabilityImport->import(); 187 $res = $readabilityImport->import();
220 188
@@ -222,13 +190,13 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
222 190
223 $records = $this->logHandler->getRecords(); 191 $records = $this->logHandler->getRecords();
224 $this->assertContains('ReadabilityImport: unable to read file', $records[0]['message']); 192 $this->assertContains('ReadabilityImport: unable to read file', $records[0]['message']);
225 $this->assertEquals('ERROR', $records[0]['level_name']); 193 $this->assertSame('ERROR', $records[0]['level_name']);
226 } 194 }
227 195
228 public function testImportUserNotDefined() 196 public function testImportUserNotDefined()
229 { 197 {
230 $readabilityImport = $this->getReadabilityImport(true); 198 $readabilityImport = $this->getReadabilityImport(true);
231 $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); 199 $readabilityImport->setFilepath(__DIR__ . '/../fixtures/readability.json');
232 200
233 $res = $readabilityImport->import(); 201 $res = $readabilityImport->import();
234 202
@@ -236,6 +204,43 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
236 204
237 $records = $this->logHandler->getRecords(); 205 $records = $this->logHandler->getRecords();
238 $this->assertContains('ReadabilityImport: user is not defined', $records[0]['message']); 206 $this->assertContains('ReadabilityImport: user is not defined', $records[0]['message']);
239 $this->assertEquals('ERROR', $records[0]['level_name']); 207 $this->assertSame('ERROR', $records[0]['level_name']);
208 }
209
210 private function getReadabilityImport($unsetUser = false, $dispatched = 0)
211 {
212 $this->user = new User();
213
214 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
215 ->disableOriginalConstructor()
216 ->getMock();
217
218 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
219 ->disableOriginalConstructor()
220 ->getMock();
221
222 $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner')
223 ->disableOriginalConstructor()
224 ->getMock();
225
226 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
227 ->disableOriginalConstructor()
228 ->getMock();
229
230 $dispatcher
231 ->expects($this->exactly($dispatched))
232 ->method('dispatch');
233
234 $wallabag = new ReadabilityImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher);
235
236 $this->logHandler = new TestHandler();
237 $logger = new Logger('test', [$this->logHandler]);
238 $wallabag->setLogger($logger);
239
240 if (false === $unsetUser) {
241 $wallabag->setUser($this->user);
242 }
243
244 return $wallabag;
240 } 245 }
241} 246}
diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php
index 4dbced60..822ad694 100644
--- a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php
@@ -2,14 +2,14 @@
2 2
3namespace Tests\Wallabag\ImportBundle\Import; 3namespace Tests\Wallabag\ImportBundle\Import;
4 4
5use Wallabag\ImportBundle\Import\WallabagV1Import; 5use M6Web\Component\RedisMock\RedisMockFactory;
6use Wallabag\UserBundle\Entity\User;
7use Wallabag\CoreBundle\Entity\Entry;
8use Wallabag\ImportBundle\Redis\Producer;
9use Monolog\Logger;
10use Monolog\Handler\TestHandler; 6use Monolog\Handler\TestHandler;
7use Monolog\Logger;
11use Simpleue\Queue\RedisQueue; 8use Simpleue\Queue\RedisQueue;
12use M6Web\Component\RedisMock\RedisMockFactory; 9use Wallabag\CoreBundle\Entity\Entry;
10use Wallabag\ImportBundle\Import\WallabagV1Import;
11use Wallabag\ImportBundle\Redis\Producer;
12use Wallabag\UserBundle\Entity\User;
13 13
14class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase 14class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
15{ 15{
@@ -17,73 +17,30 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
17 protected $em; 17 protected $em;
18 protected $logHandler; 18 protected $logHandler;
19 protected $contentProxy; 19 protected $contentProxy;
20 20 protected $tagsAssigner;
21 private function getWallabagV1Import($unsetUser = false, $dispatched = 0) 21 protected $uow;
22 { 22 protected $fetchingErrorMessageTitle = 'No title found';
23 $this->user = new User(); 23 protected $fetchingErrorMessage = 'wallabag can\'t retrieve contents for this article. Please <a href="http://doc.wallabag.org/en/master/user/errors_during_fetching.html#how-can-i-help-to-fix-that">troubleshoot this issue</a>.';
24
25 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
26 ->disableOriginalConstructor()
27 ->getMock();
28
29 $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork')
30 ->disableOriginalConstructor()
31 ->getMock();
32
33 $this->em
34 ->expects($this->any())
35 ->method('getUnitOfWork')
36 ->willReturn($this->uow);
37
38 $this->uow
39 ->expects($this->any())
40 ->method('getScheduledEntityInsertions')
41 ->willReturn([]);
42
43 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
44 ->disableOriginalConstructor()
45 ->getMock();
46
47 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
48 ->disableOriginalConstructor()
49 ->getMock();
50
51 $dispatcher
52 ->expects($this->exactly($dispatched))
53 ->method('dispatch');
54
55 $wallabag = new WallabagV1Import($this->em, $this->contentProxy, $dispatcher);
56
57 $this->logHandler = new TestHandler();
58 $logger = new Logger('test', [$this->logHandler]);
59 $wallabag->setLogger($logger);
60
61 if (false === $unsetUser) {
62 $wallabag->setUser($this->user);
63 }
64
65 return $wallabag;
66 }
67 24
68 public function testInit() 25 public function testInit()
69 { 26 {
70 $wallabagV1Import = $this->getWallabagV1Import(); 27 $wallabagV1Import = $this->getWallabagV1Import();
71 28
72 $this->assertEquals('wallabag v1', $wallabagV1Import->getName()); 29 $this->assertSame('wallabag v1', $wallabagV1Import->getName());
73 $this->assertNotEmpty($wallabagV1Import->getUrl()); 30 $this->assertNotEmpty($wallabagV1Import->getUrl());
74 $this->assertEquals('import.wallabag_v1.description', $wallabagV1Import->getDescription()); 31 $this->assertSame('import.wallabag_v1.description', $wallabagV1Import->getDescription());
75 } 32 }
76 33
77 public function testImport() 34 public function testImport()
78 { 35 {
79 $wallabagV1Import = $this->getWallabagV1Import(false, 3); 36 $wallabagV1Import = $this->getWallabagV1Import(false, 1);
80 $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); 37 $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.json');
81 38
82 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 39 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
83 ->disableOriginalConstructor() 40 ->disableOriginalConstructor()
84 ->getMock(); 41 ->getMock();
85 42
86 $entryRepo->expects($this->exactly(4)) 43 $entryRepo->expects($this->exactly(2))
87 ->method('findByUrlAndUserId') 44 ->method('findByUrlAndUserId')
88 ->will($this->onConsecutiveCalls(false, true, false, false)); 45 ->will($this->onConsecutiveCalls(false, true, false, false));
89 46
@@ -97,20 +54,20 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
97 ->getMock(); 54 ->getMock();
98 55
99 $this->contentProxy 56 $this->contentProxy
100 ->expects($this->exactly(3)) 57 ->expects($this->exactly(1))
101 ->method('updateEntry') 58 ->method('updateEntry')
102 ->willReturn($entry); 59 ->willReturn($entry);
103 60
104 $res = $wallabagV1Import->import(); 61 $res = $wallabagV1Import->import();
105 62
106 $this->assertTrue($res); 63 $this->assertTrue($res);
107 $this->assertEquals(['skipped' => 1, 'imported' => 3, 'queued' => 0], $wallabagV1Import->getSummary()); 64 $this->assertSame(['skipped' => 1, 'imported' => 1, 'queued' => 0], $wallabagV1Import->getSummary());
108 } 65 }
109 66
110 public function testImportAndMarkAllAsRead() 67 public function testImportAndMarkAllAsRead()
111 { 68 {
112 $wallabagV1Import = $this->getWallabagV1Import(false, 3); 69 $wallabagV1Import = $this->getWallabagV1Import(false, 3);
113 $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1-read.json'); 70 $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v1-read.json');
114 71
115 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 72 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
116 ->disableOriginalConstructor() 73 ->disableOriginalConstructor()
@@ -142,13 +99,13 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
142 99
143 $this->assertTrue($res); 100 $this->assertTrue($res);
144 101
145 $this->assertEquals(['skipped' => 0, 'imported' => 3, 'queued' => 0], $wallabagV1Import->getSummary()); 102 $this->assertSame(['skipped' => 0, 'imported' => 3, 'queued' => 0], $wallabagV1Import->getSummary());
146 } 103 }
147 104
148 public function testImportWithRabbit() 105 public function testImportWithRabbit()
149 { 106 {
150 $wallabagV1Import = $this->getWallabagV1Import(); 107 $wallabagV1Import = $this->getWallabagV1Import();
151 $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); 108 $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.json');
152 109
153 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 110 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
154 ->disableOriginalConstructor() 111 ->disableOriginalConstructor()
@@ -174,7 +131,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
174 ->getMock(); 131 ->getMock();
175 132
176 $producer 133 $producer
177 ->expects($this->exactly(4)) 134 ->expects($this->exactly(2))
178 ->method('publish'); 135 ->method('publish');
179 136
180 $wallabagV1Import->setProducer($producer); 137 $wallabagV1Import->setProducer($producer);
@@ -182,13 +139,13 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
182 $res = $wallabagV1Import->setMarkAsRead(true)->import(); 139 $res = $wallabagV1Import->setMarkAsRead(true)->import();
183 140
184 $this->assertTrue($res); 141 $this->assertTrue($res);
185 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $wallabagV1Import->getSummary()); 142 $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 2], $wallabagV1Import->getSummary());
186 } 143 }
187 144
188 public function testImportWithRedis() 145 public function testImportWithRedis()
189 { 146 {
190 $wallabagV1Import = $this->getWallabagV1Import(); 147 $wallabagV1Import = $this->getWallabagV1Import();
191 $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); 148 $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.json');
192 149
193 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 150 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
194 ->disableOriginalConstructor() 151 ->disableOriginalConstructor()
@@ -220,7 +177,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
220 $res = $wallabagV1Import->setMarkAsRead(true)->import(); 177 $res = $wallabagV1Import->setMarkAsRead(true)->import();
221 178
222 $this->assertTrue($res); 179 $this->assertTrue($res);
223 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $wallabagV1Import->getSummary()); 180 $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 2], $wallabagV1Import->getSummary());
224 181
225 $this->assertNotEmpty($redisMock->lpop('wallabag_v1')); 182 $this->assertNotEmpty($redisMock->lpop('wallabag_v1'));
226 } 183 }
@@ -228,7 +185,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
228 public function testImportBadFile() 185 public function testImportBadFile()
229 { 186 {
230 $wallabagV1Import = $this->getWallabagV1Import(); 187 $wallabagV1Import = $this->getWallabagV1Import();
231 $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); 188 $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.jsonx');
232 189
233 $res = $wallabagV1Import->import(); 190 $res = $wallabagV1Import->import();
234 191
@@ -236,13 +193,13 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
236 193
237 $records = $this->logHandler->getRecords(); 194 $records = $this->logHandler->getRecords();
238 $this->assertContains('WallabagImport: unable to read file', $records[0]['message']); 195 $this->assertContains('WallabagImport: unable to read file', $records[0]['message']);
239 $this->assertEquals('ERROR', $records[0]['level_name']); 196 $this->assertSame('ERROR', $records[0]['level_name']);
240 } 197 }
241 198
242 public function testImportUserNotDefined() 199 public function testImportUserNotDefined()
243 { 200 {
244 $wallabagV1Import = $this->getWallabagV1Import(true); 201 $wallabagV1Import = $this->getWallabagV1Import(true);
245 $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); 202 $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.json');
246 203
247 $res = $wallabagV1Import->import(); 204 $res = $wallabagV1Import->import();
248 205
@@ -250,6 +207,64 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
250 207
251 $records = $this->logHandler->getRecords(); 208 $records = $this->logHandler->getRecords();
252 $this->assertContains('WallabagImport: user is not defined', $records[0]['message']); 209 $this->assertContains('WallabagImport: user is not defined', $records[0]['message']);
253 $this->assertEquals('ERROR', $records[0]['level_name']); 210 $this->assertSame('ERROR', $records[0]['level_name']);
211 }
212
213 private function getWallabagV1Import($unsetUser = false, $dispatched = 0)
214 {
215 $this->user = new User();
216
217 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
218 ->disableOriginalConstructor()
219 ->getMock();
220
221 $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork')
222 ->disableOriginalConstructor()
223 ->getMock();
224
225 $this->em
226 ->expects($this->any())
227 ->method('getUnitOfWork')
228 ->willReturn($this->uow);
229
230 $this->uow
231 ->expects($this->any())
232 ->method('getScheduledEntityInsertions')
233 ->willReturn([]);
234
235 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
236 ->disableOriginalConstructor()
237 ->getMock();
238
239 $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner')
240 ->disableOriginalConstructor()
241 ->getMock();
242
243 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
244 ->disableOriginalConstructor()
245 ->getMock();
246
247 $dispatcher
248 ->expects($this->exactly($dispatched))
249 ->method('dispatch');
250
251 $wallabag = new WallabagV1Import(
252 $this->em,
253 $this->contentProxy,
254 $this->tagsAssigner,
255 $dispatcher,
256 $this->fetchingErrorMessageTitle,
257 $this->fetchingErrorMessage
258 );
259
260 $this->logHandler = new TestHandler();
261 $logger = new Logger('test', [$this->logHandler]);
262 $wallabag->setLogger($logger);
263
264 if (false === $unsetUser) {
265 $wallabag->setUser($this->user);
266 }
267
268 return $wallabag;
254 } 269 }
255} 270}
diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php
index 0e50b8b2..fab50a45 100644
--- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php
@@ -2,14 +2,14 @@
2 2
3namespace Tests\Wallabag\ImportBundle\Import; 3namespace Tests\Wallabag\ImportBundle\Import;
4 4
5use Wallabag\ImportBundle\Import\WallabagV2Import; 5use M6Web\Component\RedisMock\RedisMockFactory;
6use Wallabag\UserBundle\Entity\User;
7use Wallabag\CoreBundle\Entity\Entry;
8use Wallabag\ImportBundle\Redis\Producer;
9use Monolog\Logger;
10use Monolog\Handler\TestHandler; 6use Monolog\Handler\TestHandler;
7use Monolog\Logger;
11use Simpleue\Queue\RedisQueue; 8use Simpleue\Queue\RedisQueue;
12use M6Web\Component\RedisMock\RedisMockFactory; 9use Wallabag\CoreBundle\Entity\Entry;
10use Wallabag\ImportBundle\Import\WallabagV2Import;
11use Wallabag\ImportBundle\Redis\Producer;
12use Wallabag\UserBundle\Entity\User;
13 13
14class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase 14class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
15{ 15{
@@ -17,73 +17,28 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
17 protected $em; 17 protected $em;
18 protected $logHandler; 18 protected $logHandler;
19 protected $contentProxy; 19 protected $contentProxy;
20 20 protected $tagsAssigner;
21 private function getWallabagV2Import($unsetUser = false, $dispatched = 0) 21 protected $uow;
22 {
23 $this->user = new User();
24
25 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
26 ->disableOriginalConstructor()
27 ->getMock();
28
29 $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork')
30 ->disableOriginalConstructor()
31 ->getMock();
32
33 $this->em
34 ->expects($this->any())
35 ->method('getUnitOfWork')
36 ->willReturn($this->uow);
37
38 $this->uow
39 ->expects($this->any())
40 ->method('getScheduledEntityInsertions')
41 ->willReturn([]);
42
43 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
44 ->disableOriginalConstructor()
45 ->getMock();
46
47 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
48 ->disableOriginalConstructor()
49 ->getMock();
50
51 $dispatcher
52 ->expects($this->exactly($dispatched))
53 ->method('dispatch');
54
55 $wallabag = new WallabagV2Import($this->em, $this->contentProxy, $dispatcher);
56
57 $this->logHandler = new TestHandler();
58 $logger = new Logger('test', [$this->logHandler]);
59 $wallabag->setLogger($logger);
60
61 if (false === $unsetUser) {
62 $wallabag->setUser($this->user);
63 }
64
65 return $wallabag;
66 }
67 22
68 public function testInit() 23 public function testInit()
69 { 24 {
70 $wallabagV2Import = $this->getWallabagV2Import(); 25 $wallabagV2Import = $this->getWallabagV2Import();
71 26
72 $this->assertEquals('wallabag v2', $wallabagV2Import->getName()); 27 $this->assertSame('wallabag v2', $wallabagV2Import->getName());
73 $this->assertNotEmpty($wallabagV2Import->getUrl()); 28 $this->assertNotEmpty($wallabagV2Import->getUrl());
74 $this->assertEquals('import.wallabag_v2.description', $wallabagV2Import->getDescription()); 29 $this->assertSame('import.wallabag_v2.description', $wallabagV2Import->getDescription());
75 } 30 }
76 31
77 public function testImport() 32 public function testImport()
78 { 33 {
79 $wallabagV2Import = $this->getWallabagV2Import(false, 2); 34 $wallabagV2Import = $this->getWallabagV2Import(false, 2);
80 $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); 35 $wallabagV2Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2.json');
81 36
82 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 37 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
83 ->disableOriginalConstructor() 38 ->disableOriginalConstructor()
84 ->getMock(); 39 ->getMock();
85 40
86 $entryRepo->expects($this->exactly(24)) 41 $entryRepo->expects($this->exactly(6))
87 ->method('findByUrlAndUserId') 42 ->method('findByUrlAndUserId')
88 ->will($this->onConsecutiveCalls(false, true, false)); 43 ->will($this->onConsecutiveCalls(false, true, false));
89 44
@@ -100,13 +55,13 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
100 $res = $wallabagV2Import->import(); 55 $res = $wallabagV2Import->import();
101 56
102 $this->assertTrue($res); 57 $this->assertTrue($res);
103 $this->assertEquals(['skipped' => 22, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); 58 $this->assertSame(['skipped' => 4, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary());
104 } 59 }
105 60
106 public function testImportAndMarkAllAsRead() 61 public function testImportAndMarkAllAsRead()
107 { 62 {
108 $wallabagV2Import = $this->getWallabagV2Import(false, 2); 63 $wallabagV2Import = $this->getWallabagV2Import(false, 2);
109 $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2-read.json'); 64 $wallabagV2Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2-read.json');
110 65
111 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 66 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
112 ->disableOriginalConstructor() 67 ->disableOriginalConstructor()
@@ -138,13 +93,13 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
138 93
139 $this->assertTrue($res); 94 $this->assertTrue($res);
140 95
141 $this->assertEquals(['skipped' => 0, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); 96 $this->assertSame(['skipped' => 0, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary());
142 } 97 }
143 98
144 public function testImportWithRabbit() 99 public function testImportWithRabbit()
145 { 100 {
146 $wallabagV2Import = $this->getWallabagV2Import(); 101 $wallabagV2Import = $this->getWallabagV2Import();
147 $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); 102 $wallabagV2Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2.json');
148 103
149 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 104 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
150 ->disableOriginalConstructor() 105 ->disableOriginalConstructor()
@@ -166,7 +121,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
166 ->getMock(); 121 ->getMock();
167 122
168 $producer 123 $producer
169 ->expects($this->exactly(24)) 124 ->expects($this->exactly(6))
170 ->method('publish'); 125 ->method('publish');
171 126
172 $wallabagV2Import->setProducer($producer); 127 $wallabagV2Import->setProducer($producer);
@@ -174,13 +129,13 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
174 $res = $wallabagV2Import->setMarkAsRead(true)->import(); 129 $res = $wallabagV2Import->setMarkAsRead(true)->import();
175 130
176 $this->assertTrue($res); 131 $this->assertTrue($res);
177 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $wallabagV2Import->getSummary()); 132 $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 6], $wallabagV2Import->getSummary());
178 } 133 }
179 134
180 public function testImportWithRedis() 135 public function testImportWithRedis()
181 { 136 {
182 $wallabagV2Import = $this->getWallabagV2Import(); 137 $wallabagV2Import = $this->getWallabagV2Import();
183 $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); 138 $wallabagV2Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2.json');
184 139
185 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 140 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
186 ->disableOriginalConstructor() 141 ->disableOriginalConstructor()
@@ -208,7 +163,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
208 $res = $wallabagV2Import->setMarkAsRead(true)->import(); 163 $res = $wallabagV2Import->setMarkAsRead(true)->import();
209 164
210 $this->assertTrue($res); 165 $this->assertTrue($res);
211 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $wallabagV2Import->getSummary()); 166 $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 6], $wallabagV2Import->getSummary());
212 167
213 $this->assertNotEmpty($redisMock->lpop('wallabag_v2')); 168 $this->assertNotEmpty($redisMock->lpop('wallabag_v2'));
214 } 169 }
@@ -216,7 +171,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
216 public function testImportBadFile() 171 public function testImportBadFile()
217 { 172 {
218 $wallabagV1Import = $this->getWallabagV2Import(); 173 $wallabagV1Import = $this->getWallabagV2Import();
219 $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.jsonx'); 174 $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2.jsonx');
220 175
221 $res = $wallabagV1Import->import(); 176 $res = $wallabagV1Import->import();
222 177
@@ -224,13 +179,13 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
224 179
225 $records = $this->logHandler->getRecords(); 180 $records = $this->logHandler->getRecords();
226 $this->assertContains('WallabagImport: unable to read file', $records[0]['message']); 181 $this->assertContains('WallabagImport: unable to read file', $records[0]['message']);
227 $this->assertEquals('ERROR', $records[0]['level_name']); 182 $this->assertSame('ERROR', $records[0]['level_name']);
228 } 183 }
229 184
230 public function testImportUserNotDefined() 185 public function testImportUserNotDefined()
231 { 186 {
232 $wallabagV1Import = $this->getWallabagV2Import(true); 187 $wallabagV1Import = $this->getWallabagV2Import(true);
233 $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); 188 $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2.json');
234 189
235 $res = $wallabagV1Import->import(); 190 $res = $wallabagV1Import->import();
236 191
@@ -238,30 +193,30 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
238 193
239 $records = $this->logHandler->getRecords(); 194 $records = $this->logHandler->getRecords();
240 $this->assertContains('WallabagImport: user is not defined', $records[0]['message']); 195 $this->assertContains('WallabagImport: user is not defined', $records[0]['message']);
241 $this->assertEquals('ERROR', $records[0]['level_name']); 196 $this->assertSame('ERROR', $records[0]['level_name']);
242 } 197 }
243 198
244 public function testImportEmptyFile() 199 public function testImportEmptyFile()
245 { 200 {
246 $wallabagV2Import = $this->getWallabagV2Import(); 201 $wallabagV2Import = $this->getWallabagV2Import();
247 $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2-empty.json'); 202 $wallabagV2Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2-empty.json');
248 203
249 $res = $wallabagV2Import->import(); 204 $res = $wallabagV2Import->import();
250 205
251 $this->assertFalse($res); 206 $this->assertFalse($res);
252 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 0], $wallabagV2Import->getSummary()); 207 $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 0], $wallabagV2Import->getSummary());
253 } 208 }
254 209
255 public function testImportWithExceptionFromGraby() 210 public function testImportWithExceptionFromGraby()
256 { 211 {
257 $wallabagV2Import = $this->getWallabagV2Import(false, 2); 212 $wallabagV2Import = $this->getWallabagV2Import(false, 2);
258 $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); 213 $wallabagV2Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2.json');
259 214
260 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 215 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
261 ->disableOriginalConstructor() 216 ->disableOriginalConstructor()
262 ->getMock(); 217 ->getMock();
263 218
264 $entryRepo->expects($this->exactly(24)) 219 $entryRepo->expects($this->exactly(6))
265 ->method('findByUrlAndUserId') 220 ->method('findByUrlAndUserId')
266 ->will($this->onConsecutiveCalls(false, true, false)); 221 ->will($this->onConsecutiveCalls(false, true, false));
267 222
@@ -278,6 +233,57 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
278 $res = $wallabagV2Import->import(); 233 $res = $wallabagV2Import->import();
279 234
280 $this->assertTrue($res); 235 $this->assertTrue($res);
281 $this->assertEquals(['skipped' => 22, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); 236 $this->assertSame(['skipped' => 4, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary());
237 }
238
239 private function getWallabagV2Import($unsetUser = false, $dispatched = 0)
240 {
241 $this->user = new User();
242
243 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
244 ->disableOriginalConstructor()
245 ->getMock();
246
247 $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork')
248 ->disableOriginalConstructor()
249 ->getMock();
250
251 $this->em
252 ->expects($this->any())
253 ->method('getUnitOfWork')
254 ->willReturn($this->uow);
255
256 $this->uow
257 ->expects($this->any())
258 ->method('getScheduledEntityInsertions')
259 ->willReturn([]);
260
261 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
262 ->disableOriginalConstructor()
263 ->getMock();
264
265 $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner')
266 ->disableOriginalConstructor()
267 ->getMock();
268
269 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
270 ->disableOriginalConstructor()
271 ->getMock();
272
273 $dispatcher
274 ->expects($this->exactly($dispatched))
275 ->method('dispatch');
276
277 $wallabag = new WallabagV2Import($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher);
278
279 $this->logHandler = new TestHandler();
280 $logger = new Logger('test', [$this->logHandler]);
281 $wallabag->setLogger($logger);
282
283 if (false === $unsetUser) {
284 $wallabag->setUser($this->user);
285 }
286
287 return $wallabag;
282 } 288 }
283} 289}