mirror of
https://github.com/wallabag/wallabag.git
synced 2025-09-15 18:57:05 +00:00
Enable Redis async import
- using javibravo/simpleue - internal config value are now `import_with_redis` & `import_with_rabbit` which are more clear - if both option are enable rabbit will be choosen - services imports related to async are now splitted into 2 files: `redis.yml` & `rabbit.yml` -
This commit is contained in:
parent
7f7531171f
commit
b3437d58ae
28 changed files with 846 additions and 68 deletions
|
@ -2,12 +2,12 @@
|
|||
|
||||
namespace Tests\Wallabag\ImportBundle\Consumer\AMQP;
|
||||
|
||||
use Wallabag\ImportBundle\Consumer\AMPQ\EntryConsumer;
|
||||
use Wallabag\ImportBundle\Consumer\AMPQEntryConsumer;
|
||||
use PhpAmqpLib\Message\AMQPMessage;
|
||||
use Wallabag\UserBundle\Entity\User;
|
||||
use Wallabag\CoreBundle\Entity\Entry;
|
||||
|
||||
class EntryConsumerTest extends \PHPUnit_Framework_TestCase
|
||||
class AMPQEntryConsumerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testMessageOk()
|
||||
{
|
||||
|
@ -112,7 +112,7 @@ JSON;
|
|||
->with(json_decode($body, true))
|
||||
->willReturn($entry);
|
||||
|
||||
$consumer = new EntryConsumer(
|
||||
$consumer = new AMPQEntryConsumer(
|
||||
$em,
|
||||
$userRepository,
|
||||
$import
|
||||
|
@ -157,7 +157,7 @@ JSON;
|
|||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$consumer = new EntryConsumer(
|
||||
$consumer = new AMPQEntryConsumer(
|
||||
$em,
|
||||
$userRepository,
|
||||
$import
|
||||
|
@ -212,7 +212,7 @@ JSON;
|
|||
->with(json_decode($body, true))
|
||||
->willReturn(null);
|
||||
|
||||
$consumer = new EntryConsumer(
|
||||
$consumer = new AMPQEntryConsumer(
|
||||
$em,
|
||||
$userRepository,
|
||||
$import
|
224
tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php
Normal file
224
tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php
Normal file
|
@ -0,0 +1,224 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Wallabag\ImportBundle\Consumer\AMQP;
|
||||
|
||||
use Wallabag\ImportBundle\Consumer\RedisEntryConsumer;
|
||||
use Wallabag\UserBundle\Entity\User;
|
||||
use Wallabag\CoreBundle\Entity\Entry;
|
||||
|
||||
class RedisEntryConsumerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testMessageOk()
|
||||
{
|
||||
$em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$em
|
||||
->expects($this->once())
|
||||
->method('flush');
|
||||
|
||||
$em
|
||||
->expects($this->exactly(2))
|
||||
->method('clear');
|
||||
|
||||
$body = <<<'JSON'
|
||||
{
|
||||
"item_id": "1402935436",
|
||||
"resolved_id": "1402935436",
|
||||
"given_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial",
|
||||
"given_title": "Leslie Jones is back on Twitter and her comeback tweet rules",
|
||||
"favorite": "0",
|
||||
"status": "0",
|
||||
"time_added": "1473020899",
|
||||
"time_updated": "1473020899",
|
||||
"time_read": "0",
|
||||
"time_favorited": "0",
|
||||
"sort_id": 0,
|
||||
"resolved_title": "Leslie Jones is back on Twitter and her comeback tweet rules",
|
||||
"resolved_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial",
|
||||
"excerpt": "Leslie Jones is back to communicating with her adoring public on Twitter after cowardly hacker-trolls drove her away, probably to compensate for their own failings. It all started with a mic drop ...",
|
||||
"is_article": "1",
|
||||
"is_index": "0",
|
||||
"has_video": "0",
|
||||
"has_image": "1",
|
||||
"word_count": "200",
|
||||
"tags": {
|
||||
"ifttt": {
|
||||
"item_id": "1402935436",
|
||||
"tag": "ifttt"
|
||||
},
|
||||
"mashable": {
|
||||
"item_id": "1402935436",
|
||||
"tag": "mashable"
|
||||
}
|
||||
},
|
||||
"authors": {
|
||||
"2484273": {
|
||||
"item_id": "1402935436",
|
||||
"author_id": "2484273",
|
||||
"name": "Adam Rosenberg",
|
||||
"url": "http://mashable.com/author/adam-rosenberg/"
|
||||
}
|
||||
},
|
||||
"image": {
|
||||
"item_id": "1402935436",
|
||||
"src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg",
|
||||
"width": "0",
|
||||
"height": "0"
|
||||
},
|
||||
"images": {
|
||||
"1": {
|
||||
"item_id": "1402935436",
|
||||
"image_id": "1",
|
||||
"src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg",
|
||||
"width": "0",
|
||||
"height": "0",
|
||||
"credit": "Image: Steve Eichner/NameFace/Sipa USA",
|
||||
"caption": ""
|
||||
}
|
||||
},
|
||||
"userId": 1
|
||||
}
|
||||
JSON;
|
||||
|
||||
$user = new User();
|
||||
$entry = new Entry($user);
|
||||
|
||||
$userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$userRepository
|
||||
->expects($this->once())
|
||||
->method('find')
|
||||
// userId from the body json above
|
||||
->with(1)
|
||||
->willReturn($user);
|
||||
|
||||
$import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$import
|
||||
->expects($this->once())
|
||||
->method('setUser')
|
||||
->with($user);
|
||||
|
||||
$import
|
||||
->expects($this->once())
|
||||
->method('parseEntry')
|
||||
->with(json_decode($body, true))
|
||||
->willReturn($entry);
|
||||
|
||||
$consumer = new RedisEntryConsumer(
|
||||
$em,
|
||||
$userRepository,
|
||||
$import
|
||||
);
|
||||
|
||||
$res = $consumer->manage($body);
|
||||
|
||||
$this->assertTrue($res);
|
||||
}
|
||||
|
||||
public function testMessageWithBadUser()
|
||||
{
|
||||
$em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$em
|
||||
->expects($this->never())
|
||||
->method('flush');
|
||||
|
||||
$em
|
||||
->expects($this->never())
|
||||
->method('clear');
|
||||
|
||||
$body = '{ "userId": 123 }';
|
||||
|
||||
$user = new User();
|
||||
$entry = new Entry($user);
|
||||
|
||||
$userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$userRepository
|
||||
->expects($this->once())
|
||||
->method('find')
|
||||
// userId from the body json above
|
||||
->with(123)
|
||||
->willReturn(null);
|
||||
|
||||
$import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$consumer = new RedisEntryConsumer(
|
||||
$em,
|
||||
$userRepository,
|
||||
$import
|
||||
);
|
||||
|
||||
$res = $consumer->manage($body);
|
||||
|
||||
$this->assertFalse($res);
|
||||
}
|
||||
|
||||
public function testMessageWithEntryProcessed()
|
||||
{
|
||||
$em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$em
|
||||
->expects($this->never())
|
||||
->method('flush');
|
||||
|
||||
$em
|
||||
->expects($this->never())
|
||||
->method('clear');
|
||||
|
||||
$body = '{ "userId": 123 }';
|
||||
|
||||
$user = new User();
|
||||
|
||||
$userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$userRepository
|
||||
->expects($this->once())
|
||||
->method('find')
|
||||
// userId from the body json above
|
||||
->with(123)
|
||||
->willReturn($user);
|
||||
|
||||
$import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$import
|
||||
->expects($this->once())
|
||||
->method('setUser')
|
||||
->with($user);
|
||||
|
||||
$import
|
||||
->expects($this->once())
|
||||
->method('parseEntry')
|
||||
->with(json_decode($body, true))
|
||||
->willReturn(null);
|
||||
|
||||
$consumer = new RedisEntryConsumer(
|
||||
$em,
|
||||
$userRepository,
|
||||
$import
|
||||
);
|
||||
|
||||
$res = $consumer->manage($body);
|
||||
|
||||
$this->assertFalse($res);
|
||||
}
|
||||
}
|
|
@ -22,14 +22,29 @@ class PocketControllerTest extends WallabagCoreTestCase
|
|||
$this->logInAs('admin');
|
||||
$client = $this->getClient();
|
||||
|
||||
$client->getContainer()->get('craue_config')->set('rabbitmq', 1);
|
||||
$client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1);
|
||||
|
||||
$crawler = $client->request('GET', '/import/pocket');
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
||||
$this->assertEquals(1, $crawler->filter('button[type=submit]')->count());
|
||||
|
||||
$client->getContainer()->get('craue_config')->set('rabbitmq', 0);
|
||||
$client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0);
|
||||
}
|
||||
|
||||
public function testImportPocketWithRedisEnabled()
|
||||
{
|
||||
$this->logInAs('admin');
|
||||
$client = $this->getClient();
|
||||
|
||||
$client->getContainer()->get('craue_config')->set('import_with_redis', 1);
|
||||
|
||||
$crawler = $client->request('GET', '/import/pocket');
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
||||
$this->assertEquals(1, $crawler->filter('button[type=submit]')->count());
|
||||
|
||||
$client->getContainer()->get('craue_config')->set('import_with_redis', 0);
|
||||
}
|
||||
|
||||
public function testImportPocketAuthBadToken()
|
||||
|
|
|
@ -24,7 +24,7 @@ class ReadabilityControllerTest extends WallabagCoreTestCase
|
|||
$this->logInAs('admin');
|
||||
$client = $this->getClient();
|
||||
|
||||
$client->getContainer()->get('craue_config')->set('rabbitmq', 1);
|
||||
$client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1);
|
||||
|
||||
$crawler = $client->request('GET', '/import/readability');
|
||||
|
||||
|
@ -32,7 +32,23 @@ class ReadabilityControllerTest extends WallabagCoreTestCase
|
|||
$this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
|
||||
$this->assertEquals(1, $crawler->filter('input[type=file]')->count());
|
||||
|
||||
$client->getContainer()->get('craue_config')->set('rabbitmq', 0);
|
||||
$client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0);
|
||||
}
|
||||
|
||||
public function testImportReadabilityWithRedisEnabled()
|
||||
{
|
||||
$this->logInAs('admin');
|
||||
$client = $this->getClient();
|
||||
|
||||
$client->getContainer()->get('craue_config')->set('import_with_redis', 1);
|
||||
|
||||
$crawler = $client->request('GET', '/import/readability');
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
||||
$this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
|
||||
$this->assertEquals(1, $crawler->filter('input[type=file]')->count());
|
||||
|
||||
$client->getContainer()->get('craue_config')->set('import_with_redis', 0);
|
||||
}
|
||||
|
||||
public function testImportReadabilityWithFile()
|
||||
|
|
|
@ -24,7 +24,7 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase
|
|||
$this->logInAs('admin');
|
||||
$client = $this->getClient();
|
||||
|
||||
$client->getContainer()->get('craue_config')->set('rabbitmq', 1);
|
||||
$client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1);
|
||||
|
||||
$crawler = $client->request('GET', '/import/wallabag-v1');
|
||||
|
||||
|
@ -32,7 +32,23 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase
|
|||
$this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
|
||||
$this->assertEquals(1, $crawler->filter('input[type=file]')->count());
|
||||
|
||||
$client->getContainer()->get('craue_config')->set('rabbitmq', 0);
|
||||
$client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0);
|
||||
}
|
||||
|
||||
public function testImportWallabagWithRedisEnabled()
|
||||
{
|
||||
$this->logInAs('admin');
|
||||
$client = $this->getClient();
|
||||
|
||||
$client->getContainer()->get('craue_config')->set('import_with_redis', 1);
|
||||
|
||||
$crawler = $client->request('GET', '/import/wallabag-v1');
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
||||
$this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
|
||||
$this->assertEquals(1, $crawler->filter('input[type=file]')->count());
|
||||
|
||||
$client->getContainer()->get('craue_config')->set('import_with_redis', 0);
|
||||
}
|
||||
|
||||
public function testImportWallabagWithFile()
|
||||
|
|
|
@ -24,7 +24,7 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase
|
|||
$this->logInAs('admin');
|
||||
$client = $this->getClient();
|
||||
|
||||
$client->getContainer()->get('craue_config')->set('rabbitmq', 1);
|
||||
$client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1);
|
||||
|
||||
$crawler = $client->request('GET', '/import/wallabag-v2');
|
||||
|
||||
|
@ -32,7 +32,23 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase
|
|||
$this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
|
||||
$this->assertEquals(1, $crawler->filter('input[type=file]')->count());
|
||||
|
||||
$client->getContainer()->get('craue_config')->set('rabbitmq', 0);
|
||||
$client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0);
|
||||
}
|
||||
|
||||
public function testImportWallabagWithRedisEnabled()
|
||||
{
|
||||
$this->logInAs('admin');
|
||||
$client = $this->getClient();
|
||||
|
||||
$client->getContainer()->get('craue_config')->set('import_with_redis', 1);
|
||||
|
||||
$crawler = $client->request('GET', '/import/wallabag-v2');
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
||||
$this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
|
||||
$this->assertEquals(1, $crawler->filter('input[type=file]')->count());
|
||||
|
||||
$client->getContainer()->get('craue_config')->set('import_with_redis', 0);
|
||||
}
|
||||
|
||||
public function testImportWallabagWithFile()
|
||||
|
|
|
@ -9,8 +9,11 @@ use GuzzleHttp\Client;
|
|||
use GuzzleHttp\Subscriber\Mock;
|
||||
use GuzzleHttp\Message\Response;
|
||||
use GuzzleHttp\Stream\Stream;
|
||||
use Wallabag\ImportBundle\Redis\Producer;
|
||||
use Monolog\Logger;
|
||||
use Monolog\Handler\TestHandler;
|
||||
use Simpleue\Queue\RedisQueue;
|
||||
use M6Web\Component\RedisMock\RedisMockFactory;
|
||||
|
||||
class PocketImportTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
@ -442,7 +445,7 @@ JSON;
|
|||
->with(json_encode($bodyAsArray));
|
||||
|
||||
$pocketImport->setClient($client);
|
||||
$pocketImport->setRabbitmqProducer($producer);
|
||||
$pocketImport->setProducer($producer);
|
||||
$pocketImport->authorize('wunderbar_code');
|
||||
|
||||
$res = $pocketImport->setMarkAsRead(true)->import();
|
||||
|
@ -451,6 +454,87 @@ JSON;
|
|||
$this->assertEquals(['skipped' => 0, 'imported' => 1], $pocketImport->getSummary());
|
||||
}
|
||||
|
||||
/**
|
||||
* Will sample results from https://getpocket.com/developer/docs/v3/retrieve.
|
||||
*/
|
||||
public function testImportWithRedis()
|
||||
{
|
||||
$client = new Client();
|
||||
|
||||
$body = <<<'JSON'
|
||||
{
|
||||
"item_id": "229279689",
|
||||
"resolved_id": "229279689",
|
||||
"given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview",
|
||||
"given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland",
|
||||
"favorite": "1",
|
||||
"status": "1",
|
||||
"time_added": "1473020899",
|
||||
"time_updated": "1473020899",
|
||||
"time_read": "0",
|
||||
"time_favorited": "0",
|
||||
"sort_id": 0,
|
||||
"resolved_title": "The Massive Ryder Cup Preview",
|
||||
"resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview",
|
||||
"excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.",
|
||||
"is_article": "1",
|
||||
"has_video": "0",
|
||||
"has_image": "0",
|
||||
"word_count": "3197"
|
||||
}
|
||||
JSON;
|
||||
|
||||
$mock = new Mock([
|
||||
new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))),
|
||||
new Response(200, ['Content-Type' => 'application/json'], Stream::factory('
|
||||
{
|
||||
"status": 1,
|
||||
"list": {
|
||||
"229279690": '.$body.'
|
||||
}
|
||||
}
|
||||
')),
|
||||
]);
|
||||
|
||||
$client->getEmitter()->attach($mock);
|
||||
|
||||
$pocketImport = $this->getPocketImport();
|
||||
|
||||
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$entryRepo->expects($this->never())
|
||||
->method('findByUrlAndUserId');
|
||||
|
||||
$this->em
|
||||
->expects($this->never())
|
||||
->method('getRepository');
|
||||
|
||||
$entry = new Entry($this->user);
|
||||
|
||||
$this->contentProxy
|
||||
->expects($this->never())
|
||||
->method('updateEntry');
|
||||
|
||||
$factory = new RedisMockFactory();
|
||||
$redisMock = $factory->getAdapter('Predis\Client', true);
|
||||
|
||||
$queue = new RedisQueue($redisMock, 'pocket');
|
||||
$producer = new Producer($queue);
|
||||
|
||||
$pocketImport->setClient($client);
|
||||
$pocketImport->setProducer($producer);
|
||||
$pocketImport->authorize('wunderbar_code');
|
||||
|
||||
$res = $pocketImport->setMarkAsRead(true)->import();
|
||||
|
||||
$this->assertTrue($res);
|
||||
$this->assertEquals(['skipped' => 0, 'imported' => 1], $pocketImport->getSummary());
|
||||
|
||||
$this->assertNotEmpty($redisMock->lpop('pocket'));
|
||||
}
|
||||
|
||||
public function testImportBadResponse()
|
||||
{
|
||||
$client = new Client();
|
||||
|
|
|
@ -5,8 +5,11 @@ namespace Tests\Wallabag\ImportBundle\Import;
|
|||
use Wallabag\ImportBundle\Import\ReadabilityImport;
|
||||
use Wallabag\UserBundle\Entity\User;
|
||||
use Wallabag\CoreBundle\Entity\Entry;
|
||||
use Wallabag\ImportBundle\Redis\Producer;
|
||||
use Monolog\Logger;
|
||||
use Monolog\Handler\TestHandler;
|
||||
use Simpleue\Queue\RedisQueue;
|
||||
use M6Web\Component\RedisMock\RedisMockFactory;
|
||||
|
||||
class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
@ -152,7 +155,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
|
|||
->expects($this->exactly(2))
|
||||
->method('publish');
|
||||
|
||||
$readabilityImport->setRabbitmqProducer($producer);
|
||||
$readabilityImport->setProducer($producer);
|
||||
|
||||
$res = $readabilityImport->setMarkAsRead(true)->import();
|
||||
|
||||
|
@ -160,6 +163,46 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(['skipped' => 0, 'imported' => 2], $readabilityImport->getSummary());
|
||||
}
|
||||
|
||||
public function testImportWithRedis()
|
||||
{
|
||||
$readabilityImport = $this->getReadabilityImport();
|
||||
$readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json');
|
||||
|
||||
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$entryRepo->expects($this->never())
|
||||
->method('findByUrlAndUserId');
|
||||
|
||||
$this->em
|
||||
->expects($this->never())
|
||||
->method('getRepository');
|
||||
|
||||
$entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->contentProxy
|
||||
->expects($this->never())
|
||||
->method('updateEntry');
|
||||
|
||||
$factory = new RedisMockFactory();
|
||||
$redisMock = $factory->getAdapter('Predis\Client', true);
|
||||
|
||||
$queue = new RedisQueue($redisMock, 'readability');
|
||||
$producer = new Producer($queue);
|
||||
|
||||
$readabilityImport->setProducer($producer);
|
||||
|
||||
$res = $readabilityImport->setMarkAsRead(true)->import();
|
||||
|
||||
$this->assertTrue($res);
|
||||
$this->assertEquals(['skipped' => 0, 'imported' => 2], $readabilityImport->getSummary());
|
||||
|
||||
$this->assertNotEmpty($redisMock->lpop('readability'));
|
||||
}
|
||||
|
||||
public function testImportBadFile()
|
||||
{
|
||||
$readabilityImport = $this->getReadabilityImport();
|
||||
|
|
|
@ -5,8 +5,11 @@ namespace Tests\Wallabag\ImportBundle\Import;
|
|||
use Wallabag\ImportBundle\Import\WallabagV1Import;
|
||||
use Wallabag\UserBundle\Entity\User;
|
||||
use Wallabag\CoreBundle\Entity\Entry;
|
||||
use Wallabag\ImportBundle\Redis\Producer;
|
||||
use Monolog\Logger;
|
||||
use Monolog\Handler\TestHandler;
|
||||
use Simpleue\Queue\RedisQueue;
|
||||
use M6Web\Component\RedisMock\RedisMockFactory;
|
||||
|
||||
class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
@ -152,7 +155,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
|
|||
->expects($this->exactly(4))
|
||||
->method('publish');
|
||||
|
||||
$wallabagV1Import->setRabbitmqProducer($producer);
|
||||
$wallabagV1Import->setProducer($producer);
|
||||
|
||||
$res = $wallabagV1Import->setMarkAsRead(true)->import();
|
||||
|
||||
|
@ -160,6 +163,46 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(['skipped' => 0, 'imported' => 4], $wallabagV1Import->getSummary());
|
||||
}
|
||||
|
||||
public function testImportWithRedis()
|
||||
{
|
||||
$wallabagV1Import = $this->getWallabagV1Import();
|
||||
$wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json');
|
||||
|
||||
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$entryRepo->expects($this->never())
|
||||
->method('findByUrlAndUserId');
|
||||
|
||||
$this->em
|
||||
->expects($this->never())
|
||||
->method('getRepository');
|
||||
|
||||
$entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->contentProxy
|
||||
->expects($this->never())
|
||||
->method('updateEntry');
|
||||
|
||||
$factory = new RedisMockFactory();
|
||||
$redisMock = $factory->getAdapter('Predis\Client', true);
|
||||
|
||||
$queue = new RedisQueue($redisMock, 'wallabag_v1');
|
||||
$producer = new Producer($queue);
|
||||
|
||||
$wallabagV1Import->setProducer($producer);
|
||||
|
||||
$res = $wallabagV1Import->setMarkAsRead(true)->import();
|
||||
|
||||
$this->assertTrue($res);
|
||||
$this->assertEquals(['skipped' => 0, 'imported' => 4], $wallabagV1Import->getSummary());
|
||||
|
||||
$this->assertNotEmpty($redisMock->lpop('wallabag_v1'));
|
||||
}
|
||||
|
||||
public function testImportBadFile()
|
||||
{
|
||||
$wallabagV1Import = $this->getWallabagV1Import();
|
||||
|
|
|
@ -5,8 +5,11 @@ namespace Tests\Wallabag\ImportBundle\Import;
|
|||
use Wallabag\ImportBundle\Import\WallabagV2Import;
|
||||
use Wallabag\UserBundle\Entity\User;
|
||||
use Wallabag\CoreBundle\Entity\Entry;
|
||||
use Wallabag\ImportBundle\Redis\Producer;
|
||||
use Monolog\Logger;
|
||||
use Monolog\Handler\TestHandler;
|
||||
use Simpleue\Queue\RedisQueue;
|
||||
use M6Web\Component\RedisMock\RedisMockFactory;
|
||||
|
||||
class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
@ -144,7 +147,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
|
|||
->expects($this->exactly(24))
|
||||
->method('publish');
|
||||
|
||||
$wallabagV2Import->setRabbitmqProducer($producer);
|
||||
$wallabagV2Import->setProducer($producer);
|
||||
|
||||
$res = $wallabagV2Import->setMarkAsRead(true)->import();
|
||||
|
||||
|
@ -152,6 +155,42 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(['skipped' => 0, 'imported' => 24], $wallabagV2Import->getSummary());
|
||||
}
|
||||
|
||||
public function testImportWithRedis()
|
||||
{
|
||||
$wallabagV2Import = $this->getWallabagV2Import();
|
||||
$wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json');
|
||||
|
||||
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$entryRepo->expects($this->never())
|
||||
->method('findByUrlAndUserId');
|
||||
|
||||
$this->em
|
||||
->expects($this->never())
|
||||
->method('getRepository');
|
||||
|
||||
$this->contentProxy
|
||||
->expects($this->never())
|
||||
->method('updateEntry');
|
||||
|
||||
$factory = new RedisMockFactory();
|
||||
$redisMock = $factory->getAdapter('Predis\Client', true);
|
||||
|
||||
$queue = new RedisQueue($redisMock, 'wallabag_v2');
|
||||
$producer = new Producer($queue);
|
||||
|
||||
$wallabagV2Import->setProducer($producer);
|
||||
|
||||
$res = $wallabagV2Import->setMarkAsRead(true)->import();
|
||||
|
||||
$this->assertTrue($res);
|
||||
$this->assertEquals(['skipped' => 0, 'imported' => 24], $wallabagV2Import->getSummary());
|
||||
|
||||
$this->assertNotEmpty($redisMock->lpop('wallabag_v2'));
|
||||
}
|
||||
|
||||
public function testImportBadFile()
|
||||
{
|
||||
$wallabagV1Import = $this->getWallabagV2Import();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue