/** * Save collected changes * * @param PostFlushEventArgs $args */ public function postFlush(PostFlushEventArgs $args) { /** @var $entityManager */ $entityManager = $args->getEntityManager(); $this->activityListManager->processDeletedEntities($this->deletedEntities, $entityManager); $this->deletedEntities = []; if ($this->activityListManager->processInsertEntities($this->insertedEntities, $entityManager)) { $this->insertedEntities = []; $entityManager->flush(); } if ($this->activityListManager->processFillOwners($this->insertedOwnerEntities, $entityManager)) { $this->insertedOwnerEntities = []; $entityManager->flush(); } }
public function testProcessFillOwners() { $activityOwner = $this->getMockBuilder('Oro\\Bundle\\ActivityListBundle\\Entity\\ActivityOwner')->setMethods(['isOwnerInCollection'])->disableOriginalConstructor()->getMock(); $activityOwner->expects($this->exactly(2))->method('isOwnerInCollection')->willReturn(false); $activity = $this->getMockBuilder('Oro\\Bundle\\ActivityListBundle\\Entity\\ActivityList')->disableOriginalConstructor()->getMock(); $activity->expects($this->once())->method('getActivityOwners')->willReturn(new ArrayCollection([$activityOwner])); $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $testEntity = new \stdClass(); $this->chainProvider->expects($this->once())->method('getActivityListByEntity')->willReturn($activity); $emailProvider = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Provider\\EmailActivityListProvider')->disableOriginalConstructor()->getMock(); $emailProvider->expects($this->once())->method('getActivityOwners')->willReturn([$activityOwner]); $this->chainProvider->expects($this->once())->method('getProviderForOwnerEntity')->willReturn($emailProvider); $activity->expects($this->once())->method('removeActivityOwner'); $activity->expects($this->once())->method('addActivityOwner'); $this->manager->processFillOwners([$testEntity], $em); }