Esempio n. 1
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testMerge()
 {
     $fieldData = $this->createFieldData();
     $fieldMetadataData = $this->createFieldMetadata();
     $entityData = $this->createEntityData();
     $masterEntity = new EntityStub(1);
     $sourceEntity = new EntityStub(2);
     $collectionItem1 = new CollectionItemStub(1);
     $collectionItem2 = new CollectionItemStub(2);
     $masterEntity->addCollectionItem($collectionItem1);
     $sourceEntity->addCollectionItem($collectionItem2);
     $entities = [$masterEntity, $sourceEntity];
     $relatedEntities = [$collectionItem1, $collectionItem2];
     $fieldData->expects($this->once())->method('getEntityData')->will($this->returnValue($entityData));
     $fieldData->expects($this->once())->method('getMetadata')->will($this->returnValue($fieldMetadataData));
     $entityData->expects($this->once())->method('getEntities')->will($this->returnValue($entities));
     $entityData->expects($this->once())->method('getMasterEntity')->will($this->returnValue($masterEntity));
     $this->doctrineHelper->expects($this->any())->method('getEntityIdentifierValue')->will($this->returnCallback(function ($value) {
         return $value->getId();
     }));
     $fieldDoctrineMetadata = $this->createDoctrineMetadata();
     $fieldDoctrineMetadata->expects($this->any())->method('getFieldName')->will($this->returnValue('field_name'));
     $fieldMetadataData->expects($this->any())->method('getDoctrineMetadata')->will($this->returnValue($fieldDoctrineMetadata));
     $fieldMetadataData->expects($this->any())->method('getFieldName')->will($this->returnValue('collection'));
     $fieldMetadataData->expects($this->any())->method('has')->will($this->returnValue(true));
     $fieldMetadataData->expects($this->any())->method('get')->will($this->returnValue('setEntityStub'));
     $repository = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ObjectRepository')->disableOriginalConstructor()->getMock();
     $this->doctrineHelper->expects($this->any())->method('getEntityRepository')->will($this->returnValue($repository));
     $repository->expects($this->any())->method('findBy')->will($this->returnCallback(function ($values) use($relatedEntities) {
         return [$relatedEntities[$values['field_name']->getId() - 1]];
     }));
     $this->strategy->merge($fieldData);
     $this->assertEquals($masterEntity, $collectionItem1->getEntityStub());
     $this->assertEquals($masterEntity, $collectionItem2->getEntityStub());
 }
Esempio n. 2
0
 public function setParentId($id)
 {
     $this->parent->setId($id);
 }