3 namespace Tests\Wallabag\ImportBundle\Consumer\AMQP
;
5 use Wallabag\ImportBundle\Consumer\AMQPEntryConsumer
;
6 use PhpAmqpLib\Message\AMQPMessage
;
7 use Wallabag\UserBundle\Entity\User
;
8 use Wallabag\CoreBundle\Entity\Entry
;
10 class AMQPEntryConsumerTest
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 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
116 ->disableOriginalConstructor()
120 ->expects($this->once())
121 ->method('dispatch');
123 $consumer = new AMQPEntryConsumer(
130 $message = new AMQPMessage($body);
132 $consumer->execute($message);
135 public function testMessageWithBadUser()
137 $em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
138 ->disableOriginalConstructor()
142 ->expects($this->never())
146 ->expects($this->never())
149 $body = '{ "userId": 123 }';
152 $entry = new Entry($user);
154 $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository')
155 ->disableOriginalConstructor()
159 ->expects($this->once())
161 // userId from the body json above
165 $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport')
166 ->disableOriginalConstructor()
169 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
170 ->disableOriginalConstructor()
174 ->expects($this->never())
175 ->method('dispatch');
177 $consumer = new AMQPEntryConsumer(
184 $message = new AMQPMessage($body);
186 $consumer->execute($message);
189 public function testMessageWithEntryProcessed()
191 $em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
192 ->disableOriginalConstructor()
196 ->expects($this->never())
200 ->expects($this->never())
203 $body = '{ "userId": 123 }';
207 $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository')
208 ->disableOriginalConstructor()
212 ->expects($this->once())
214 // userId from the body json above
218 $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport')
219 ->disableOriginalConstructor()
223 ->expects($this->once())
228 ->expects($this->once())
229 ->method('parseEntry')
230 ->with(json_decode($body, true))
233 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
234 ->disableOriginalConstructor()
238 ->expects($this->never())
239 ->method('dispatch');
241 $consumer = new AMQPEntryConsumer(
248 $message = new AMQPMessage($body);
250 $consumer->execute($message);