diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-09-09 18:02:29 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-09-11 21:58:56 +0200 |
commit | 13470c3596d0b1490bbf18b39128a05bbb3c7f3e (patch) | |
tree | 962028a191b644653e6c9b2b536189ded89c3017 /tests/Wallabag/ImportBundle/Import | |
parent | 8664069e1aa2fa89e17587308a03f2720c20327a (diff) | |
download | wallabag-13470c3596d0b1490bbf18b39128a05bbb3c7f3e.tar.gz wallabag-13470c3596d0b1490bbf18b39128a05bbb3c7f3e.tar.zst wallabag-13470c3596d0b1490bbf18b39128a05bbb3c7f3e.zip |
Add test for RabbitMQ
Also update Symfony deps
Diffstat (limited to 'tests/Wallabag/ImportBundle/Import')
4 files changed, 197 insertions, 0 deletions
diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index 26c6b825..5ad3e435 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php | |||
@@ -343,6 +343,87 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase | |||
343 | $this->assertEquals(['skipped' => 0, 'imported' => 2], $pocketImport->getSummary()); | 343 | $this->assertEquals(['skipped' => 0, 'imported' => 2], $pocketImport->getSummary()); |
344 | } | 344 | } |
345 | 345 | ||
346 | /** | ||
347 | * Will sample results from https://getpocket.com/developer/docs/v3/retrieve. | ||
348 | */ | ||
349 | public function testImportWithRabbit() | ||
350 | { | ||
351 | $client = new Client(); | ||
352 | |||
353 | $body = <<<'JSON' | ||
354 | { | ||
355 | "item_id": "229279689", | ||
356 | "resolved_id": "229279689", | ||
357 | "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", | ||
358 | "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", | ||
359 | "favorite": "1", | ||
360 | "status": "1", | ||
361 | "resolved_title": "The Massive Ryder Cup Preview", | ||
362 | "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", | ||
363 | "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.", | ||
364 | "is_article": "1", | ||
365 | "has_video": "0", | ||
366 | "has_image": "0", | ||
367 | "word_count": "3197" | ||
368 | } | ||
369 | JSON; | ||
370 | |||
371 | $mock = new Mock([ | ||
372 | new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))), | ||
373 | new Response(200, ['Content-Type' => 'application/json'], Stream::factory(' | ||
374 | { | ||
375 | "status": 1, | ||
376 | "list": { | ||
377 | "229279690": '.$body.' | ||
378 | } | ||
379 | } | ||
380 | ')), | ||
381 | ]); | ||
382 | |||
383 | $client->getEmitter()->attach($mock); | ||
384 | |||
385 | $pocketImport = $this->getPocketImport(); | ||
386 | |||
387 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | ||
388 | ->disableOriginalConstructor() | ||
389 | ->getMock(); | ||
390 | |||
391 | $entryRepo->expects($this->never()) | ||
392 | ->method('findByUrlAndUserId'); | ||
393 | |||
394 | $this->em | ||
395 | ->expects($this->never()) | ||
396 | ->method('getRepository'); | ||
397 | |||
398 | $entry = new Entry($this->user); | ||
399 | |||
400 | $this->contentProxy | ||
401 | ->expects($this->never()) | ||
402 | ->method('updateEntry'); | ||
403 | |||
404 | $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') | ||
405 | ->disableOriginalConstructor() | ||
406 | ->getMock(); | ||
407 | |||
408 | $bodyAsArray = json_decode($body, true); | ||
409 | // because with just use `new User()` so it doesn't have an id | ||
410 | $bodyAsArray['userId'] = null; | ||
411 | |||
412 | $producer | ||
413 | ->expects($this->once()) | ||
414 | ->method('publish') | ||
415 | ->with(json_encode($bodyAsArray)); | ||
416 | |||
417 | $pocketImport->setClient($client); | ||
418 | $pocketImport->setRabbitmqProducer($producer); | ||
419 | $pocketImport->authorize('wunderbar_code'); | ||
420 | |||
421 | $res = $pocketImport->setMarkAsRead(true)->import(); | ||
422 | |||
423 | $this->assertTrue($res); | ||
424 | $this->assertEquals(['skipped' => 0, 'imported' => 1], $pocketImport->getSummary()); | ||
425 | } | ||
426 | |||
346 | public function testImportBadResponse() | 427 | public function testImportBadResponse() |
347 | { | 428 | { |
348 | $client = new Client(); | 429 | $client = new Client(); |
diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php index 706d707b..69a66d6a 100644 --- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php | |||
@@ -120,6 +120,46 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase | |||
120 | $this->assertEquals(['skipped' => 0, 'imported' => 2], $readabilityImport->getSummary()); | 120 | $this->assertEquals(['skipped' => 0, 'imported' => 2], $readabilityImport->getSummary()); |
121 | } | 121 | } |
122 | 122 | ||
123 | public function testImportWithRabbit() | ||
124 | { | ||
125 | $readabilityImport = $this->getReadabilityImport(); | ||
126 | $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); | ||
127 | |||
128 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | ||
129 | ->disableOriginalConstructor() | ||
130 | ->getMock(); | ||
131 | |||
132 | $entryRepo->expects($this->never()) | ||
133 | ->method('findByUrlAndUserId'); | ||
134 | |||
135 | $this->em | ||
136 | ->expects($this->never()) | ||
137 | ->method('getRepository'); | ||
138 | |||
139 | $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') | ||
140 | ->disableOriginalConstructor() | ||
141 | ->getMock(); | ||
142 | |||
143 | $this->contentProxy | ||
144 | ->expects($this->never()) | ||
145 | ->method('updateEntry'); | ||
146 | |||
147 | $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') | ||
148 | ->disableOriginalConstructor() | ||
149 | ->getMock(); | ||
150 | |||
151 | $producer | ||
152 | ->expects($this->exactly(2)) | ||
153 | ->method('publish'); | ||
154 | |||
155 | $readabilityImport->setRabbitmqProducer($producer); | ||
156 | |||
157 | $res = $readabilityImport->setMarkAsRead(true)->import(); | ||
158 | |||
159 | $this->assertTrue($res); | ||
160 | $this->assertEquals(['skipped' => 0, 'imported' => 2], $readabilityImport->getSummary()); | ||
161 | } | ||
162 | |||
123 | public function testImportBadFile() | 163 | public function testImportBadFile() |
124 | { | 164 | { |
125 | $readabilityImport = $this->getReadabilityImport(); | 165 | $readabilityImport = $this->getReadabilityImport(); |
diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php index bdc47dac..ada5493e 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php | |||
@@ -120,6 +120,46 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase | |||
120 | $this->assertEquals(['skipped' => 0, 'imported' => 3], $wallabagV1Import->getSummary()); | 120 | $this->assertEquals(['skipped' => 0, 'imported' => 3], $wallabagV1Import->getSummary()); |
121 | } | 121 | } |
122 | 122 | ||
123 | public function testImportWithRabbit() | ||
124 | { | ||
125 | $wallabagV1Import = $this->getWallabagV1Import(); | ||
126 | $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); | ||
127 | |||
128 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | ||
129 | ->disableOriginalConstructor() | ||
130 | ->getMock(); | ||
131 | |||
132 | $entryRepo->expects($this->never()) | ||
133 | ->method('findByUrlAndUserId'); | ||
134 | |||
135 | $this->em | ||
136 | ->expects($this->never()) | ||
137 | ->method('getRepository'); | ||
138 | |||
139 | $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') | ||
140 | ->disableOriginalConstructor() | ||
141 | ->getMock(); | ||
142 | |||
143 | $this->contentProxy | ||
144 | ->expects($this->never()) | ||
145 | ->method('updateEntry'); | ||
146 | |||
147 | $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') | ||
148 | ->disableOriginalConstructor() | ||
149 | ->getMock(); | ||
150 | |||
151 | $producer | ||
152 | ->expects($this->exactly(4)) | ||
153 | ->method('publish'); | ||
154 | |||
155 | $wallabagV1Import->setRabbitmqProducer($producer); | ||
156 | |||
157 | $res = $wallabagV1Import->setMarkAsRead(true)->import(); | ||
158 | |||
159 | $this->assertTrue($res); | ||
160 | $this->assertEquals(['skipped' => 0, 'imported' => 4], $wallabagV1Import->getSummary()); | ||
161 | } | ||
162 | |||
123 | public function testImportBadFile() | 163 | public function testImportBadFile() |
124 | { | 164 | { |
125 | $wallabagV1Import = $this->getWallabagV1Import(); | 165 | $wallabagV1Import = $this->getWallabagV1Import(); |
diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php index 4a45e0f0..51f0aada 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php | |||
@@ -116,6 +116,42 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
116 | $this->assertEquals(['skipped' => 0, 'imported' => 2], $wallabagV2Import->getSummary()); | 116 | $this->assertEquals(['skipped' => 0, 'imported' => 2], $wallabagV2Import->getSummary()); |
117 | } | 117 | } |
118 | 118 | ||
119 | public function testImportWithRabbit() | ||
120 | { | ||
121 | $wallabagV2Import = $this->getWallabagV2Import(); | ||
122 | $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); | ||
123 | |||
124 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | ||
125 | ->disableOriginalConstructor() | ||
126 | ->getMock(); | ||
127 | |||
128 | $entryRepo->expects($this->never()) | ||
129 | ->method('findByUrlAndUserId'); | ||
130 | |||
131 | $this->em | ||
132 | ->expects($this->never()) | ||
133 | ->method('getRepository'); | ||
134 | |||
135 | $this->contentProxy | ||
136 | ->expects($this->never()) | ||
137 | ->method('updateEntry'); | ||
138 | |||
139 | $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') | ||
140 | ->disableOriginalConstructor() | ||
141 | ->getMock(); | ||
142 | |||
143 | $producer | ||
144 | ->expects($this->exactly(24)) | ||
145 | ->method('publish'); | ||
146 | |||
147 | $wallabagV2Import->setRabbitmqProducer($producer); | ||
148 | |||
149 | $res = $wallabagV2Import->setMarkAsRead(true)->import(); | ||
150 | |||
151 | $this->assertTrue($res); | ||
152 | $this->assertEquals(['skipped' => 0, 'imported' => 24], $wallabagV2Import->getSummary()); | ||
153 | } | ||
154 | |||
119 | public function testImportBadFile() | 155 | public function testImportBadFile() |
120 | { | 156 | { |
121 | $wallabagV1Import = $this->getWallabagV2Import(); | 157 | $wallabagV1Import = $this->getWallabagV2Import(); |