aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/ImportBundle/Import
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-09-09 21:02:03 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-09-11 21:58:56 +0200
commitb3437d58ae224121375c99e9288d8b808524e624 (patch)
tree94ce3446aed4396ba9304b8c97e421eba35e4edf /tests/Wallabag/ImportBundle/Import
parent7f7531171f6e49110b5842f869e37c766a682473 (diff)
downloadwallabag-b3437d58ae224121375c99e9288d8b808524e624.tar.gz
wallabag-b3437d58ae224121375c99e9288d8b808524e624.tar.zst
wallabag-b3437d58ae224121375c99e9288d8b808524e624.zip
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` -
Diffstat (limited to 'tests/Wallabag/ImportBundle/Import')
-rw-r--r--tests/Wallabag/ImportBundle/Import/PocketImportTest.php86
-rw-r--r--tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php45
-rw-r--r--tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php45
-rw-r--r--tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php41
4 files changed, 213 insertions, 4 deletions
diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php
index 1750e3a1..425fa321 100644
--- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php
@@ -9,8 +9,11 @@ use GuzzleHttp\Client;
9use GuzzleHttp\Subscriber\Mock; 9use GuzzleHttp\Subscriber\Mock;
10use GuzzleHttp\Message\Response; 10use GuzzleHttp\Message\Response;
11use GuzzleHttp\Stream\Stream; 11use GuzzleHttp\Stream\Stream;
12use Wallabag\ImportBundle\Redis\Producer;
12use Monolog\Logger; 13use Monolog\Logger;
13use Monolog\Handler\TestHandler; 14use Monolog\Handler\TestHandler;
15use Simpleue\Queue\RedisQueue;
16use M6Web\Component\RedisMock\RedisMockFactory;
14 17
15class PocketImportTest extends \PHPUnit_Framework_TestCase 18class PocketImportTest extends \PHPUnit_Framework_TestCase
16{ 19{
@@ -442,7 +445,7 @@ JSON;
442 ->with(json_encode($bodyAsArray)); 445 ->with(json_encode($bodyAsArray));
443 446
444 $pocketImport->setClient($client); 447 $pocketImport->setClient($client);
445 $pocketImport->setRabbitmqProducer($producer); 448 $pocketImport->setProducer($producer);
446 $pocketImport->authorize('wunderbar_code'); 449 $pocketImport->authorize('wunderbar_code');
447 450
448 $res = $pocketImport->setMarkAsRead(true)->import(); 451 $res = $pocketImport->setMarkAsRead(true)->import();
@@ -451,6 +454,87 @@ JSON;
451 $this->assertEquals(['skipped' => 0, 'imported' => 1], $pocketImport->getSummary()); 454 $this->assertEquals(['skipped' => 0, 'imported' => 1], $pocketImport->getSummary());
452 } 455 }
453 456
457 /**
458 * Will sample results from https://getpocket.com/developer/docs/v3/retrieve.
459 */
460 public function testImportWithRedis()
461 {
462 $client = new Client();
463
464 $body = <<<'JSON'
465{
466 "item_id": "229279689",
467 "resolved_id": "229279689",
468 "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview",
469 "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland",
470 "favorite": "1",
471 "status": "1",
472 "time_added": "1473020899",
473 "time_updated": "1473020899",
474 "time_read": "0",
475 "time_favorited": "0",
476 "sort_id": 0,
477 "resolved_title": "The Massive Ryder Cup Preview",
478 "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview",
479 "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.",
480 "is_article": "1",
481 "has_video": "0",
482 "has_image": "0",
483 "word_count": "3197"
484}
485JSON;
486
487 $mock = new Mock([
488 new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))),
489 new Response(200, ['Content-Type' => 'application/json'], Stream::factory('
490 {
491 "status": 1,
492 "list": {
493 "229279690": '.$body.'
494 }
495 }
496 ')),
497 ]);
498
499 $client->getEmitter()->attach($mock);
500
501 $pocketImport = $this->getPocketImport();
502
503 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
504 ->disableOriginalConstructor()
505 ->getMock();
506
507 $entryRepo->expects($this->never())
508 ->method('findByUrlAndUserId');
509
510 $this->em
511 ->expects($this->never())
512 ->method('getRepository');
513
514 $entry = new Entry($this->user);
515
516 $this->contentProxy
517 ->expects($this->never())
518 ->method('updateEntry');
519
520 $factory = new RedisMockFactory();
521 $redisMock = $factory->getAdapter('Predis\Client', true);
522
523 $queue = new RedisQueue($redisMock, 'pocket');
524 $producer = new Producer($queue);
525
526 $pocketImport->setClient($client);
527 $pocketImport->setProducer($producer);
528 $pocketImport->authorize('wunderbar_code');
529
530 $res = $pocketImport->setMarkAsRead(true)->import();
531
532 $this->assertTrue($res);
533 $this->assertEquals(['skipped' => 0, 'imported' => 1], $pocketImport->getSummary());
534
535 $this->assertNotEmpty($redisMock->lpop('pocket'));
536 }
537
454 public function testImportBadResponse() 538 public function testImportBadResponse()
455 { 539 {
456 $client = new Client(); 540 $client = new Client();
diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php
index 69a66d6a..0981eedb 100644
--- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php
@@ -5,8 +5,11 @@ namespace Tests\Wallabag\ImportBundle\Import;
5use Wallabag\ImportBundle\Import\ReadabilityImport; 5use Wallabag\ImportBundle\Import\ReadabilityImport;
6use Wallabag\UserBundle\Entity\User; 6use Wallabag\UserBundle\Entity\User;
7use Wallabag\CoreBundle\Entity\Entry; 7use Wallabag\CoreBundle\Entity\Entry;
8use Wallabag\ImportBundle\Redis\Producer;
8use Monolog\Logger; 9use Monolog\Logger;
9use Monolog\Handler\TestHandler; 10use Monolog\Handler\TestHandler;
11use Simpleue\Queue\RedisQueue;
12use M6Web\Component\RedisMock\RedisMockFactory;
10 13
11class ReadabilityImportTest extends \PHPUnit_Framework_TestCase 14class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
12{ 15{
@@ -152,7 +155,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
152 ->expects($this->exactly(2)) 155 ->expects($this->exactly(2))
153 ->method('publish'); 156 ->method('publish');
154 157
155 $readabilityImport->setRabbitmqProducer($producer); 158 $readabilityImport->setProducer($producer);
156 159
157 $res = $readabilityImport->setMarkAsRead(true)->import(); 160 $res = $readabilityImport->setMarkAsRead(true)->import();
158 161
@@ -160,6 +163,46 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
160 $this->assertEquals(['skipped' => 0, 'imported' => 2], $readabilityImport->getSummary()); 163 $this->assertEquals(['skipped' => 0, 'imported' => 2], $readabilityImport->getSummary());
161 } 164 }
162 165
166 public function testImportWithRedis()
167 {
168 $readabilityImport = $this->getReadabilityImport();
169 $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json');
170
171 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
172 ->disableOriginalConstructor()
173 ->getMock();
174
175 $entryRepo->expects($this->never())
176 ->method('findByUrlAndUserId');
177
178 $this->em
179 ->expects($this->never())
180 ->method('getRepository');
181
182 $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry')
183 ->disableOriginalConstructor()
184 ->getMock();
185
186 $this->contentProxy
187 ->expects($this->never())
188 ->method('updateEntry');
189
190 $factory = new RedisMockFactory();
191 $redisMock = $factory->getAdapter('Predis\Client', true);
192
193 $queue = new RedisQueue($redisMock, 'readability');
194 $producer = new Producer($queue);
195
196 $readabilityImport->setProducer($producer);
197
198 $res = $readabilityImport->setMarkAsRead(true)->import();
199
200 $this->assertTrue($res);
201 $this->assertEquals(['skipped' => 0, 'imported' => 2], $readabilityImport->getSummary());
202
203 $this->assertNotEmpty($redisMock->lpop('readability'));
204 }
205
163 public function testImportBadFile() 206 public function testImportBadFile()
164 { 207 {
165 $readabilityImport = $this->getReadabilityImport(); 208 $readabilityImport = $this->getReadabilityImport();
diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php
index ada5493e..b43682cd 100644
--- a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php
@@ -5,8 +5,11 @@ namespace Tests\Wallabag\ImportBundle\Import;
5use Wallabag\ImportBundle\Import\WallabagV1Import; 5use Wallabag\ImportBundle\Import\WallabagV1Import;
6use Wallabag\UserBundle\Entity\User; 6use Wallabag\UserBundle\Entity\User;
7use Wallabag\CoreBundle\Entity\Entry; 7use Wallabag\CoreBundle\Entity\Entry;
8use Wallabag\ImportBundle\Redis\Producer;
8use Monolog\Logger; 9use Monolog\Logger;
9use Monolog\Handler\TestHandler; 10use Monolog\Handler\TestHandler;
11use Simpleue\Queue\RedisQueue;
12use M6Web\Component\RedisMock\RedisMockFactory;
10 13
11class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase 14class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
12{ 15{
@@ -152,7 +155,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
152 ->expects($this->exactly(4)) 155 ->expects($this->exactly(4))
153 ->method('publish'); 156 ->method('publish');
154 157
155 $wallabagV1Import->setRabbitmqProducer($producer); 158 $wallabagV1Import->setProducer($producer);
156 159
157 $res = $wallabagV1Import->setMarkAsRead(true)->import(); 160 $res = $wallabagV1Import->setMarkAsRead(true)->import();
158 161
@@ -160,6 +163,46 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
160 $this->assertEquals(['skipped' => 0, 'imported' => 4], $wallabagV1Import->getSummary()); 163 $this->assertEquals(['skipped' => 0, 'imported' => 4], $wallabagV1Import->getSummary());
161 } 164 }
162 165
166 public function testImportWithRedis()
167 {
168 $wallabagV1Import = $this->getWallabagV1Import();
169 $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json');
170
171 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
172 ->disableOriginalConstructor()
173 ->getMock();
174
175 $entryRepo->expects($this->never())
176 ->method('findByUrlAndUserId');
177
178 $this->em
179 ->expects($this->never())
180 ->method('getRepository');
181
182 $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry')
183 ->disableOriginalConstructor()
184 ->getMock();
185
186 $this->contentProxy
187 ->expects($this->never())
188 ->method('updateEntry');
189
190 $factory = new RedisMockFactory();
191 $redisMock = $factory->getAdapter('Predis\Client', true);
192
193 $queue = new RedisQueue($redisMock, 'wallabag_v1');
194 $producer = new Producer($queue);
195
196 $wallabagV1Import->setProducer($producer);
197
198 $res = $wallabagV1Import->setMarkAsRead(true)->import();
199
200 $this->assertTrue($res);
201 $this->assertEquals(['skipped' => 0, 'imported' => 4], $wallabagV1Import->getSummary());
202
203 $this->assertNotEmpty($redisMock->lpop('wallabag_v1'));
204 }
205
163 public function testImportBadFile() 206 public function testImportBadFile()
164 { 207 {
165 $wallabagV1Import = $this->getWallabagV1Import(); 208 $wallabagV1Import = $this->getWallabagV1Import();
diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php
index 51f0aada..18998b35 100644
--- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php
@@ -5,8 +5,11 @@ namespace Tests\Wallabag\ImportBundle\Import;
5use Wallabag\ImportBundle\Import\WallabagV2Import; 5use Wallabag\ImportBundle\Import\WallabagV2Import;
6use Wallabag\UserBundle\Entity\User; 6use Wallabag\UserBundle\Entity\User;
7use Wallabag\CoreBundle\Entity\Entry; 7use Wallabag\CoreBundle\Entity\Entry;
8use Wallabag\ImportBundle\Redis\Producer;
8use Monolog\Logger; 9use Monolog\Logger;
9use Monolog\Handler\TestHandler; 10use Monolog\Handler\TestHandler;
11use Simpleue\Queue\RedisQueue;
12use M6Web\Component\RedisMock\RedisMockFactory;
10 13
11class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase 14class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
12{ 15{
@@ -144,7 +147,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
144 ->expects($this->exactly(24)) 147 ->expects($this->exactly(24))
145 ->method('publish'); 148 ->method('publish');
146 149
147 $wallabagV2Import->setRabbitmqProducer($producer); 150 $wallabagV2Import->setProducer($producer);
148 151
149 $res = $wallabagV2Import->setMarkAsRead(true)->import(); 152 $res = $wallabagV2Import->setMarkAsRead(true)->import();
150 153
@@ -152,6 +155,42 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
152 $this->assertEquals(['skipped' => 0, 'imported' => 24], $wallabagV2Import->getSummary()); 155 $this->assertEquals(['skipped' => 0, 'imported' => 24], $wallabagV2Import->getSummary());
153 } 156 }
154 157
158 public function testImportWithRedis()
159 {
160 $wallabagV2Import = $this->getWallabagV2Import();
161 $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json');
162
163 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
164 ->disableOriginalConstructor()
165 ->getMock();
166
167 $entryRepo->expects($this->never())
168 ->method('findByUrlAndUserId');
169
170 $this->em
171 ->expects($this->never())
172 ->method('getRepository');
173
174 $this->contentProxy
175 ->expects($this->never())
176 ->method('updateEntry');
177
178 $factory = new RedisMockFactory();
179 $redisMock = $factory->getAdapter('Predis\Client', true);
180
181 $queue = new RedisQueue($redisMock, 'wallabag_v2');
182 $producer = new Producer($queue);
183
184 $wallabagV2Import->setProducer($producer);
185
186 $res = $wallabagV2Import->setMarkAsRead(true)->import();
187
188 $this->assertTrue($res);
189 $this->assertEquals(['skipped' => 0, 'imported' => 24], $wallabagV2Import->getSummary());
190
191 $this->assertNotEmpty($redisMock->lpop('wallabag_v2'));
192 }
193
155 public function testImportBadFile() 194 public function testImportBadFile()
156 { 195 {
157 $wallabagV1Import = $this->getWallabagV2Import(); 196 $wallabagV1Import = $this->getWallabagV2Import();