public function testOnFlushNotSupported() { $contactsArray = [new User(), new User(), new User()]; $createdEmailsArray = [new Email(), new Email(), new Email()]; $updatedEmailsArray = [new Email()]; $createdEmails = [spl_object_hash($createdEmailsArray[0]) => $createdEmailsArray[0], spl_object_hash($createdEmailsArray[1]) => $createdEmailsArray[1], spl_object_hash($createdEmailsArray[2]) => $createdEmailsArray[2]]; $updatedEmails = [spl_object_hash($updatedEmailsArray[0]) => $updatedEmailsArray[0]]; $uow = new UnitOfWork(); array_map([$uow, 'addInsertion'], array_merge($contactsArray, $createdEmailsArray)); array_map([$uow, 'addUpdate'], $updatedEmailsArray); $metadata = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadataInfo')->disableOriginalConstructor()->getMock(); $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $em->expects($this->any())->method('getClassMetadata')->will($this->returnValue($metadata)); $em->expects($this->any())->method('getUnitOfWork')->will($this->returnValue($uow)); $onFlushEventArgs = $this->getMockBuilder('Doctrine\\ORM\\Event\\OnFlushEventArgs')->disableOriginalConstructor()->getMock(); $onFlushEventArgs->expects($this->any())->method('getEntityManager')->will($this->returnValue($em)); $this->emailOwnerManager->expects($this->once())->method('createEmailAddressData')->will($this->returnValue([])); $this->emailOwnerManager->expects($this->once())->method('handleChangedAddresses')->will($this->returnValue([])); $this->emailActivityManager->expects($this->once())->method('updateActivities')->with($createdEmails); $this->emailThreadManager->expects($this->once())->method('updateThreads')->with($createdEmails); $this->emailThreadManager->expects($this->once())->method('updateHeads')->with($updatedEmails); $this->emailActivityManager->expects($this->once())->method('updateActivities')->with($createdEmails); $postFlushEventArgs = $this->getMockBuilder('Doctrine\\ORM\\Event\\PostFlushEventArgs')->disableOriginalConstructor()->getMock(); $postFlushEventArgs->expects($this->any())->method('getEntityManager')->will($this->returnValue($em)); $this->registry->expects($this->never())->method('getRepository')->will($this->returnValue($this->registry)); $this->registry->expects($this->never())->method('getEmailsByOwnerEntity')->will($this->returnValue($createdEmailsArray)); $this->emailOwnersProvider->expects($this->exactly(6))->method('supportOwnerProvider')->will($this->returnValue(true)); $this->userEmailOwnerProvider->expects($this->never())->method('getEmailOwnerClass')->will($this->returnValue(ClassUtils::getClass(new User()))); $this->emailActivityManager->expects($this->never())->method('addAssociation'); $this->listener->onFlush($onFlushEventArgs); $this->listener->postFlush($postFlushEventArgs); }
public function testOnFlushNotSupported() { $contactsArray = [new User(), new User(), new User()]; $emailsArray = [new Email(), new Email(), new Email()]; $onFlushEventArgs = $this->getMockBuilder('Doctrine\\ORM\\Event\\OnFlushEventArgs')->setMethods(['getEntityManager', 'getUnitOfWork', 'getScheduledEntityInsertions'])->disableOriginalConstructor()->getMock(); $onFlushEventArgs->expects($this->once())->method('getEntityManager')->will($this->returnValue($onFlushEventArgs)); $onFlushEventArgs->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($onFlushEventArgs)); $onFlushEventArgs->expects($this->once())->method('getScheduledEntityInsertions')->will($this->returnValue($contactsArray)); $this->emailOwnerManager->expects($this->once())->method('handleOnFlush')->with($this->identicalTo($onFlushEventArgs)); $this->emailActivityManager->expects($this->once())->method('handleOnFlush')->with($this->identicalTo($onFlushEventArgs)); $this->emailThreadManager->expects($this->once())->method('handleOnFlush')->with($this->identicalTo($onFlushEventArgs)); $postFlushEventArgs = $this->getMockBuilder('Doctrine\\ORM\\Event\\PostFlushEventArgs')->setMethods(['getEntityManager', 'flush'])->disableOriginalConstructor()->getMock(); $postFlushEventArgs->expects($this->once())->method('getEntityManager')->will($this->returnValue($postFlushEventArgs)); $this->registry->expects($this->never())->method('getRepository')->will($this->returnValue($this->registry)); $this->registry->expects($this->never())->method('getEmailsByOwnerEntity')->will($this->returnValue($emailsArray)); $this->emailOwnersProvider->expects($this->exactly(3))->method('supportOwnerProvider')->will($this->returnValue(true)); $this->chainProvider->expects($this->exactly(3))->method('isSupportedTargetEntity')->will($this->returnValue(false)); $this->userEmailOwnerProvider->expects($this->exactly(3))->method('getEmailOwnerClass')->will($this->returnValue(ClassUtils::getClass(new User()))); $this->emailActivityManager->expects($this->never())->method('addAssociation'); $postFlushEventArgs->expects($this->once())->method('flush'); $this->listener->onFlush($onFlushEventArgs); $this->listener->postFlush($postFlushEventArgs); }