Add entry.saved event to import & rest

This commit is contained in:
Jeremy Benoist 2016-11-02 07:10:23 +01:00
parent e0597476d1
commit 7816eb622d
No known key found for this signature in database
GPG key ID: BCA73962457ACC3C
17 changed files with 222 additions and 49 deletions

View file

@ -14,6 +14,8 @@ use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\CoreBundle\Entity\Tag; use Wallabag\CoreBundle\Entity\Tag;
use Wallabag\AnnotationBundle\Entity\Annotation; use Wallabag\AnnotationBundle\Entity\Annotation;
use Wallabag\CoreBundle\Event\EntrySavedEvent;
use Wallabag\CoreBundle\Event\EntryDeletedEvent;
class WallabagRestController extends FOSRestController class WallabagRestController extends FOSRestController
{ {
@ -233,9 +235,11 @@ class WallabagRestController extends FOSRestController
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$em->persist($entry); $em->persist($entry);
$em->flush(); $em->flush();
// entry saved, dispatch event about it!
$this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
$json = $this->get('serializer')->serialize($entry, 'json'); $json = $this->get('serializer')->serialize($entry, 'json');
return (new JsonResponse())->setJson($json); return (new JsonResponse())->setJson($json);
@ -308,6 +312,9 @@ class WallabagRestController extends FOSRestController
$this->validateAuthentication(); $this->validateAuthentication();
$this->validateUserAccess($entry->getUser()->getId()); $this->validateUserAccess($entry->getUser()->getId());
// entry deleted, dispatch event about it!
$this->get('event_dispatcher')->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry));
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$em->remove($entry); $em->remove($entry);
$em->flush(); $em->flush();

View file

