/**
  * @param EntityMetadata $entityMetadata
  * @param ClassMetadata $classMetadata
  * @param string $className
  */
 protected function addDoctrineInverseAssociations(EntityMetadata $entityMetadata, ClassMetadata $classMetadata, $className)
 {
     $allMetadata = $this->doctrineHelper->getAllMetadata();
     foreach ($allMetadata as $metadata) {
         if ($metadata == $classMetadata) {
             // Skip own class metadata
             continue;
         }
         $currentClassName = $metadata->getName();
         $associationMappings = $metadata->getAssociationsByTargetClass($className);
         foreach ($associationMappings as $fieldName => $associationMapping) {
             if (isset($associationMapping['type']) && $associationMapping['type'] === ClassMetadataInfo::MANY_TO_MANY || isset($associationMapping['mappedBy'])) {
                 // Skip "mapped by" and many-to-many as it's included on other side.
                 continue;
             }
             $associationMapping['mappedBySourceEntity'] = false;
             $mergeModes = [MergeModes::UNITE];
             if ($associationMapping['type'] === ClassMetadataInfo::ONE_TO_ONE) {
                 // for fields with ONE_TO_ONE relation Unite strategy is impossible, so Replace is used
                 $mergeModes = [MergeModes::REPLACE];
             }
             $fieldMetadata = $this->metadataFactory->createFieldMetadata(array('field_name' => $this->createInverseAssociationFieldName($currentClassName, $fieldName), 'merge_modes' => $mergeModes, 'source_field_name' => $fieldName, 'source_class_name' => $currentClassName), $associationMapping);
             $entityMetadata->addFieldMetadata($fieldMetadata);
         }
     }
 }
 public function testGetAllMetadata()
 {
     $className = 'TestEntity';
     $expectedResult = array($this->metadata);
     $this->entityManager->expects($this->once())->method('getMetadataFactory')->will($this->returnValue($this->metadataFactory));
     $this->metadataFactory->expects($this->once())->method('getAllMetadata')->will($this->returnValue($expectedResult));
     $this->assertEquals($expectedResult, $this->doctrineHelper->getAllMetadata($className));
 }