3 namespace Tests\Wallabag\ImportBundle\Consumer\AMQP
;
5 use Wallabag\ImportBundle\Consumer\AMPQ\EntryConsumer
;
6 use PhpAmqpLib\Message\AMQPMessage
;
7 use Wallabag\UserBundle\Entity\User
;
8 use Wallabag\CoreBundle\Entity\Entry
;
10 class EntryConsumerTest
extends \PHPUnit_Framework_TestCase
12 public function testMessageOk()
14 $em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
15 ->disableOriginalConstructor()
19 ->expects($this->once())
23 ->expects($this->exactly(2))
28 "item_id": "1402935436",
29 "resolved_id": "1402935436",
30 "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",
31 "given_title": "Leslie Jones is back on Twitter and her comeback tweet rules",
34 "time_added": "1473020899",
35 "time_updated": "1473020899",
37 "time_favorited": "0",
39 "resolved_title": "Leslie Jones is back on Twitter and her comeback tweet rules",
40 "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",
41 "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 ...",
49 "item_id": "1402935436",
53 "item_id": "1402935436",
59 "item_id": "1402935436",
60 "author_id": "2484273",
61 "name": "Adam Rosenberg",
62 "url": "http://mashable.com/author/adam-rosenberg/"
66 "item_id": "1402935436",
67 "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",
73 "item_id": "1402935436",
75 "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",
78 "credit": "Image: Steve Eichner/NameFace/Sipa USA",
87 $entry = new Entry($user);
89 $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository')
90 ->disableOriginalConstructor()
94 ->expects($this->once())
96 // userId from the body json above
100 $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport')
101 ->disableOriginalConstructor()
105 ->expects($this->once())
110 ->expects($this->once())
111 ->method('parseEntry')
112 ->with(json_decode($body, true))
113 ->willReturn($entry);
115 $consumer = new EntryConsumer(
121 $message = new AMQPMessage($body);
123 $consumer->execute($message);
126 public function testMessageWithBadUser()
128 $em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
129 ->disableOriginalConstructor()
133 ->expects($this->never())
137 ->expects($this->never())
140 $body = '{ "userId": 123 }';
143 $entry = new Entry($user);
145 $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository')
146 ->disableOriginalConstructor()
150 ->expects($this->once())
152 // userId from the body json above
156 $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport')
157 ->disableOriginalConstructor()
160 $consumer = new EntryConsumer(
166 $message = new AMQPMessage($body);
168 $consumer->execute($message);
171 public function testMessageWithEntryProcessed()
173 $em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
174 ->disableOriginalConstructor()
178 ->expects($this->never())
182 ->expects($this->never())
185 $body = '{ "userId": 123 }';
189 $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository')
190 ->disableOriginalConstructor()
194 ->expects($this->once())
196 // userId from the body json above
200 $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport')
201 ->disableOriginalConstructor()
205 ->expects($this->once())
210 ->expects($this->once())
211 ->method('parseEntry')
212 ->with(json_decode($body, true))
215 $consumer = new EntryConsumer(
221 $message = new AMQPMessage($body);
223 $consumer->execute($message);