/** * @param array $items * * @return PersistentCollection */ protected function getCollection(array $items = []) { /** @var \PHPUnit_Framework_MockObject_MockObject|EntityManager $em */ $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); /** @var \PHPUnit_Framework_MockObject_MockObject|ClassMetadata $metadata */ $metadata = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock(); $collection = new PersistentCollection($em, $metadata, new ArrayCollection($items)); $collection->takeSnapshot(); return $collection; }
/** * @return array */ public function postSetDataProvider() { $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $meta = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata'); $existing = (object) ['$existing' => true]; $removed = (object) ['$removed' => true]; $added = (object) ['$added' => true]; $collectionWithElements = new ArrayCollection([$added]); $cleanCollection = new PersistentCollection($em, $meta, new ArrayCollection()); $dirtyCollection = new PersistentCollection($em, $meta, new ArrayCollection([$existing, $removed])); $dirtyCollection->takeSnapshot(); $dirtyCollection->removeElement($removed); $dirtyCollection->add($added); return ['Initialization with empty value should not be broken' => ['$data' => null, '$expectedAddedData' => [], '$expectedRemovedData' => []], 'Empty collection given should set nothing' => ['$data' => new ArrayCollection(), '$expectedAddedData' => [], '$expectedRemovedData' => []], 'Array collection with elements given, should be set to added' => ['$data' => $collectionWithElements, '$expectedAddedData' => [$added], '$expectedRemovedData' => []], 'Clean persistent collection given, should set nothing' => ['$data' => $cleanCollection, '$expectedAddedData' => [], '$expectedRemovedData' => []], 'Persistent collection given, should set from diffs' => ['$data' => $dirtyCollection, '$expectedAddedData' => [$added], '$expectedRemovedData' => [$removed]]]; }
/** * @param FormInterface $form * @param array $categories */ protected function addRFMTypes(FormInterface $form, array $categories) { foreach (RFMMetricCategory::$types as $type) { $typeCategories = array_filter($categories, function (RFMMetricCategory $category) use($type) { return $category->getCategoryType() === $type; }); $collection = new PersistentCollection($this->doctrineHelper->getEntityManager($this->rfmCategoryClass), $this->doctrineHelper->getEntityMetadata($this->rfmCategoryClass), new ArrayCollection($typeCategories)); $collection->takeSnapshot(); $constraint = new CategoriesConstraint(); $constraint->setType($type); $form->add($type, RFMCategorySettingsType::NAME, [RFMCategorySettingsType::TYPE_OPTION => $type, 'label' => sprintf('orocrm.analytics.form.%s.label', $type), 'tooltip' => sprintf('orocrm.analytics.%s.tooltip', $type), 'mapped' => false, 'required' => false, 'error_bubbling' => false, 'is_increasing' => $type === RFMMetricCategory::TYPE_RECENCY, 'constraints' => [$constraint], 'data' => $collection]); } }