/** * @dataProvider updateHeadsDataProvider */ public function testUpdateHeads(array $updatedEmails, array $returnThreadEmails, array $expectedEmails) { $consecutiveThreadEmails = array_map(function (TestEmailEntity $entity, $returnEmails) { return $returnEmails ? $this->getThreadEmails($entity) : []; }, $updatedEmails, $returnThreadEmails); $this->emailThreadProvider->expects($this->any())->method('getThreadEmails')->will(call_user_func_array([$this, 'onConsecutiveCalls'], $consecutiveThreadEmails)); $this->emailThreadManager->updateHeads($updatedEmails); $this->assertEquals($expectedEmails, $updatedEmails); }
/** * @param PostFlushEventArgs $event */ public function postFlush(PostFlushEventArgs $event) { $this->emailThreadManager->handlePostFlush($event); $this->emailActivityManager->handlePostFlush($event); if ($this->emailsToRemove) { $em = $event->getEntityManager(); foreach ($this->emailsToRemove as $email) { $em->remove($email); } $this->emailsToRemove = []; $em->flush(); } }
/** * @dataProvider dataHeadProvider * * @param array $heads * @param array $seens * @param array $calls */ public function testUpdateThreadHead($heads, $seens, $calls) { $thread = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\EmailThread'); $thread->expects($this->any())->method('getId')->will($this->returnValue(1)); $emailFromThread1 = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\Email'); $emailFromThread2 = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\Email'); $emailFromThread3 = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\Email'); // reset $emailFromThread1->expects($this->at(0))->method('setHead')->with(false); $emailFromThread2->expects($this->at(0))->method('setHead')->with(false); $emailFromThread3->expects($this->at(0))->method('setHead')->with(false); // set heads if ($calls[0]) { $emailFromThread1->expects($this->at($calls[0]))->method('setHead')->with($heads[0]); } if ($calls[1]) { $emailFromThread2->expects($this->at($calls[1]))->method('setHead')->with($heads[1]); } if ($calls[2]) { $emailFromThread3->expects($this->at($calls[2]))->method('setHead')->with($heads[2]); } // mock seen $emailFromThread1->expects($this->exactly($calls[3]))->method('isSeen')->will($this->returnValue($seens[0])); $emailFromThread2->expects($this->exactly($calls[4]))->method('isSeen')->will($this->returnValue($seens[1])); $emailFromThread3->expects($this->exactly($calls[5]))->method('isSeen')->will($this->returnValue($seens[2])); $this->emailThreadProvider->expects($this->once())->method('getThreadEmails')->will($this->returnValue([$emailFromThread1, $emailFromThread2, $emailFromThread3])); $email = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\Email'); $email->expects($this->exactly(1))->method('getThread')->will($this->returnValue($thread)); $email->expects($this->any())->method('getId')->will($this->returnValue(1)); $entityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $entityManager->expects($this->exactly(4))->method('persist'); $entityManager->expects($this->exactly(1))->method('flush'); $this->manager->addEmailToQueueHeadUpdate($email); $this->manager->handlePostFlush(new PostFlushEventArgs($entityManager)); $this->assertEmpty($this->manager->getQueueHeadUpdate()); }
/** * @param PostFlushEventArgs $event */ public function postFlush(PostFlushEventArgs $event) { $this->emailThreadManager->handlePostFlush($event); $this->emailActivityManager->handlePostFlush($event); }