@ -9,6 +9,8 @@ use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\CoreBundle\Entity\Tag; use Wallabag\CoreBundle\Entity\Tag;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger; use Psr\Log\NullLogger;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Wallabag\CoreBundle\Event\EntrySavedEvent;
abstract class AbstractConsumer abstract class AbstractConsumer
{ {
@ -17,11 +19,12 @@ abstract class AbstractConsumer
protected $import; protected $import;
protected $logger; protected $logger;
public function __construct(EntityManager $em, UserRepository $userRepository, AbstractImport $import, LoggerInterface $logger = null) public function __construct(EntityManager $em, UserRepository $userRepository, AbstractImport $import, EventDispatcherInterface $eventDispatcher, LoggerInterface $logger = null)
{ {
$this->em = $em; $this->em = $em;
$this->userRepository = $userRepository; $this->userRepository = $userRepository;
$this->import = $import; $this->import = $import;
$this->eventDispatcher = $eventDispatcher;
$this->logger = $logger ?: new NullLogger(); $this->logger = $logger ?: new NullLogger();
} }
@ -59,6 +62,9 @@ abstract class AbstractConsumer
try { try {
$this->em->flush(); $this->em->flush();
// entry saved, dispatch event about it!
$this->eventDispatcher->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
// clear only affected entities // clear only affected entities
$this->em->clear(Entry::class); $this->em->clear(Entry::class);
$this->em->clear(Tag::class); $this->em->clear(Tag::class);

View file

@ -10,12 +10,15 @@ use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\CoreBundle\Entity\Tag; use Wallabag\CoreBundle\Entity\Tag;
use Wallabag\UserBundle\Entity\User; use Wallabag\UserBundle\Entity\User;
use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface; use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Wallabag\CoreBundle\Event\EntrySavedEvent;
abstract class AbstractImport implements ImportInterface abstract class AbstractImport implements ImportInterface
{ {
protected $em; protected $em;
protected $logger; protected $logger;
protected $contentProxy; protected $contentProxy;
protected $eventDispatcher;
protected $producer; protected $producer;
protected $user; protected $user;
protected $markAsRead; protected $markAsRead;
@ -23,11 +26,12 @@ abstract class AbstractImport implements ImportInterface
protected $importedEntries = 0; protected $importedEntries = 0;
protected $queuedEntries = 0; protected $queuedEntries = 0;
public function __construct(EntityManager $em, ContentProxy $contentProxy) public function __construct(EntityManager $em, ContentProxy $contentProxy, EventDispatcherInterface $eventDispatcher)
{ {
$this->em = $em; $this->em = $em;
$this->logger = new NullLogger(); $this->logger = new NullLogger();
$this->contentProxy = $contentProxy; $this->contentProxy = $contentProxy;
$this->eventDispatcher = $eventDispatcher;
} }
public function setLogger(LoggerInterface $logger) public function setLogger(LoggerInterface $logger)
@ -104,6 +108,7 @@ abstract class AbstractImport implements ImportInterface
protected function parseEntries($entries) protected function parseEntries($entries)
{ {
$i = 1; $i = 1;
$entryToBeFlushed = [];
foreach ($entries as $importedEntry) { foreach ($entries as $importedEntry) {
if ($this->markAsRead) { if ($this->markAsRead) {
@ -116,10 +121,21 @@ abstract class AbstractImport implements ImportInterface
continue; continue;
} }
// store each entry to be flushed so we can trigger the entry.saved event for each of them
// entry.saved needs the entry to be persisted in db because it needs it id to generate
// images (at least)
$entryToBeFlushed[] = $entry;
// flush every 20 entries // flush every 20 entries
if (($i % 20) === 0) { if (($i % 20) === 0) {
$this->em->flush(); $this->em->flush();
foreach ($entryToBeFlushed as $entry) {
$this->eventDispatcher->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
}
$entryToBeFlushed = [];
// clear only affected entities // clear only affected entities
$this->em->clear(Entry::class); $this->em->clear(Entry::class);
$this->em->clear(Tag::class); $this->em->clear(Tag::class);
@ -128,6 +144,12 @@ abstract class AbstractImport implements ImportInterface
} }
$this->em->flush(); $this->em->flush();
if (!empty($entryToBeFlushed)) {
foreach ($entryToBeFlushed as $entry) {
$this->eventDispatcher->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
}
}
} }
/** /**

View file

@ -5,6 +5,7 @@ namespace Wallabag\ImportBundle\Import;
use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\UserBundle\Entity\User; use Wallabag\UserBundle\Entity\User;
use Wallabag\CoreBundle\Helper\ContentProxy; use Wallabag\CoreBundle\Helper\ContentProxy;
use Wallabag\CoreBundle\Event\EntrySavedEvent;
abstract class BrowserImport extends AbstractImport abstract class BrowserImport extends AbstractImport
{ {
@ -81,6 +82,7 @@ abstract class BrowserImport extends AbstractImport
protected function parseEntries($entries) protected function parseEntries($entries)
{ {
$i = 1; $i = 1;
$entryToBeFlushed = [];
foreach ($entries as $importedEntry) { foreach ($entries as $importedEntry) {
if ((array) $importedEntry !== $importedEntry) { if ((array) $importedEntry !== $importedEntry) {
@ -93,14 +95,29 @@ abstract class BrowserImport extends AbstractImport
continue; continue;
} }
// @see AbstractImport
$entryToBeFlushed[] = $entry;
// flush every 20 entries // flush every 20 entries
if (($i % 20) === 0) { if (($i % 20) === 0) {
$this->em->flush(); $this->em->flush();
foreach ($entryToBeFlushed as $entry) {
$this->eventDispatcher->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
}
$entryToBeFlushed = [];
} }
++$i; ++$i;
} }
$this->em->flush(); $this->em->flush();
if (!empty($entryToBeFlushed)) {
foreach ($entryToBeFlushed as $entry) {
$this->eventDispatcher->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
}
}
} }
/** /**

View file

@ -16,13 +16,6 @@ class PocketImport extends AbstractImport
const NB_ELEMENTS = 5000; const NB_ELEMENTS = 5000;
public function __construct(EntityManager $em, ContentProxy $contentProxy)
{
$this->em = $em;
$this->contentProxy = $contentProxy;
$this->logger = new NullLogger();
}
/** /**
* Only used for test purpose. * Only used for test purpose.
* *

View file

@ -6,6 +6,7 @@ services:
- "@doctrine.orm.entity_manager" - "@doctrine.orm.entity_manager"
- "@wallabag_user.user_repository" - "@wallabag_user.user_repository"
- "@wallabag_import.pocket.import" - "@wallabag_import.pocket.import"
- "@event_dispatcher"
- "@logger" - "@logger"
wallabag_import.consumer.amqp.readability: wallabag_import.consumer.amqp.readability:
class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer
@ -13,6 +14,7 @@ services:
- "@doctrine.orm.entity_manager" - "@doctrine.orm.entity_manager"
- "@wallabag_user.user_repository" - "@wallabag_user.user_repository"
- "@wallabag_import.readability.import" - "@wallabag_import.readability.import"
- "@event_dispatcher"
- "@logger" - "@logger"
wallabag_import.consumer.amqp.instapaper: wallabag_import.consumer.amqp.instapaper:
class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer
@ -20,6 +22,7 @@ services:
- "@doctrine.orm.entity_manager" - "@doctrine.orm.entity_manager"
- "@wallabag_user.user_repository" - "@wallabag_user.user_repository"
- "@wallabag_import.instapaper.import" - "@wallabag_import.instapaper.import"
- "@event_dispatcher"
- "@logger" - "@logger"
wallabag_import.consumer.amqp.wallabag_v1: wallabag_import.consumer.amqp.wallabag_v1:
class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer
@ -27,6 +30,7 @@ services:
- "@doctrine.orm.entity_manager" - "@doctrine.orm.entity_manager"
- "@wallabag_user.user_repository" - "@wallabag_user.user_repository"
- "@wallabag_import.wallabag_v1.import" - "@wallabag_import.wallabag_v1.import"
- "@event_dispatcher"
- "@logger" - "@logger"
wallabag_import.consumer.amqp.wallabag_v2: wallabag_import.consumer.amqp.wallabag_v2:
class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer
@ -34,6 +38,7 @@ services:
- "@doctrine.orm.entity_manager" - "@doctrine.orm.entity_manager"
- "@wallabag_user.user_repository" - "@wallabag_user.user_repository"
- "@wallabag_import.wallabag_v2.import" - "@wallabag_import.wallabag_v2.import"
- "@event_dispatcher"
- "@logger" - "@logger"
wallabag_import.consumer.amqp.firefox: wallabag_import.consumer.amqp.firefox:
class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer
@ -41,6 +46,7 @@ services:
- "@doctrine.orm.entity_manager" - "@doctrine.orm.entity_manager"
- "@wallabag_user.user_repository" - "@wallabag_user.user_repository"
- "@wallabag_import.firefox.import" - "@wallabag_import.firefox.import"
- "@event_dispatcher"
- "@logger" - "@logger"
wallabag_import.consumer.amqp.chrome: wallabag_import.consumer.amqp.chrome:
class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer
@ -48,4 +54,5 @@ services:
- "@doctrine.orm.entity_manager" - "@doctrine.orm.entity_manager"
- "@wallabag_user.user_repository" - "@wallabag_user.user_repository"
- "@wallabag_import.chrome.import" - "@wallabag_import.chrome.import"
- "@event_dispatcher"
- "@logger" - "@logger"

View file

@ -18,6 +18,7 @@ services:
- "@doctrine.orm.entity_manager" - "@doctrine.orm.entity_manager"
- "@wallabag_user.user_repository" - "@wallabag_user.user_repository"
- "@wallabag_import.readability.import" - "@wallabag_import.readability.import"
- "@event_dispatcher"
- "@logger" - "@logger"
# instapaper # instapaper
@ -38,6 +39,7 @@ services:
- "@doctrine.orm.entity_manager" - "@doctrine.orm.entity_manager"
- "@wallabag_user.user_repository" - "@wallabag_user.user_repository"
- "@wallabag_import.instapaper.import" - "@wallabag_import.instapaper.import"
- "@event_dispatcher"
- "@logger" - "@logger"
# pocket # pocket
@ -58,6 +60,7 @@ services:
- "@doctrine.orm.entity_manager" - "@doctrine.orm.entity_manager"
- "@wallabag_user.user_repository" - "@wallabag_user.user_repository"
- "@wallabag_import.pocket.import" - "@wallabag_import.pocket.import"
- "@event_dispatcher"
- "@logger" - "@logger"
# wallabag v1 # wallabag v1
@ -78,6 +81,7 @@ services:
- "@doctrine.orm.entity_manager" - "@doctrine.orm.entity_manager"
- "@wallabag_user.user_repository" - "@wallabag_user.user_repository"
- "@wallabag_import.wallabag_v1.import" - "@wallabag_import.wallabag_v1.import"
- "@event_dispatcher"
- "@logger" - "@logger"
# wallabag v2 # wallabag v2
@ -98,6 +102,7 @@ services:
- "@doctrine.orm.entity_manager" - "@doctrine.orm.entity_manager"
- "@wallabag_user.user_repository" - "@wallabag_user.user_repository"
- "@wallabag_import.wallabag_v2.import" - "@wallabag_import.wallabag_v2.import"
- "@event_dispatcher"
- "@logger" - "@logger"
# firefox # firefox
@ -118,6 +123,7 @@ services:
- "@doctrine.orm.entity_manager" - "@doctrine.orm.entity_manager"
- "@wallabag_user.user_repository" - "@wallabag_user.user_repository"
- "@wallabag_import.firefox.import" - "@wallabag_import.firefox.import"
- "@event_dispatcher"
- "@logger" - "@logger"
# chrome # chrome
@ -138,4 +144,5 @@ services:
- "@doctrine.orm.entity_manager" - "@doctrine.orm.entity_manager"
- "@wallabag_user.user_repository" - "@wallabag_user.user_repository"
- "@wallabag_import.chrome.import" - "@wallabag_import.chrome.import"
- "@event_dispatcher"
- "@logger" - "@logger"

View file

@ -20,6 +20,7 @@ services:
arguments: arguments:
- "@doctrine.orm.entity_manager" - "@doctrine.orm.entity_manager"
- "@wallabag_core.content_proxy" - "@wallabag_core.content_proxy"
- "@event_dispatcher"
calls: calls:
- [ setClient, [ "@wallabag_import.pocket.client" ] ] - [ setClient, [ "@wallabag_import.pocket.client" ] ]
- [ setLogger, [ "@logger" ]] - [ setLogger, [ "@logger" ]]
@ -31,6 +32,7 @@ services:
arguments: arguments:
- "@doctrine.orm.entity_manager" - "@doctrine.orm.entity_manager"
- "@wallabag_core.content_proxy" - "@wallabag_core.content_proxy"
- "@event_dispatcher"
calls: calls:
- [ setLogger, [ "@logger" ]] - [ setLogger, [ "@logger" ]]
tags: tags:
@ -41,6 +43,7 @@ services:
arguments: arguments:
- "@doctrine.orm.entity_manager" - "@doctrine.orm.entity_manager"
- "@wallabag_core.content_proxy" - "@wallabag_core.content_proxy"
- "@event_dispatcher"
calls: calls:
- [ setLogger, [ "@logger" ]] - [ setLogger, [ "@logger" ]]
tags: tags:
@ -51,6 +54,7 @@ services:
arguments: arguments:
- "@doctrine.orm.entity_manager" - "@doctrine.orm.entity_manager"
- "@wallabag_core.content_proxy" - "@wallabag_core.content_proxy"
- "@event_dispatcher"
calls: calls:
- [ setLogger, [ "@logger" ]] - [ setLogger, [ "@logger" ]]
tags: tags:
@ -61,6 +65,7 @@ services:
arguments: arguments:
- "@doctrine.orm.entity_manager" - "@doctrine.orm.entity_manager"
- "@wallabag_core.content_proxy" - "@wallabag_core.content_proxy"
- "@event_dispatcher"
calls: calls:
- [ setLogger, [ "@logger" ]] - [ setLogger, [ "@logger" ]]
tags: tags:
@ -71,6 +76,7 @@ services:
arguments: arguments:
- "@doctrine.orm.entity_manager" - "@doctrine.orm.entity_manager"
- "@wallabag_core.content_proxy" - "@wallabag_core.content_proxy"
- "@event_dispatcher"
calls: calls:
- [ setLogger, [ "@logger" ]] - [ setLogger, [ "@logger" ]]
tags: tags:
@ -80,6 +86,7 @@ services:
arguments: arguments:
- "@doctrine.orm.entity_manager" - "@doctrine.orm.entity_manager"
- "@wallabag_core.content_proxy" - "@wallabag_core.content_proxy"
- "@event_dispatcher"
calls: calls:
- [ setLogger, [ "@logger" ]] - [ setLogger, [ "@logger" ]]
tags: tags:

View file

@ -112,10 +112,19 @@ JSON;
->with(json_decode($body, true)) ->with(json_decode($body, true))
->willReturn($entry); ->willReturn($entry);
$dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
->disableOriginalConstructor()
->getMock();
$dispatcher
->expects($this->once())
->method('dispatch');
$consumer = new AMQPEntryConsumer( $consumer = new AMQPEntryConsumer(
$em, $em,
$userRepository, $userRepository,
$import $import,
$dispatcher
); );
$message = new AMQPMessage($body); $message = new AMQPMessage($body);
@ -157,10 +166,19 @@ JSON;
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
->disableOriginalConstructor()
->getMock();
$dispatcher
->expects($this->never())
->method('dispatch');
$consumer = new AMQPEntryConsumer( $consumer = new AMQPEntryConsumer(
$em, $em,
$userRepository, $userRepository,
$import $import,
$dispatcher
); );
$message = new AMQPMessage($body); $message = new AMQPMessage($body);
@ -212,10 +230,19 @@ JSON;
->with(json_decode($body, true)) ->with(json_decode($body, true))
->willReturn(null); ->willReturn(null);
$dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
->disableOriginalConstructor()
->getMock();
$dispatcher
->expects($this->never())
->method('dispatch');
$consumer = new AMQPEntryConsumer( $consumer = new AMQPEntryConsumer(
$em, $em,
$userRepository, $userRepository,
$import $import,
$dispatcher
); );
$message = new AMQPMessage($body); $message = new AMQPMessage($body);

View file

@ -111,10 +111,19 @@ JSON;
->with(json_decode($body, true)) ->with(json_decode($body, true))
->willReturn($entry); ->willReturn($entry);
$dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
->disableOriginalConstructor()
->getMock();
$dispatcher
->expects($this->once())
->method('dispatch');
$consumer = new RedisEntryConsumer( $consumer = new RedisEntryConsumer(
$em, $em,
$userRepository, $userRepository,
$import $import,
$dispatcher
); );
$res = $consumer->manage($body); $res = $consumer->manage($body);
@ -156,10 +165,19 @@ JSON;
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
->disableOriginalConstructor()
->getMock();
$dispatcher
->expects($this->never())
->method('dispatch');
$consumer = new RedisEntryConsumer( $consumer = new RedisEntryConsumer(
$em, $em,
$userRepository, $userRepository,
$import $import,
$dispatcher
); );
$res = $consumer->manage($body); $res = $consumer->manage($body);
@ -211,10 +229,19 @@ JSON;
->with(json_decode($body, true)) ->with(json_decode($body, true))
->willReturn(null); ->willReturn(null);
$dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
->disableOriginalConstructor()
->getMock();
$dispatcher
->expects($this->never())
->method('dispatch');
$consumer = new RedisEntryConsumer( $consumer = new RedisEntryConsumer(
$em, $em,
$userRepository, $userRepository,
$import $import,
$dispatcher
); );
$res = $consumer->manage($body); $res = $consumer->manage($body);

View file

@ -18,7 +18,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
protected $logHandler; protected $logHandler;
protected $contentProxy; protected $contentProxy;
private function getChromeImport($unsetUser = false) private function getChromeImport($unsetUser = false, $dispatched = 0)
{ {
$this->user = new User(); $this->user = new User();
@ -30,7 +30,15 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$wallabag = new ChromeImport($this->em, $this->contentProxy); $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
->disableOriginalConstructor()
->getMock();
$dispatcher
->expects($this->exactly($dispatched))
->method('dispatch');
$wallabag = new ChromeImport($this->em, $this->contentProxy, $dispatcher);
$this->logHandler = new TestHandler(); $this->logHandler = new TestHandler();
$logger = new Logger('test', [$this->logHandler]); $logger = new Logger('test', [$this->logHandler]);
@ -54,7 +62,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
public function testImport() public function testImport()
{ {
$chromeImport = $this->getChromeImport(); $chromeImport = $this->getChromeImport(false, 1);
$chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks');
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@ -87,7 +95,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
public function testImportAndMarkAllAsRead() public function testImportAndMarkAllAsRead()
{ {
$chromeImport = $this->getChromeImport(); $chromeImport = $this->getChromeImport(false, 1);
$chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks');
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')

View file

@ -18,7 +18,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
protected $logHandler; protected $logHandler;
protected $contentProxy; protected $contentProxy;
private function getFirefoxImport($unsetUser = false) private function getFirefoxImport($unsetUser = false, $dispatched = 0)
{ {
$this->user = new User(); $this->user = new User();
@ -30,7 +30,15 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$wallabag = new FirefoxImport($this->em, $this->contentProxy); $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
->disableOriginalConstructor()
->getMock();
$dispatcher
->expects($this->exactly($dispatched))
->method('dispatch');
$wallabag = new FirefoxImport($this->em, $this->contentProxy, $dispatcher);
$this->logHandler = new TestHandler(); $this->logHandler = new TestHandler();
$logger = new Logger('test', [$this->logHandler]); $logger = new Logger('test', [$this->logHandler]);
@ -54,7 +62,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
public function testImport() public function testImport()
{ {
$firefoxImport = $this->getFirefoxImport(); $firefoxImport = $this->getFirefoxImport(false, 2);
$firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json');
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@ -87,7 +95,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
public function testImportAndMarkAllAsRead() public function testImportAndMarkAllAsRead()
{ {
$firefoxImport = $this->getFirefoxImport(); $firefoxImport = $this->getFirefoxImport(false, 1);
$firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json');
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')

View file

@ -18,7 +18,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
protected $logHandler; protected $logHandler;
protected $contentProxy; protected $contentProxy;
private function getInstapaperImport($unsetUser = false) private function getInstapaperImport($unsetUser = false, $dispatched = 0)
{ {
$this->user = new User(); $this->user = new User();
@ -30,7 +30,15 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$import = new InstapaperImport($this->em, $this->contentProxy); $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
->disableOriginalConstructor()
->getMock();
$dispatcher
->expects($this->exactly($dispatched))
->method('dispatch');
$import = new InstapaperImport($this->em, $this->contentProxy, $dispatcher);
$this->logHandler = new TestHandler(); $this->logHandler = new TestHandler();
$logger = new Logger('test', [$this->logHandler]); $logger = new Logger('test', [$this->logHandler]);
@ -54,7 +62,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
public function testImport() public function testImport()
{ {
$instapaperImport = $this->getInstapaperImport(); $instapaperImport = $this->getInstapaperImport(false, 3);
$instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv');
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@ -87,7 +95,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
public function testImportAndMarkAllAsRead() public function testImportAndMarkAllAsRead()
{ {
$instapaperImport = $this->getInstapaperImport(); $instapaperImport = $this->getInstapaperImport(false, 1);
$instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv');
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')

View file

@ -24,7 +24,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
protected $contentProxy; protected $contentProxy;
protected $logHandler; protected $logHandler;
private function getPocketImport($consumerKey = 'ConsumerKey') private function getPocketImport($consumerKey = 'ConsumerKey', $dispatched = 0)
{ {
$this->user = new User(); $this->user = new User();
@ -55,10 +55,15 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
->method('getScheduledEntityInsertions') ->method('getScheduledEntityInsertions')
->willReturn([]); ->willReturn([]);
$pocket = new PocketImport( $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
$this->em, ->disableOriginalConstructor()
$this->contentProxy ->getMock();
);
$dispatcher
->expects($this->exactly($dispatched))
->method('dispatch');
$pocket = new PocketImport($this->em, $this->contentProxy, $dispatcher);
$pocket->setUser($this->user); $pocket->setUser($this->user);
$this->logHandler = new TestHandler(); $this->logHandler = new TestHandler();
@ -252,7 +257,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
$client->getEmitter()->attach($mock); $client->getEmitter()->attach($mock);
$pocketImport = $this->getPocketImport(); $pocketImport = $this->getPocketImport('ConsumerKey', 1);
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
->disableOriginalConstructor() ->disableOriginalConstructor()
@ -339,7 +344,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
$client->getEmitter()->attach($mock); $client->getEmitter()->attach($mock);
$pocketImport = $this->getPocketImport(); $pocketImport = $this->getPocketImport('ConsumerKey', 2);
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
->disableOriginalConstructor() ->disableOriginalConstructor()
@ -591,7 +596,7 @@ JSON;
$client->getEmitter()->attach($mock); $client->getEmitter()->attach($mock);
$pocketImport = $this->getPocketImport(); $pocketImport = $this->getPocketImport('ConsumerKey', 1);
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
->disableOriginalConstructor() ->disableOriginalConstructor()

View file

@ -18,7 +18,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
protected $logHandler; protected $logHandler;
protected $contentProxy; protected $contentProxy;
private function getReadabilityImport($unsetUser = false) private function getReadabilityImport($unsetUser = false, $dispatched = 0)
{ {
$this->user = new User(); $this->user = new User();
@ -30,7 +30,15 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$wallabag = new ReadabilityImport($this->em, $this->contentProxy); $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
->disableOriginalConstructor()
->getMock();
$dispatcher
->expects($this->exactly($dispatched))
->method('dispatch');
$wallabag = new ReadabilityImport($this->em, $this->contentProxy, $dispatcher);
$this->logHandler = new TestHandler(); $this->logHandler = new TestHandler();
$logger = new Logger('test', [$this->logHandler]); $logger = new Logger('test', [$this->logHandler]);
@ -54,7 +62,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
public function testImport() public function testImport()
{ {
$readabilityImport = $this->getReadabilityImport(); $readabilityImport = $this->getReadabilityImport(false, 24);
$readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json');
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@ -87,7 +95,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
public function testImportAndMarkAllAsRead() public function testImportAndMarkAllAsRead()
{ {
$readabilityImport = $this->getReadabilityImport(); $readabilityImport = $this->getReadabilityImport(false, 1);
$readabilityImport->setFilepath(__DIR__.'/../fixtures/readability-read.json'); $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability-read.json');
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')

View file

@ -18,7 +18,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
protected $logHandler; protected $logHandler;
protected $contentProxy; protected $contentProxy;
private function getWallabagV1Import($unsetUser = false) private function getWallabagV1Import($unsetUser = false, $dispatched = 0)
{ {
$this->user = new User(); $this->user = new User();
@ -44,7 +44,15 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$wallabag = new WallabagV1Import($this->em, $this->contentProxy); $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
->disableOriginalConstructor()
->getMock();
$dispatcher
->expects($this->exactly($dispatched))
->method('dispatch');
$wallabag = new WallabagV1Import($this->em, $this->contentProxy, $dispatcher);
$this->logHandler = new TestHandler(); $this->logHandler = new TestHandler();
$logger = new Logger('test', [$this->logHandler]); $logger = new Logger('test', [$this->logHandler]);
@ -68,7 +76,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
public function testImport() public function testImport()
{ {
$wallabagV1Import = $this->getWallabagV1Import(); $wallabagV1Import = $this->getWallabagV1Import(false, 3);
$wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json');
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@ -101,7 +109,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
public function testImportAndMarkAllAsRead() public function testImportAndMarkAllAsRead()
{ {
$wallabagV1Import = $this->getWallabagV1Import(); $wallabagV1Import = $this->getWallabagV1Import(false, 3);
$wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1-read.json'); $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1-read.json');
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')

View file

@ -18,7 +18,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
protected $logHandler; protected $logHandler;
protected $contentProxy; protected $contentProxy;
private function getWallabagV2Import($unsetUser = false) private function getWallabagV2Import($unsetUser = false, $dispatched = 0)
{ {
$this->user = new User(); $this->user = new User();
@ -44,7 +44,15 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$wallabag = new WallabagV2Import($this->em, $this->contentProxy); $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
->disableOriginalConstructor()
->getMock();
$dispatcher
->expects($this->exactly($dispatched))
->method('dispatch');
$wallabag = new WallabagV2Import($this->em, $this->contentProxy, $dispatcher);
$this->logHandler = new TestHandler(); $this->logHandler = new TestHandler();
$logger = new Logger('test', [$this->logHandler]); $logger = new Logger('test', [$this->logHandler]);
@ -68,7 +76,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
public function testImport() public function testImport()
{ {
$wallabagV2Import = $this->getWallabagV2Import(); $wallabagV2Import = $this->getWallabagV2Import(false, 2);
$wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json');
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@ -97,7 +105,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
public function testImportAndMarkAllAsRead() public function testImportAndMarkAllAsRead()
{ {
$wallabagV2Import = $this->getWallabagV2Import(); $wallabagV2Import = $this->getWallabagV2Import(false, 2);
$wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2-read.json'); $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2-read.json');
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@ -246,7 +254,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
public function testImportWithExceptionFromGraby() public function testImportWithExceptionFromGraby()
{ {
$wallabagV2Import = $this->getWallabagV2Import(); $wallabagV2Import = $this->getWallabagV2Import(false, 2);
$wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json');
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')