public function testAddEntity() { $fooEntity = $this->createTestEntity(1); $barEntity = $this->createTestEntity(2); $expectedCount = count($this->entities) + 1; $expectedEntities = array_merge($this->entities, array($fooEntity)); $this->assertEquals($this->entityData, $this->entityData->addEntity($fooEntity)); $this->assertCount($expectedCount, $this->entityData->getEntities()); $this->assertEquals($expectedEntities, $this->entityData->getEntities()); $this->entityData->addEntity($barEntity); $expectedCount += 1; $expectedEntities = array_merge($expectedEntities, array($barEntity)); $this->assertCount($expectedCount, $this->entityData->getEntities()); $this->assertEquals($expectedEntities, $this->entityData->getEntities()); }
/** * Merge fields * * @param EntityData $data */ public function run(EntityData $data) { $masterEntity = $data->getMasterEntity(); foreach ($data->getEntities() as $entity) { if (!$this->doctrineHelper->isEntityEqual($masterEntity, $entity)) { $this->entityManager->remove($entity); } } }
/** * Get entities that are not master. * * @param EntityData $entityData * @return array */ protected function getEntitiesToClear(EntityData $entityData) { $result = array(); $masterEntity = $entityData->getMasterEntity(); foreach ($entityData->getEntities() as $entity) { if (!$this->doctrineHelper->isEntityEqual($masterEntity, $entity)) { $result[] = $entity; } } return $result; }