public function testGetIdentifier() { $entity = new \stdClass(); $identifier = 1; $this->doctrineHelper->expects($this->once())->method('getSingleEntityIdentifier')->with($entity)->will($this->returnValue($identifier)); $this->assertEquals($identifier, $this->helper->getIdentifier($entity)); }
/** * @param object $entity * @param array $searchContext * @return null|object */ protected function findExistingEntity($entity, array $searchContext = array()) { $entityName = ClassUtils::getClass($entity); $identifier = $this->databaseHelper->getIdentifier($entity); $existingEntity = null; // find by identifier if ($identifier) { $existingEntity = $this->databaseHelper->find($entityName, $identifier); } // find by identity fields if (!$existingEntity && (!$searchContext || $this->databaseHelper->getIdentifier(current($searchContext)))) { $identityValues = $searchContext; $identityValues += $this->fieldHelper->getIdentityValues($entity); $existingEntity = $this->findEntityByIdentityValues($entityName, $identityValues); } return $existingEntity; }
/** * @param object $entity * @param array $searchContext * @return null|object */ protected function findExistingEntity($entity, array $searchContext = []) { $entityName = ClassUtils::getClass($entity); $identifier = $this->databaseHelper->getIdentifier($entity); $existingEntity = null; // find by identifier if ($identifier) { $existingEntity = $this->databaseHelper->find($entityName, $identifier); } // find by identity fields if (!$existingEntity && (!$searchContext || $this->databaseHelper->getIdentifier(current($searchContext)))) { $existingEntity = $this->findExistingEntityByIdentityFields($entity, $searchContext); } if ($existingEntity && !$identifier) { $identifier = $this->databaseHelper->getIdentifier($existingEntity); $identifierName = $this->databaseHelper->getIdentifierFieldName($entity); $this->fieldHelper->setObjectValue($entity, $identifierName, $identifier); } return $existingEntity; }