aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Wallabag/ApiBundle/Controller/WallabagRestController.php9
-rw-r--r--src/Wallabag/ImportBundle/Consumer/AbstractConsumer.php8
-rw-r--r--src/Wallabag/ImportBundle/Import/AbstractImport.php24
-rw-r--r--src/Wallabag/ImportBundle/Import/BrowserImport.php17
-rw-r--r--src/Wallabag/ImportBundle/Import/PocketImport.php7
-rw-r--r--src/Wallabag/ImportBundle/Resources/config/rabbit.yml7
-rw-r--r--src/Wallabag/ImportBundle/Resources/config/redis.yml7
-rw-r--r--src/Wallabag/ImportBundle/Resources/config/services.yml7
-rw-r--r--tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php33
-rw-r--r--tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php33
-rw-r--r--tests/Wallabag/ImportBundle/Import/ChromeImportTest.php16
-rw-r--r--tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php16
-rw-r--r--tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php16
-rw-r--r--tests/Wallabag/ImportBundle/Import/PocketImportTest.php21
-rw-r--r--tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php16
-rw-r--r--tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php16
-rw-r--r--tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php18
17 files changed, 222 insertions, 49 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
index a73d44ca..50652b77 100644
--- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
@@ -14,6 +14,8 @@ use Symfony\Component\Security\Core\Exception\AccessDeniedException;
14use Wallabag\CoreBundle\Entity\Entry; 14use Wallabag\CoreBundle\Entity\Entry;
15use Wallabag\CoreBundle\Entity\Tag; 15use Wallabag\CoreBundle\Entity\Tag;
16use Wallabag\AnnotationBundle\Entity\Annotation; 16use Wallabag\AnnotationBundle\Entity\Annotation;
17use Wallabag\CoreBundle\Event\EntrySavedEvent;
18use Wallabag\CoreBundle\Event\EntryDeletedEvent;
17 19
18class WallabagRestController extends FOSRestController 20class WallabagRestController extends FOSRestController
19{ 21{
@@ -233,9 +235,11 @@ class WallabagRestController extends FOSRestController
233 235
234 $em = $this->getDoctrine()->getManager(); 236 $em = $this->getDoctrine()->getManager();
235 $em->persist($entry); 237 $em->persist($entry);
236
237 $em->flush(); 238 $em->flush();
238 239
240 // entry saved, dispatch event about it!
241 $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
242
239 $json = $this->get('serializer')->serialize($entry, 'json'); 243 $json = $this->get('serializer')->serialize($entry, 'json');
240 244
241 return (new JsonResponse())->setJson($json); 245 return (new JsonResponse())->setJson($json);
@@ -308,6 +312,9 @@ class WallabagRestController extends FOSRestController
308 $this->validateAuthentication(); 312 $this->validateAuthentication();
309 $this->validateUserAccess($entry->getUser()->getId()); 313 $this->validateUserAccess($entry->getUser()->getId());
310 314
315 // entry deleted, dispatch event about it!
316 $this->get('event_dispatcher')->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry));
317
311 $em = $this->getDoctrine()->getManager(); 318 $em = $this->getDoctrine()->getManager();
312 $em->remove($entry); 319 $em->remove($entry);
313 $em->flush(); 320 $em->flush();
diff --git a/src/Wallabag/ImportBundle/Consumer/AbstractConsumer.php b/src/Wallabag/ImportBundle/Consumer/AbstractConsumer.php
index b893ea29..aa7ff914 100644
--- a/src/Wallabag/ImportBundle/Consumer/AbstractConsumer.php
+++ b/src/Wallabag/ImportBundle/Consumer/AbstractConsumer.php
@@ -9,6 +9,8 @@ use Wallabag\CoreBundle\Entity\Entry;
9use Wallabag\CoreBundle\Entity\Tag; 9use Wallabag\CoreBundle\Entity\Tag;
10use Psr\Log\LoggerInterface; 10use Psr\Log\LoggerInterface;
11use Psr\Log\NullLogger; 11use Psr\Log\NullLogger;
12use Symfony\Component\EventDispatcher\EventDispatcherInterface;
13use Wallabag\CoreBundle\Event\EntrySavedEvent;
12 14
13abstract class AbstractConsumer 15abstract class AbstractConsumer
14{ 16{
@@ -17,11 +19,12 @@ abstract class AbstractConsumer
17 protected $import; 19 protected $import;
18 protected $logger; 20 protected $logger;
19 21
20 public function __construct(EntityManager $em, UserRepository $userRepository, AbstractImport $import, LoggerInterface $logger = null) 22 public function __construct(EntityManager $em, UserRepository $userRepository, AbstractImport $import, EventDispatcherInterface $eventDispatcher, LoggerInterface $logger = null)
21 { 23 {
22 $this->em = $em; 24 $this->em = $em;
23 $this->userRepository = $userRepository; 25 $this->userRepository = $userRepository;
24 $this->import = $import; 26 $this->import = $import;
27 $this->eventDispatcher = $eventDispatcher;
25 $this->logger = $logger ?: new NullLogger(); 28 $this->logger = $logger ?: new NullLogger();
26 } 29 }
27 30
@@ -59,6 +62,9 @@ abstract class AbstractConsumer
59 try { 62 try {
60 $this->em->flush(); 63 $this->em->flush();
61 64
65 // entry saved, dispatch event about it!
66 $this->eventDispatcher->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
67
62 // clear only affected entities 68 // clear only affected entities
63 $this->em->clear(Entry::class); 69 $this->em->clear(Entry::class);
64 $this->em->clear(Tag::class); 70 $this->em->clear(Tag::class);
diff --git a/src/Wallabag/ImportBundle/Import/AbstractImport.php b/src/Wallabag/ImportBundle/Import/AbstractImport.php
index 764b390a..1d4a6e27 100644
--- a/src/Wallabag/ImportBundle/Import/AbstractImport.php
+++ b/src/Wallabag/ImportBundle/Import/AbstractImport.php
@@ -10,12 +10,15 @@ use Wallabag\CoreBundle\Entity\Entry;
10use Wallabag\CoreBundle\Entity\Tag; 10use Wallabag\CoreBundle\Entity\Tag;
11use Wallabag\UserBundle\Entity\User; 11use Wallabag\UserBundle\Entity\User;
12use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface; 12use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface;
13use Symfony\Component\EventDispatcher\EventDispatcherInterface;
14use Wallabag\CoreBundle\Event\EntrySavedEvent;
13 15
14abstract class AbstractImport implements ImportInterface 16abstract class AbstractImport implements ImportInterface
15{ 17{
16 protected $em; 18 protected $em;
17 protected $logger; 19 protected $logger;
18 protected $contentProxy; 20 protected $contentProxy;
21 protected $eventDispatcher;
19 protected $producer; 22 protected $producer;
20 protected $user; 23 protected $user;
21 protected $markAsRead; 24 protected $markAsRead;
@@ -23,11 +26,12 @@ abstract class AbstractImport implements ImportInterface
23 protected $importedEntries = 0; 26 protected $importedEntries = 0;
24 protected $queuedEntries = 0; 27 protected $queuedEntries = 0;
25 28
26 public function __construct(EntityManager $em, ContentProxy $contentProxy) 29 public function __construct(EntityManager $em, ContentProxy $contentProxy, EventDispatcherInterface $eventDispatcher)
27 { 30 {
28 $this->em = $em; 31 $this->em = $em;
29 $this->logger = new NullLogger(); 32 $this->logger = new NullLogger();
30 $this->contentProxy = $contentProxy; 33 $this->contentProxy = $contentProxy;
34 $this->eventDispatcher = $eventDispatcher;
31 } 35 }
32 36
33 public function setLogger(LoggerInterface $logger) 37 public function setLogger(LoggerInterface $logger)
@@ -104,6 +108,7 @@ abstract class AbstractImport implements ImportInterface
104 protected function parseEntries($entries) 108 protected function parseEntries($entries)
105 { 109 {
106 $i = 1; 110 $i = 1;
111 $entryToBeFlushed = [];
107 112
108 foreach ($entries as $importedEntry) { 113 foreach ($entries as $importedEntry) {
109 if ($this->markAsRead) { 114 if ($this->markAsRead) {
@@ -116,10 +121,21 @@ abstract class AbstractImport implements ImportInterface
116 continue; 121 continue;
117 } 122 }
118 123
124 // store each entry to be flushed so we can trigger the entry.saved event for each of them
125 // entry.saved needs the entry to be persisted in db because it needs it id to generate
126 // images (at least)
127 $entryToBeFlushed[] = $entry;
128
119 // flush every 20 entries 129 // flush every 20 entries
120 if (($i % 20) === 0) { 130 if (($i % 20) === 0) {
121 $this->em->flush(); 131 $this->em->flush();
122 132
133 foreach ($entryToBeFlushed as $entry) {
134 $this->eventDispatcher->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
135 }
136
137 $entryToBeFlushed = [];
138
123 // clear only affected entities 139 // clear only affected entities
124 $this->em->clear(Entry::class); 140 $this->em->clear(Entry::class);
125 $this->em->clear(Tag::class); 141 $this->em->clear(Tag::class);
@@ -128,6 +144,12 @@ abstract class AbstractImport implements ImportInterface
128 } 144 }
129 145
130 $this->em->flush(); 146 $this->em->flush();
147
148 if (!empty($entryToBeFlushed)) {
149 foreach ($entryToBeFlushed as $entry) {
150 $this->eventDispatcher->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
151 }
152 }
131 } 153 }
132 154
133 /** 155 /**
diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php
index 2ca1683b..8bf7d92e 100644
--- a/src/Wallabag/ImportBundle/Import/BrowserImport.php
+++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php
@@ -5,6 +5,7 @@ namespace Wallabag\ImportBundle\Import;
5use Wallabag\CoreBundle\Entity\Entry; 5use Wallabag\CoreBundle\Entity\Entry;
6use Wallabag\UserBundle\Entity\User; 6use Wallabag\UserBundle\Entity\User;
7use Wallabag\CoreBundle\Helper\ContentProxy; 7use Wallabag\CoreBundle\Helper\ContentProxy;
8use Wallabag\CoreBundle\Event\EntrySavedEvent;
8 9
9abstract class BrowserImport extends AbstractImport 10abstract class BrowserImport extends AbstractImport
10{ 11{
@@ -81,6 +82,7 @@ abstract class BrowserImport extends AbstractImport
81 protected function parseEntries($entries) 82 protected function parseEntries($entries)
82 { 83 {
83 $i = 1; 84 $i = 1;
85 $entryToBeFlushed = [];
84 86
85 foreach ($entries as $importedEntry) { 87 foreach ($entries as $importedEntry) {
86 if ((array) $importedEntry !== $importedEntry) { 88 if ((array) $importedEntry !== $importedEntry) {
@@ -93,14 +95,29 @@ abstract class BrowserImport extends AbstractImport
93 continue; 95 continue;
94 } 96 }
95 97
98 // @see AbstractImport
99 $entryToBeFlushed[] = $entry;
100
96 // flush every 20 entries 101 // flush every 20 entries
97 if (($i % 20) === 0) { 102 if (($i % 20) === 0) {
98 $this->em->flush(); 103 $this->em->flush();
104
105 foreach ($entryToBeFlushed as $entry) {
106 $this->eventDispatcher->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
107 }
108
109 $entryToBeFlushed = [];
99 } 110 }
100 ++$i; 111 ++$i;
101 } 112 }
102 113
103 $this->em->flush(); 114 $this->em->flush();
115
116 if (!empty($entryToBeFlushed)) {
117 foreach ($entryToBeFlushed as $entry) {
118 $this->eventDispatcher->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
119 }
120 }
104 } 121 }
105 122
106 /** 123 /**
diff --git a/src/Wallabag/ImportBundle/Import/PocketImport.php b/src/Wallabag/ImportBundle/Import/PocketImport.php
index 327e2500..0c26aced 100644
--- a/src/Wallabag/ImportBundle/Import/PocketImport.php
+++ b/src/Wallabag/ImportBundle/Import/PocketImport.php
@@ -16,13 +16,6 @@ class PocketImport extends AbstractImport
16 16
17 const NB_ELEMENTS = 5000; 17 const NB_ELEMENTS = 5000;
18 18
19 public function __construct(EntityManager $em, ContentProxy $contentProxy)
20 {
21 $this->em = $em;
22 $this->contentProxy = $contentProxy;
23 $this->logger = new NullLogger();
24 }
25
26 /** 19 /**
27 * Only used for test purpose. 20 * Only used for test purpose.
28 * 21 *
diff --git a/src/Wallabag/ImportBundle/Resources/config/rabbit.yml b/src/Wallabag/ImportBundle/Resources/config/rabbit.yml
index 70b8a0d4..a5af5282 100644
--- a/src/Wallabag/ImportBundle/Resources/config/rabbit.yml
+++ b/src/Wallabag/ImportBundle/Resources/config/rabbit.yml
@@ -6,6 +6,7 @@ services:
6 - "@doctrine.orm.entity_manager" 6 - "@doctrine.orm.entity_manager"
7 - "@wallabag_user.user_repository" 7 - "@wallabag_user.user_repository"
8 - "@wallabag_import.pocket.import" 8 - "@wallabag_import.pocket.import"
9 - "@event_dispatcher"
9 - "@logger" 10 - "@logger"
10 wallabag_import.consumer.amqp.readability: 11 wallabag_import.consumer.amqp.readability:
11 class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer 12 class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer
@@ -13,6 +14,7 @@ services:
13 - "@doctrine.orm.entity_manager" 14 - "@doctrine.orm.entity_manager"
14 - "@wallabag_user.user_repository" 15 - "@wallabag_user.user_repository"
15 - "@wallabag_import.readability.import" 16 - "@wallabag_import.readability.import"
17 - "@event_dispatcher"
16 - "@logger" 18 - "@logger"
17 wallabag_import.consumer.amqp.instapaper: 19 wallabag_import.consumer.amqp.instapaper:
18 class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer 20 class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer
@@ -20,6 +22,7 @@ services:
20 - "@doctrine.orm.entity_manager" 22 - "@doctrine.orm.entity_manager"
21 - "@wallabag_user.user_repository" 23 - "@wallabag_user.user_repository"
22 - "@wallabag_import.instapaper.import" 24 - "@wallabag_import.instapaper.import"
25 - "@event_dispatcher"
23 - "@logger" 26 - "@logger"
24 wallabag_import.consumer.amqp.wallabag_v1: 27 wallabag_import.consumer.amqp.wallabag_v1:
25 class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer 28 class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer
@@ -27,6 +30,7 @@ services:
27 - "@doctrine.orm.entity_manager" 30 - "@doctrine.orm.entity_manager"
28 - "@wallabag_user.user_repository" 31 - "@wallabag_user.user_repository"
29 - "@wallabag_import.wallabag_v1.import" 32 - "@wallabag_import.wallabag_v1.import"
33 - "@event_dispatcher"
30 - "@logger" 34 - "@logger"
31 wallabag_import.consumer.amqp.wallabag_v2: 35 wallabag_import.consumer.amqp.wallabag_v2:
32 class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer 36 class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer
@@ -34,6 +38,7 @@ services:
34 - "@doctrine.orm.entity_manager" 38 - "@doctrine.orm.entity_manager"
35 - "@wallabag_user.user_repository" 39 - "@wallabag_user.user_repository"
36 - "@wallabag_import.wallabag_v2.import" 40 - "@wallabag_import.wallabag_v2.import"
41 - "@event_dispatcher"
37 - "@logger" 42 - "@logger"
38 wallabag_import.consumer.amqp.firefox: 43 wallabag_import.consumer.amqp.firefox:
39 class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer 44 class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer
@@ -41,6 +46,7 @@ services:
41 - "@doctrine.orm.entity_manager" 46 - "@doctrine.orm.entity_manager"
42 - "@wallabag_user.user_repository" 47 - "@wallabag_user.user_repository"
43 - "@wallabag_import.firefox.import" 48 - "@wallabag_import.firefox.import"
49 - "@event_dispatcher"
44 - "@logger" 50 - "@logger"
45 wallabag_import.consumer.amqp.chrome: 51 wallabag_import.consumer.amqp.chrome:
46 class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer 52 class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer
@@ -48,4 +54,5 @@ services:
48 - "@doctrine.orm.entity_manager" 54 - "@doctrine.orm.entity_manager"
49 - "@wallabag_user.user_repository" 55 - "@wallabag_user.user_repository"
50 - "@wallabag_import.chrome.import" 56 - "@wallabag_import.chrome.import"
57 - "@event_dispatcher"
51 - "@logger" 58 - "@logger"
diff --git a/src/Wallabag/ImportBundle/Resources/config/redis.yml b/src/Wallabag/ImportBundle/Resources/config/redis.yml
index 0a81e1b5..5ced4c83 100644
--- a/src/Wallabag/ImportBundle/Resources/config/redis.yml
+++ b/src/Wallabag/ImportBundle/Resources/config/redis.yml
@@ -18,6 +18,7 @@ services:
18 - "@doctrine.orm.entity_manager" 18 - "@doctrine.orm.entity_manager"
19 - "@wallabag_user.user_repository" 19 - "@wallabag_user.user_repository"
20 - "@wallabag_import.readability.import" 20 - "@wallabag_import.readability.import"
21 - "@event_dispatcher"
21 - "@logger" 22 - "@logger"
22 23
23 # instapaper 24 # instapaper
@@ -38,6 +39,7 @@ services:
38 - "@doctrine.orm.entity_manager" 39 - "@doctrine.orm.entity_manager"
39 - "@wallabag_user.user_repository" 40 - "@wallabag_user.user_repository"
40 - "@wallabag_import.instapaper.import" 41 - "@wallabag_import.instapaper.import"
42 - "@event_dispatcher"
41 - "@logger" 43 - "@logger"
42 44
43 # pocket 45 # pocket
@@ -58,6 +60,7 @@ services:
58 - "@doctrine.orm.entity_manager" 60 - "@doctrine.orm.entity_manager"
59 - "@wallabag_user.user_repository" 61 - "@wallabag_user.user_repository"
60 - "@wallabag_import.pocket.import" 62 - "@wallabag_import.pocket.import"
63 - "@event_dispatcher"
61 - "@logger" 64 - "@logger"
62 65
63 # wallabag v1 66 # wallabag v1
@@ -78,6 +81,7 @@ services:
78 - "@doctrine.orm.entity_manager" 81 - "@doctrine.orm.entity_manager"
79 - "@wallabag_user.user_repository" 82 - "@wallabag_user.user_repository"
80 - "@wallabag_import.wallabag_v1.import" 83 - "@wallabag_import.wallabag_v1.import"
84 - "@event_dispatcher"
81 - "@logger" 85 - "@logger"
82 86
83 # wallabag v2 87 # wallabag v2
@@ -98,6 +102,7 @@ services:
98 - "@doctrine.orm.entity_manager" 102 - "@doctrine.orm.entity_manager"
99 - "@wallabag_user.user_repository" 103 - "@wallabag_user.user_repository"
100 - "@wallabag_import.wallabag_v2.import" 104 - "@wallabag_import.wallabag_v2.import"
105 - "@event_dispatcher"
101 - "@logger" 106 - "@logger"
102 107
103 # firefox 108 # firefox
@@ -118,6 +123,7 @@ services:
118 - "@doctrine.orm.entity_manager" 123 - "@doctrine.orm.entity_manager"
119 - "@wallabag_user.user_repository" 124 - "@wallabag_user.user_repository"
120 - "@wallabag_import.firefox.import" 125 - "@wallabag_import.firefox.import"
126 - "@event_dispatcher"
121 - "@logger" 127 - "@logger"
122 128
123 # chrome 129 # chrome
@@ -138,4 +144,5 @@ services:
138 - "@doctrine.orm.entity_manager" 144 - "@doctrine.orm.entity_manager"
139 - "@wallabag_user.user_repository" 145 - "@wallabag_user.user_repository"
140 - "@wallabag_import.chrome.import" 146 - "@wallabag_import.chrome.import"
147 - "@event_dispatcher"
141 - "@logger" 148 - "@logger"
diff --git a/src/Wallabag/ImportBundle/Resources/config/services.yml b/src/Wallabag/ImportBundle/Resources/config/services.yml
index d600be0f..64822963 100644
--- a/src/Wallabag/ImportBundle/Resources/config/services.yml
+++ b/src/Wallabag/ImportBundle/Resources/config/services.yml
@@ -20,6 +20,7 @@ services:
20 arguments: 20 arguments:
21 - "@doctrine.orm.entity_manager" 21 - "@doctrine.orm.entity_manager"
22 - "@wallabag_core.content_proxy" 22 - "@wallabag_core.content_proxy"
23 - "@event_dispatcher"
23 calls: 24 calls:
24 - [ setClient, [ "@wallabag_import.pocket.client" ] ] 25 - [ setClient, [ "@wallabag_import.pocket.client" ] ]
25 - [ setLogger, [ "@logger" ]] 26 - [ setLogger, [ "@logger" ]]
@@ -31,6 +32,7 @@ services:
31 arguments: 32 arguments:
32 - "@doctrine.orm.entity_manager" 33 - "@doctrine.orm.entity_manager"
33 - "@wallabag_core.content_proxy" 34 - "@wallabag_core.content_proxy"
35 - "@event_dispatcher"
34 calls: 36 calls:
35 - [ setLogger, [ "@logger" ]] 37 - [ setLogger, [ "@logger" ]]
36 tags: 38 tags:
@@ -41,6 +43,7 @@ services:
41 arguments: 43 arguments:
42 - "@doctrine.orm.entity_manager" 44 - "@doctrine.orm.entity_manager"
43 - "@wallabag_core.content_proxy" 45 - "@wallabag_core.content_proxy"
46 - "@event_dispatcher"
44 calls: 47 calls:
45 - [ setLogger, [ "@logger" ]] 48 - [ setLogger, [ "@logger" ]]
46 tags: 49 tags:
@@ -51,6 +54,7 @@ services:
51 arguments: 54 arguments:
52 - "@doctrine.orm.entity_manager" 55 - "@doctrine.orm.entity_manager"
53 - "@wallabag_core.content_proxy" 56 - "@wallabag_core.content_proxy"
57 - "@event_dispatcher"
54 calls: 58 calls:
55 - [ setLogger, [ "@logger" ]] 59 - [ setLogger, [ "@logger" ]]
56 tags: 60 tags:
@@ -61,6 +65,7 @@ services:
61 arguments: 65 arguments:
62 - "@doctrine.orm.entity_manager" 66 - "@doctrine.orm.entity_manager"
63 - "@wallabag_core.content_proxy" 67 - "@wallabag_core.content_proxy"
68 - "@event_dispatcher"
64 calls: 69 calls:
65 - [ setLogger, [ "@logger" ]] 70 - [ setLogger, [ "@logger" ]]
66 tags: 71 tags:
@@ -71,6 +76,7 @@ services:
71 arguments: 76 arguments:
72 - "@doctrine.orm.entity_manager" 77 - "@doctrine.orm.entity_manager"
73 - "@wallabag_core.content_proxy" 78 - "@wallabag_core.content_proxy"
79 - "@event_dispatcher"
74 calls: 80 calls:
75 - [ setLogger, [ "@logger" ]] 81 - [ setLogger, [ "@logger" ]]
76 tags: 82 tags:
@@ -80,6 +86,7 @@ services:
80 arguments: 86 arguments:
81 - "@doctrine.orm.entity_manager" 87 - "@doctrine.orm.entity_manager"
82 - "@wallabag_core.content_proxy" 88 - "@wallabag_core.content_proxy"
89 - "@event_dispatcher"
83 calls: 90 calls:
84 - [ setLogger, [ "@logger" ]] 91 - [ setLogger, [ "@logger" ]]
85 tags: 92 tags:
diff --git a/tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php b/tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php
index a3263771..856954a6 100644
--- a/tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php
+++ b/tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php
@@ -112,10 +112,19 @@ JSON;
112 ->with(json_decode($body, true)) 112 ->with(json_decode($body, true))
113 ->willReturn($entry); 113 ->willReturn($entry);
114 114
115 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
116 ->disableOriginalConstructor()
117 ->getMock();
118
119 $dispatcher
120 ->expects($this->once())
121 ->method('dispatch');
122
115 $consumer = new AMQPEntryConsumer( 123 $consumer = new AMQPEntryConsumer(
116 $em, 124 $em,
117 $userRepository, 125 $userRepository,
118 $import 126 $import,
127 $dispatcher
119 ); 128 );
120 129
121 $message = new AMQPMessage($body); 130 $message = new AMQPMessage($body);
@@ -157,10 +166,19 @@ JSON;
157 ->disableOriginalConstructor() 166 ->disableOriginalConstructor()
158 ->getMock(); 167 ->getMock();
159 168
169 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
170 ->disableOriginalConstructor()
171 ->getMock();
172
173 $dispatcher
174 ->expects($this->never())
175 ->method('dispatch');
176
160 $consumer = new AMQPEntryConsumer( 177 $consumer = new AMQPEntryConsumer(
161 $em, 178 $em,
162 $userRepository, 179 $userRepository,
163 $import 180 $import,
181 $dispatcher
164 ); 182 );
165 183
166 $message = new AMQPMessage($body); 184 $message = new AMQPMessage($body);
@@ -212,10 +230,19 @@ JSON;
212 ->with(json_decode($body, true)) 230 ->with(json_decode($body, true))
213 ->willReturn(null); 231 ->willReturn(null);
214 232
233 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
234 ->disableOriginalConstructor()
235 ->getMock();
236
237 $dispatcher
238 ->expects($this->never())
239 ->method('dispatch');
240
215 $consumer = new AMQPEntryConsumer( 241 $consumer = new AMQPEntryConsumer(
216 $em, 242 $em,
217 $userRepository, 243 $userRepository,
218 $import 244 $import,
245 $dispatcher
219 ); 246 );
220 247
221 $message = new AMQPMessage($body); 248 $message = new AMQPMessage($body);
diff --git a/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php b/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php
index 01a92ad2..3b92f759 100644
--- a/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php
+++ b/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php
@@ -111,10 +111,19 @@ JSON;
111 ->with(json_decode($body, true)) 111 ->with(json_decode($body, true))
112 ->willReturn($entry); 112 ->willReturn($entry);
113 113
114 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
115 ->disableOriginalConstructor()
116 ->getMock();
117
118 $dispatcher
119 ->expects($this->once())
120 ->method('dispatch');
121
114 $consumer = new RedisEntryConsumer( 122 $consumer = new RedisEntryConsumer(
115 $em, 123 $em,
116 $userRepository, 124 $userRepository,
117 $import 125 $import,
126 $dispatcher
118 ); 127 );
119 128
120 $res = $consumer->manage($body); 129 $res = $consumer->manage($body);
@@ -156,10 +165,19 @@ JSON;
156 ->disableOriginalConstructor() 165 ->disableOriginalConstructor()
157 ->getMock(); 166 ->getMock();
158 167
168 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
169 ->disableOriginalConstructor()
170 ->getMock();
171
172 $dispatcher
173 ->expects($this->never())
174 ->method('dispatch');
175
159 $consumer = new RedisEntryConsumer( 176 $consumer = new RedisEntryConsumer(
160 $em, 177 $em,
161 $userRepository, 178 $userRepository,
162 $import 179 $import,
180 $dispatcher
163 ); 181 );
164 182
165 $res = $consumer->manage($body); 183 $res = $consumer->manage($body);
@@ -211,10 +229,19 @@ JSON;
211 ->with(json_decode($body, true)) 229 ->with(json_decode($body, true))
212 ->willReturn(null); 230 ->willReturn(null);
213 231
232 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
233 ->disableOriginalConstructor()
234 ->getMock();
235
236 $dispatcher
237 ->expects($this->never())
238 ->method('dispatch');
239
214 $consumer = new RedisEntryConsumer( 240 $consumer = new RedisEntryConsumer(
215 $em, 241 $em,
216 $userRepository, 242 $userRepository,
217 $import 243 $import,
244 $dispatcher
218 ); 245 );
219 246
220 $res = $consumer->manage($body); 247 $res = $consumer->manage($body);
diff --git a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php
index 1e52615c..6b3adda4 100644
--- a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php
@@ -18,7 +18,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
18 protected $logHandler; 18 protected $logHandler;
19 protected $contentProxy; 19 protected $contentProxy;
20 20
21 private function getChromeImport($unsetUser = false) 21 private function getChromeImport($unsetUser = false, $dispatched = 0)
22 { 22 {
23 $this->user = new User(); 23 $this->user = new User();
24 24
@@ -30,7 +30,15 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
30 ->disableOriginalConstructor() 30 ->disableOriginalConstructor()
31 ->getMock(); 31 ->getMock();
32 32
33 $wallabag = new ChromeImport($this->em, $this->contentProxy); 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);
34 42
35 $this->logHandler = new TestHandler(); 43 $this->logHandler = new TestHandler();
36 $logger = new Logger('test', [$this->logHandler]); 44 $logger = new Logger('test', [$this->logHandler]);
@@ -54,7 +62,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
54 62
55 public function testImport() 63 public function testImport()
56 { 64 {
57 $chromeImport = $this->getChromeImport(); 65 $chromeImport = $this->getChromeImport(false, 1);
58 $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); 66 $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks');
59 67
60 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 68 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@@ -87,7 +95,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
87 95
88 public function testImportAndMarkAllAsRead() 96 public function testImportAndMarkAllAsRead()
89 { 97 {
90 $chromeImport = $this->getChromeImport(); 98 $chromeImport = $this->getChromeImport(false, 1);
91 $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); 99 $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks');
92 100
93 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 101 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
diff --git a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php
index 007dda6a..b516fbc5 100644
--- a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php
@@ -18,7 +18,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
18 protected $logHandler; 18 protected $logHandler;
19 protected $contentProxy; 19 protected $contentProxy;
20 20
21 private function getFirefoxImport($unsetUser = false) 21 private function getFirefoxImport($unsetUser = false, $dispatched = 0)
22 { 22 {
23 $this->user = new User(); 23 $this->user = new User();
24 24
@@ -30,7 +30,15 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
30 ->disableOriginalConstructor() 30 ->disableOriginalConstructor()
31 ->getMock(); 31 ->getMock();
32 32
33 $wallabag = new FirefoxImport($this->em, $this->contentProxy); 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);
34 42
35 $this->logHandler = new TestHandler(); 43 $this->logHandler = new TestHandler();
36 $logger = new Logger('test', [$this->logHandler]); 44 $logger = new Logger('test', [$this->logHandler]);
@@ -54,7 +62,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
54 62
55 public function testImport() 63 public function testImport()
56 { 64 {
57 $firefoxImport = $this->getFirefoxImport(); 65 $firefoxImport = $this->getFirefoxImport(false, 2);
58 $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); 66 $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json');
59 67
60 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 68 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@@ -87,7 +95,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
87 95
88 public function testImportAndMarkAllAsRead() 96 public function testImportAndMarkAllAsRead()
89 { 97 {
90 $firefoxImport = $this->getFirefoxImport(); 98 $firefoxImport = $this->getFirefoxImport(false, 1);
91 $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); 99 $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json');
92 100
93 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 101 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
diff --git a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php
index 75900bd7..e262a808 100644
--- a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php
@@ -18,7 +18,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
18 protected $logHandler; 18 protected $logHandler;
19 protected $contentProxy; 19 protected $contentProxy;
20 20
21 private function getInstapaperImport($unsetUser = false) 21 private function getInstapaperImport($unsetUser = false, $dispatched = 0)
22 { 22 {
23 $this->user = new User(); 23 $this->user = new User();
24 24
@@ -30,7 +30,15 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
30 ->disableOriginalConstructor() 30 ->disableOriginalConstructor()
31 ->getMock(); 31 ->getMock();
32 32
33 $import = new InstapaperImport($this->em, $this->contentProxy); 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);
34 42
35 $this->logHandler = new TestHandler(); 43 $this->logHandler = new TestHandler();
36 $logger = new Logger('test', [$this->logHandler]); 44 $logger = new Logger('test', [$this->logHandler]);
@@ -54,7 +62,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
54 62
55 public function testImport() 63 public function testImport()
56 { 64 {
57 $instapaperImport = $this->getInstapaperImport(); 65 $instapaperImport = $this->getInstapaperImport(false, 3);
58 $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); 66 $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv');
59 67
60 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 68 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@@ -87,7 +95,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
87 95
88 public function testImportAndMarkAllAsRead() 96 public function testImportAndMarkAllAsRead()
89 { 97 {
90 $instapaperImport = $this->getInstapaperImport(); 98 $instapaperImport = $this->getInstapaperImport(false, 1);
91 $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); 99 $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv');
92 100
93 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 101 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php
index 9ec7935c..141ece36 100644
--- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php
@@ -24,7 +24,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
24 protected $contentProxy; 24 protected $contentProxy;
25 protected $logHandler; 25 protected $logHandler;
26 26
27 private function getPocketImport($consumerKey = 'ConsumerKey') 27 private function getPocketImport($consumerKey = 'ConsumerKey', $dispatched = 0)
28 { 28 {
29 $this->user = new User(); 29 $this->user = new User();
30 30
@@ -55,10 +55,15 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
55 ->method('getScheduledEntityInsertions') 55 ->method('getScheduledEntityInsertions')
56 ->willReturn([]); 56 ->willReturn([]);
57 57
58 $pocket = new PocketImport( 58 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
59 $this->em, 59 ->disableOriginalConstructor()
60 $this->contentProxy 60 ->getMock();
61 ); 61
62 $dispatcher
63 ->expects($this->exactly($dispatched))
64 ->method('dispatch');
65
66 $pocket = new PocketImport($this->em, $this->contentProxy, $dispatcher);
62 $pocket->setUser($this->user); 67 $pocket->setUser($this->user);
63 68
64 $this->logHandler = new TestHandler(); 69 $this->logHandler = new TestHandler();
@@ -252,7 +257,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
252 257
253 $client->getEmitter()->attach($mock); 258 $client->getEmitter()->attach($mock);
254 259
255 $pocketImport = $this->getPocketImport(); 260 $pocketImport = $this->getPocketImport('ConsumerKey', 1);
256 261
257 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 262 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
258 ->disableOriginalConstructor() 263 ->disableOriginalConstructor()
@@ -339,7 +344,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
339 344
340 $client->getEmitter()->attach($mock); 345 $client->getEmitter()->attach($mock);
341 346
342 $pocketImport = $this->getPocketImport(); 347 $pocketImport = $this->getPocketImport('ConsumerKey', 2);
343 348
344 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 349 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
345 ->disableOriginalConstructor() 350 ->disableOriginalConstructor()
@@ -591,7 +596,7 @@ JSON;
591 596
592 $client->getEmitter()->attach($mock); 597 $client->getEmitter()->attach($mock);
593 598
594 $pocketImport = $this->getPocketImport(); 599 $pocketImport = $this->getPocketImport('ConsumerKey', 1);
595 600
596 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 601 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
597 ->disableOriginalConstructor() 602 ->disableOriginalConstructor()
diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php
index d98cd486..d1bbe648 100644
--- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php
@@ -18,7 +18,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
18 protected $logHandler; 18 protected $logHandler;
19 protected $contentProxy; 19 protected $contentProxy;
20 20
21 private function getReadabilityImport($unsetUser = false) 21 private function getReadabilityImport($unsetUser = false, $dispatched = 0)
22 { 22 {
23 $this->user = new User(); 23 $this->user = new User();
24 24
@@ -30,7 +30,15 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
30 ->disableOriginalConstructor() 30 ->disableOriginalConstructor()
31 ->getMock(); 31 ->getMock();
32 32
33 $wallabag = new ReadabilityImport($this->em, $this->contentProxy); 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);
34 42
35 $this->logHandler = new TestHandler(); 43 $this->logHandler = new TestHandler();
36 $logger = new Logger('test', [$this->logHandler]); 44 $logger = new Logger('test', [$this->logHandler]);
@@ -54,7 +62,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
54 62
55 public function testImport() 63 public function testImport()
56 { 64 {
57 $readabilityImport = $this->getReadabilityImport(); 65 $readabilityImport = $this->getReadabilityImport(false, 24);
58 $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); 66 $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json');
59 67
60 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 68 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@@ -87,7 +95,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
87 95
88 public function testImportAndMarkAllAsRead() 96 public function testImportAndMarkAllAsRead()
89 { 97 {
90 $readabilityImport = $this->getReadabilityImport(); 98 $readabilityImport = $this->getReadabilityImport(false, 1);
91 $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability-read.json'); 99 $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability-read.json');
92 100
93 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 101 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php
index 82dc4c7e..4dbced60 100644
--- a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php
@@ -18,7 +18,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
18 protected $logHandler; 18 protected $logHandler;
19 protected $contentProxy; 19 protected $contentProxy;
20 20
21 private function getWallabagV1Import($unsetUser = false) 21 private function getWallabagV1Import($unsetUser = false, $dispatched = 0)
22 { 22 {
23 $this->user = new User(); 23 $this->user = new User();
24 24
@@ -44,7 +44,15 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
44 ->disableOriginalConstructor() 44 ->disableOriginalConstructor()
45 ->getMock(); 45 ->getMock();
46 46
47 $wallabag = new WallabagV1Import($this->em, $this->contentProxy); 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);
48 56
49 $this->logHandler = new TestHandler(); 57 $this->logHandler = new TestHandler();
50 $logger = new Logger('test', [$this->logHandler]); 58 $logger = new Logger('test', [$this->logHandler]);
@@ -68,7 +76,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
68 76
69 public function testImport() 77 public function testImport()
70 { 78 {
71 $wallabagV1Import = $this->getWallabagV1Import(); 79 $wallabagV1Import = $this->getWallabagV1Import(false, 3);
72 $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); 80 $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json');
73 81
74 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 82 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@@ -101,7 +109,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
101 109
102 public function testImportAndMarkAllAsRead() 110 public function testImportAndMarkAllAsRead()
103 { 111 {
104 $wallabagV1Import = $this->getWallabagV1Import(); 112 $wallabagV1Import = $this->getWallabagV1Import(false, 3);
105 $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1-read.json'); 113 $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1-read.json');
106 114
107 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 115 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php
index bea89efb..0e50b8b2 100644
--- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php
@@ -18,7 +18,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
18 protected $logHandler; 18 protected $logHandler;
19 protected $contentProxy; 19 protected $contentProxy;
20 20
21 private function getWallabagV2Import($unsetUser = false) 21 private function getWallabagV2Import($unsetUser = false, $dispatched = 0)
22 { 22 {
23 $this->user = new User(); 23 $this->user = new User();
24 24
@@ -44,7 +44,15 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
44 ->disableOriginalConstructor() 44 ->disableOriginalConstructor()
45 ->getMock(); 45 ->getMock();
46 46
47 $wallabag = new WallabagV2Import($this->em, $this->contentProxy); 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);
48 56
49 $this->logHandler = new TestHandler(); 57 $this->logHandler = new TestHandler();
50 $logger = new Logger('test', [$this->logHandler]); 58 $logger = new Logger('test', [$this->logHandler]);
@@ -68,7 +76,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
68 76
69 public function testImport() 77 public function testImport()
70 { 78 {
71 $wallabagV2Import = $this->getWallabagV2Import(); 79 $wallabagV2Import = $this->getWallabagV2Import(false, 2);
72 $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); 80 $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json');
73 81
74 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 82 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@@ -97,7 +105,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
97 105
98 public function testImportAndMarkAllAsRead() 106 public function testImportAndMarkAllAsRead()
99 { 107 {
100 $wallabagV2Import = $this->getWallabagV2Import(); 108 $wallabagV2Import = $this->getWallabagV2Import(false, 2);
101 $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2-read.json'); 109 $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2-read.json');
102 110
103 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 111 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@@ -246,7 +254,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
246 254
247 public function testImportWithExceptionFromGraby() 255 public function testImportWithExceptionFromGraby()
248 { 256 {
249 $wallabagV2Import = $this->getWallabagV2Import(); 257 $wallabagV2Import = $this->getWallabagV2Import(false, 2);
250 $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); 258 $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json');
251 259
252 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 260 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')