public function testGetMetadataForSingleClass()
 {
     $mockDriver = new MetadataDriverMock();
     $entityManager = $this->_createEntityManager($mockDriver);
     $conn = $entityManager->getConnection();
     $mockPlatform = $conn->getDatabasePlatform();
     $mockPlatform->setPrefersSequences(true);
     $mockPlatform->setPrefersIdentityColumns(false);
     $cm1 = $this->_createValidClassMetadata();
     // SUT
     $cmf = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
     $cmf->setEntityManager($entityManager);
     $cmf->setMetadataFor($cm1->name, $cm1);
     // Prechecks
     $this->assertEquals(array(), $cm1->parentClasses);
     $this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $cm1->inheritanceType);
     $this->assertTrue($cm1->hasField('name'));
     $this->assertEquals(2, count($cm1->associationMappings));
     $this->assertEquals(ClassMetadata::GENERATOR_TYPE_AUTO, $cm1->generatorType);
     $this->assertEquals('group', $cm1->table['name']);
     // Go
     $cmMap1 = $cmf->getMetadataFor($cm1->name);
     $this->assertSame($cm1, $cmMap1);
     $this->assertEquals('group', $cmMap1->table['name']);
     $this->assertTrue($cmMap1->table['quoted']);
     $this->assertEquals(array(), $cmMap1->parentClasses);
     $this->assertTrue($cmMap1->hasField('name'));
 }
 /**
  * @group DDC-3293
  * @group DDC-3477
  * @group 1238
  */
 public function testEmbeddedMappingsWithFalseUseColumnPrefix()
 {
     $factory = new ClassMetadataFactory();
     $em = $this->_getTestEntityManager();
     $em->getConfiguration()->setMetadataDriverImpl($this->_loadDriver());
     $factory->setEntityManager($em);
     $this->assertFalse($factory->getMetadataFor('Doctrine\\Tests\\Models\\DDC3293\\DDC3293User')->embeddedClasses['address']['columnPrefix']);
 }
 public function setUp()
 {
     $this->metadataFactory = $this->getMock(ClassMetadataFactory::class);
     $this->metadataFactory->method('hasMetadataFor')->will($this->returnValueMap([[DummyEntity::class, true], [DummyEmbeddable::class, true]]));
     $this->metadataFactory->method('getMetadataFor')->will($this->returnValueMap([[DummyEntity::class, DummyEntity::getMetadata()], [DummyEmbeddable::class, DummyEmbeddable::getMetadata()]]));
     $em = $this->getMock(EntityManagerInterface::class);
     $em->method('getMetadataFactory')->willReturn($this->metadataFactory);
     $this->entity = new DummyEntity();
     $this->entity->setId(1);
     $this->entity->setA('1a');
     $this->entity->setB('1b');
     $this->entity->setC('1c');
     $d = new DummyEmbeddable();
     $d->setX(1);
     $d->setY(2);
     $d->setZ(3);
     $this->entity->setD($d);
     $child = new DummyEntity();
     $child->setId(2);
     $child->setA('2a');
     $child->setB('2b');
     $child->setC('2c');
     $d = new DummyEmbeddable();
     $d->setX(21);
     $d->setY(22);
     $d->setZ(23);
     $child->setD($d);
     $this->entity->addChild($child);
     $child = new DummyEntity();
     $child->setId(3);
     $child->setA('3a');
     $child->setB('3b');
     $child->setC('3c');
     $d = new DummyEmbeddable();
     $d->setX(31);
     $d->setY(32);
     $d->setZ(33);
     $child->setD($d);
     $this->entity->addChild($child);
     $subchild = new DummyEntity();
     $subchild->setId(4);
     $subchild->setA('4a');
     $subchild->setB('4b');
     $subchild->setC('4c');
     $d = new DummyEmbeddable();
     $d->setX(41);
     $d->setY(42);
     $d->setZ(43);
     $subchild->setD($d);
     $child->addChild($subchild);
     $this->normalizer = new DoctrineNormalizer(null, null, null, $em);
     $propertyNormalizer = new PropertyNormalizer();
     $serializer = new Serializer([$this->normalizer, $propertyNormalizer]);
     $this->normalizer->setSerializer($serializer);
 }
 /**
  * @group DDC-2109
  */
 public function testAssertTableColumnsAreNotAddedInManyToMany()
 {
     $evm = $this->em->getEventManager();
     $this->listener->addResolveTargetEntity('Doctrine\\Tests\\ORM\\Tools\\ResolveTargetInterface', 'Doctrine\\Tests\\ORM\\Tools\\ResolveTargetEntity', array());
     $this->listener->addResolveTargetEntity('Doctrine\\Tests\\ORM\\Tools\\TargetInterface', 'Doctrine\\Tests\\ORM\\Tools\\TargetEntity', array());
     $evm->addEventListener(Events::loadClassMetadata, $this->listener);
     $cm = $this->factory->getMetadataFor('Doctrine\\Tests\\ORM\\Tools\\ResolveTargetEntity');
     $meta = $cm->associationMappings['manyToMany'];
     $this->assertSame('Doctrine\\Tests\\ORM\\Tools\\TargetEntity', $meta['targetEntity']);
     $this->assertEquals(array('resolvetargetentity_id', 'targetinterface_id'), $meta['joinTableColumns']);
 }
 /**
  * @group DDC-1544
  */
 public function testResolveTargetEntityListenerCanResolveTargetEntity()
 {
     $evm = $this->em->getEventManager();
     $this->listener->addResolveTargetEntity('Doctrine\\Tests\\ORM\\Tools\\ResolveTargetInterface', 'Doctrine\\Tests\\ORM\\Tools\\ResolveTargetEntity', array());
     $this->listener->addResolveTargetEntity('Doctrine\\Tests\\ORM\\Tools\\TargetInterface', 'Doctrine\\Tests\\ORM\\Tools\\TargetEntity', array());
     $evm->addEventListener(Events::loadClassMetadata, $this->listener);
     $cm = $this->factory->getMetadataFor('Doctrine\\Tests\\ORM\\Tools\\ResolveTargetEntity');
     $meta = $cm->associationMappings;
     $this->assertSame('Doctrine\\Tests\\ORM\\Tools\\TargetEntity', $meta['manyToMany']['targetEntity']);
     $this->assertSame('Doctrine\\Tests\\ORM\\Tools\\ResolveTargetEntity', $meta['manyToOne']['targetEntity']);
     $this->assertSame('Doctrine\\Tests\\ORM\\Tools\\ResolveTargetEntity', $meta['oneToMany']['targetEntity']);
     $this->assertSame('Doctrine\\Tests\\ORM\\Tools\\TargetEntity', $meta['oneToOne']['targetEntity']);
 }
Example #6
0
 /**
  * Clears the EntityManager. All entities that are currently managed
  * by this EntityManager become detached.
  *
  * @param string|null $entityName if given, only entities of this type will get detached
  *
  * @return void
  *
  * @throws ORMInvalidArgumentException                           if a non-null non-string value is given
  * @throws \Doctrine\Common\Persistence\Mapping\MappingException if a $entityName is given, but that entity is not
  *                                                               found in the mappings
  */
 public function clear($entityName = null)
 {
     if (null !== $entityName && !is_string($entityName)) {
         throw ORMInvalidArgumentException::invalidEntityName($entityName);
     }
     $this->unitOfWork->clear(null === $entityName ? null : $this->metadataFactory->getMetadataFor($entityName)->getName());
 }
 /**
  * {@inheritdoc}
  */
 public function storeCollectionCache(CollectionCacheKey $key, $elements)
 {
     /* @var $targetPersister CachedEntityPersister */
     $associationMapping = $this->sourceEntity->associationMappings[$key->association];
     $targetPersister = $this->uow->getEntityPersister($this->targetEntity->rootEntityName);
     $targetRegion = $targetPersister->getCacheRegion();
     $targetHydrator = $targetPersister->getEntityHydrator();
     // Only preserve ordering if association configured it
     if (!(isset($associationMapping['indexBy']) && $associationMapping['indexBy'])) {
         // Elements may be an array or a Collection
         $elements = array_values(is_array($elements) ? $elements : $elements->getValues());
     }
     $entry = $this->hydrator->buildCacheEntry($this->targetEntity, $key, $elements);
     foreach ($entry->identifiers as $index => $entityKey) {
         if ($targetRegion->contains($entityKey)) {
             continue;
         }
         $class = $this->targetEntity;
         $className = ClassUtils::getClass($elements[$index]);
         if ($className !== $this->targetEntity->name) {
             $class = $this->metadataFactory->getMetadataFor($className);
         }
         $entity = $elements[$index];
         $entityEntry = $targetHydrator->buildCacheEntry($class, $entityKey, $entity);
         $targetRegion->put($entityKey, $entityEntry);
     }
     $cached = $this->region->put($key, $entry);
     if ($this->cacheLogger && $cached) {
         $this->cacheLogger->collectionCachePut($this->regionName, $key);
     }
 }
 /**
  * @param string $class
  * @param array  $array
  *
  * @return array
  */
 protected function getIdentifierFromArray($class, $array)
 {
     $meta = $this->entityMetadataFactory->getMetadataFor($class);
     $fields = $meta->getIdentifierFieldNames();
     $ids = array();
     foreach ($fields as $field) {
         if (isset($array[$field])) {
             $ids[$field] = $array[$field];
         } else {
             $tmp = $array;
             $parts = explode('.', $field);
             foreach ($parts as $part) {
                 if (isset($tmp[$part])) {
                     if (is_array($tmp[$part])) {
                         $tmp = $tmp[$part];
                     } else {
                         $ids[$field] = $tmp[$part];
                         break;
                     }
                 }
             }
         }
     }
     return $ids;
 }
 /**
  * {@inheritdoc}
  */
 public function storeCollectionCache(CollectionCacheKey $key, $elements)
 {
     /* @var $targetPersister CachedEntityPersister */
     $targetPersister = $this->uow->getEntityPersister($this->targetEntity->rootEntityName);
     $targetRegion = $targetPersister->getCacheRegion();
     $targetHydrator = $targetPersister->getEntityHydrator();
     $entry = $this->hydrator->buildCacheEntry($this->targetEntity, $key, $elements);
     foreach ($entry->identifiers as $index => $entityKey) {
         if ($targetRegion->contains($entityKey)) {
             continue;
         }
         $class = $this->targetEntity;
         $className = ClassUtils::getClass($elements[$index]);
         if ($className !== $this->targetEntity->name) {
             $class = $this->metadataFactory->getMetadataFor($className);
         }
         $entity = $elements[$index];
         $entityEntry = $targetHydrator->buildCacheEntry($class, $entityKey, $entity);
         $targetRegion->put($entityKey, $entityEntry);
     }
     $cached = $this->region->put($key, $entry);
     if ($this->cacheLogger && $cached) {
         $this->cacheLogger->collectionCachePut($this->regionName, $key);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function setMetadataFor($className, $class)
 {
     $cacheDriver = $this->getCacheDriver();
     if (null !== $cacheDriver) {
         $cacheDriver->save($className . $this->cacheSalt, $class, null);
     }
     parent::setMetadataFor($className, $class);
 }
 /**
  * Ensure indexes are inherited from the mapped superclass.
  *
  * @group DDC-3418
  */
 public function testMappedSuperclassIndex()
 {
     $class = $this->cmf->getMetadataFor(__NAMESPACE__ . '\\EntityIndexSubClass');
     /* @var $class ClassMetadataInfo */
     $this->assertArrayHasKey('mapped1', $class->fieldMappings);
     $this->assertArrayHasKey('IDX_NAME_INDEX', $class->table['uniqueConstraints']);
     $this->assertArrayHasKey('IDX_MAPPED1_INDEX', $class->table['uniqueConstraints']);
     $this->assertArrayHasKey('IDX_MAPPED2_INDEX', $class->table['indexes']);
 }
Example #12
0
 /**
  * @param mixed $classes
  * @return void
  */
 public function setUp()
 {
     $this->doctrine = Zend_Registry::get('container')->getService('doctrine');
     $this->em = $this->doctrine->getEntityManager();
     $this->em->clear();
     $tool = new SchemaTool($this->em);
     $tool->dropDatabase();
     $classes = func_get_args();
     if (!empty($classes)) {
         $metadataFactory = new ClassMetadataFactory();
         $metadataFactory->setEntityManager($this->em);
         $metadataFactory->setCacheDriver(new ArrayCache());
         $metadata = array();
         foreach ((array) $classes as $class) {
             $metadata[] = $metadataFactory->getMetadataFor($class);
         }
         $tool->createSchema($metadata);
     }
 }
 public function testGetMetadataForSingleClass()
 {
     $mockDriver = new MetadataDriverMock();
     $entityManager = $this->_createEntityManager($mockDriver);
     $conn = $entityManager->getConnection();
     $mockPlatform = $conn->getDatabasePlatform();
     $mockPlatform->setPrefersSequences(true);
     $mockPlatform->setPrefersIdentityColumns(false);
     // Self-made metadata
     $cm1 = new ClassMetadata('Doctrine\\Tests\\ORM\\Mapping\\TestEntity1');
     $cm1->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $cm1->setPrimaryTable(array('name' => '`group`'));
     // Add a mapped field
     $cm1->mapField(array('fieldName' => 'name', 'type' => 'varchar'));
     // Add a mapped field
     $cm1->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
     // and a mapped association
     $cm1->mapOneToOne(array('fieldName' => 'other', 'targetEntity' => 'TestEntity1', 'mappedBy' => 'this'));
     // and an association on the owning side
     $joinColumns = array(array('name' => 'other_id', 'referencedColumnName' => 'id'));
     $cm1->mapOneToOne(array('fieldName' => 'association', 'targetEntity' => 'TestEntity1', 'joinColumns' => $joinColumns));
     // and an id generator type
     $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_AUTO);
     // SUT
     $cmf = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
     $cmf->setEntityManager($entityManager);
     $cmf->setMetadataFor('Doctrine\\Tests\\ORM\\Mapping\\TestEntity1', $cm1);
     // Prechecks
     $this->assertEquals(array(), $cm1->parentClasses);
     $this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $cm1->inheritanceType);
     $this->assertTrue($cm1->hasField('name'));
     $this->assertEquals(2, count($cm1->associationMappings));
     $this->assertEquals(ClassMetadata::GENERATOR_TYPE_AUTO, $cm1->generatorType);
     $this->assertEquals('group', $cm1->table['name']);
     // Go
     $cmMap1 = $cmf->getMetadataFor('Doctrine\\Tests\\ORM\\Mapping\\TestEntity1');
     $this->assertSame($cm1, $cmMap1);
     $this->assertEquals('group', $cmMap1->table['name']);
     $this->assertTrue($cmMap1->table['quoted']);
     $this->assertEquals(array(), $cmMap1->parentClasses);
     $this->assertTrue($cmMap1->hasField('name'));
 }
Example #14
0
 /**
  * Prepare repository for specific entity
  *
  * @param  string           $entityName
  * @param  array            $entities
  * @param  array            $entityIds
  * @return EntityRepository
  */
 protected function prepareEntityRepository($entityName, array $entities, array $entityIds)
 {
     $query = $this->getMockForAbstractClass('Doctrine\\ORM\\AbstractQuery', array($this->entityManager), '', true, true, true, array('getResult'));
     $query->expects($this->once())->method('getResult')->will($this->returnValue($entities));
     $queryBuilder = $this->getMock('Doctrine\\ORM\\QueryBuilder', array('where', 'getQuery'), array($this->entityManager));
     $queryBuilder->expects($this->once())->method('where')->with(new Func('e.id IN', $entityIds));
     $queryBuilder->expects($this->once())->method('getQuery')->will($this->returnValue($query));
     $repository = $this->getMock('Doctrine\\ORM\\EntityRepository', array('createQueryBuilder'), array($this->entityManager, $this->stubMetadata->getMetadataFor($entityName)));
     $repository->expects($this->any())->method('createQueryBuilder')->with('e')->will($this->returnValue($queryBuilder));
     return $repository;
 }
 /**
  * {@inheritDoc}
  */
 public function isTransient($class)
 {
     if ($logger = $this->getProfilingLogger()) {
         $logger->startIsTransient();
         $result = parent::isTransient($class);
         $logger->stopIsTransient();
         return $result;
     } else {
         return parent::isTransient($class);
     }
 }
Example #16
0
 /**
  * Set up entity manager
  *
  * @return Doctrine\ORM\EntityManager
  */
 protected function setUpOrm()
 {
     global $application;
     $doctrine = $application->getBootstrap()->getResource('container')->getService('doctrine');
     $orm = $doctrine->getEntityManager();
     $orm->clear();
     $tool = new SchemaTool($orm);
     $tool->dropDatabase();
     $classes = func_get_args();
     if (!empty($classes)) {
         $metadataFactory = new ClassMetadataFactory();
         $metadataFactory->setEntityManager($orm);
         $metadataFactory->setCacheDriver(new Cache());
         $metadata = array();
         foreach ((array) $classes as $class) {
             $metadata[] = $metadataFactory->getMetadataFor($class);
         }
         $tool->createSchema($metadata);
     }
     return $orm;
 }
Example #17
0
 /**
  * Gets a reference to the entity identified by the given type and identifier
  * without actually loading it.
  *
  * If partial objects are allowed, this method will return a partial object that only
  * has its identifier populated. Otherwise a proxy is returned that automatically
  * loads itself on first access.
  *
  * @return object The entity reference.
  */
 public function getReference($entityName, $identifier)
 {
     $class = $this->_metadataFactory->getMetadataFor($entityName);
     // Check identity map first, if its already in there just return it.
     if ($entity = $this->_unitOfWork->tryGetById($identifier, $class->rootEntityName)) {
         return $entity;
     }
     if (!is_array($identifier)) {
         $identifier = array($class->identifier[0] => $identifier);
     }
     $entity = $this->_proxyFactory->getProxy($class->name, $identifier);
     $this->_unitOfWork->registerManaged($entity, $identifier, array());
     return $entity;
 }
 /**
  * Gets a partial reference to the entity identified by the given type and identifier
  * without actually loading it, if the entity is not yet loaded.
  *
  * The returned reference may be a partial object if the entity is not yet loaded/managed.
  * If it is a partial object it will not initialize the rest of the entity state on access.
  * Thus you can only ever safely access the identifier of an entity obtained through
  * this method.
  *
  * The use-cases for partial references involve maintaining bidirectional associations
  * without loading one side of the association or to update an entity without loading it.
  * Note, however, that in the latter case the original (persistent) entity data will
  * never be visible to the application (especially not event listeners) as it will
  * never be loaded in the first place.
  *
  * @param string $entityName The name of the entity type.
  * @param mixed $identifier The entity identifier.
  * @return object The (partial) entity reference.
  */
 public function getPartialReference($entityName, $identifier)
 {
     $class = $this->metadataFactory->getMetadataFor(ltrim($entityName, '\\'));
     // Check identity map first, if its already in there just return it.
     if ($entity = $this->unitOfWork->tryGetById($identifier, $class->rootEntityName)) {
         return $entity instanceof $class->name ? $entity : null;
     }
     if (!is_array($identifier)) {
         $identifier = array($class->identifier[0] => $identifier);
     }
     $entity = $class->newInstance();
     $class->setIdentifierValues($entity, $identifier);
     $this->unitOfWork->registerManaged($entity, $identifier, array());
     return $entity;
 }
 protected function loadMetadata($name)
 {
     $origName = $name;
     if ($this->config instanceof Kdyby\Doctrine\Configuration) {
         $name = $this->config->getTargetEntityClassName($name);
     }
     if (!class_exists($name)) {
         throw new Kdyby\Doctrine\MissingClassException("Metadata of class {$name} was not found, because the class is missing or cannot be autoloaded.");
     }
     $result = parent::loadMetadata($name);
     if ($name !== $origName) {
         $this->setMetadataFor($origName, $this->getMetadataFor($name));
     }
     return $result;
 }
 /**
  * {@inheritDoc}
  */
 public function isTransient($class)
 {
     $logger = $this->getProfilingLogger();
     if ($logger) {
         $logger->startIsTransient();
     }
     if (array_key_exists($class, $this->isTransientCache)) {
         $result = $this->isTransientCache[$class];
     } else {
         $result = parent::isTransient($class);
         $this->isTransientCache[$class] = $result;
     }
     if ($logger) {
         $logger->stopIsTransient();
     }
     return $result;
 }
Example #21
0
 private function remapActions(ClassMetadata $metadata, ClassMetadataFactory $metadataFactory)
 {
     $fieldName = 'actions';
     unset($metadata->fieldMappings[$fieldName]);
     unset($metadata->embeddedClasses[$fieldName]);
     // Re-map the embeddable
     $mapping = ['fieldName' => $fieldName, 'class' => $this->actionsClass, 'columnPrefix' => null];
     $metadata->mapEmbedded($mapping);
     // Remove the existing inlined fields
     foreach ($metadata->fieldMappings as $name => $fieldMapping) {
         if (isset($fieldMapping['declaredField']) && $fieldMapping['declaredField'] === $fieldName) {
             unset($metadata->fieldMappings[$name]);
             unset($metadata->fieldNames[$fieldMapping['columnName']]);
         }
     }
     // Re-inline the embeddable
     $embeddableMetadata = $metadataFactory->getMetadataFor($this->actionsClass);
     $metadata->inlineEmbeddable($fieldName, $embeddableMetadata);
 }
 /**
  * {@inheritdoc}
  */
 public function loadById(array $identifier, $entity = null)
 {
     $cacheKey = new EntityCacheKey($this->class->rootEntityName, $identifier);
     $cacheEntry = $this->region->get($cacheKey);
     $class = $this->class;
     if ($cacheEntry !== null) {
         if ($cacheEntry->class !== $this->class->name) {
             $class = $this->metadataFactory->getMetadataFor($cacheEntry->class);
         }
         if (($entity = $this->hydrator->loadCacheEntry($class, $cacheKey, $cacheEntry, $entity)) !== null) {
             if ($this->cacheLogger) {
                 $this->cacheLogger->entityCacheHit($this->regionName, $cacheKey);
             }
             return $entity;
         }
     }
     $entity = $this->persister->loadById($identifier, $entity);
     if ($entity === null) {
         return null;
     }
     $class = $this->class;
     $className = ClassUtils::getClass($entity);
     if ($className !== $this->class->name) {
         $class = $this->metadataFactory->getMetadataFor($className);
     }
     $cacheEntry = $this->hydrator->buildCacheEntry($class, $cacheKey, $entity);
     $cached = $this->region->put($cacheKey, $cacheEntry);
     if ($cached && ($this->joinedAssociations === null || count($this->joinedAssociations) > 0)) {
         $this->storeJoinedAssociations($entity);
     }
     if ($this->cacheLogger) {
         if ($cached) {
             $this->cacheLogger->entityCachePut($this->regionName, $cacheKey);
         }
         $this->cacheLogger->entityCacheMiss($this->regionName, $cacheKey);
     }
     return $entity;
 }
Example #23
0
 /**
  * @param string $attributeClass
  * @param ClassMetadataInfo $metadata
  * @param ClassMetadataFactory $metadataFactory
  */
 private function mapAttributeOnAttributeValue($attributeClass, ClassMetadataInfo $metadata, ClassMetadataFactory $metadataFactory)
 {
     $attributeMetadata = $metadataFactory->getMetadataFor($attributeClass);
     $attributeMapping = ['fieldName' => 'attribute', 'targetEntity' => $attributeClass, 'inversedBy' => 'values', 'joinColumns' => [['name' => 'attribute_id', 'referencedColumnName' => $attributeMetadata->fieldMappings['id']['columnName'], 'nullable' => false, 'onDelete' => 'CASCADE']]];
     $this->mapManyToOne($metadata, $attributeMapping);
 }
Example #24
0
 /**
  * Returns the metadata for a class.
  *
  * @return Doctrine\ORM\Mapping\ClassMetadata
  * @internal Performance-sensitive method.
  */
 public function getClassMetadata($className)
 {
     return $this->_metadataFactory->getMetadataFor($className);
 }
 public function setMetadataFor($className, $class)
 {
     $this->getCacheDriver()->save($className . $this->cacheSalt, $class, null);
     parent::setMetadataFor($className, $class);
 }
 /**
  * Returns the metadata for each managed entity.
  *
  * @param ClassMetadataFactory $metadataFactory
  * @return \Doctrine\Common\Persistence\Mapping\ClassMetadata[]
  */
 protected function getMetadataForSupportedEntities(ClassMetadataFactory $metadataFactory)
 {
     $metadata = array();
     foreach ($this->entityClasses as $class) {
         $metadata[] = $metadataFactory->getMetadataFor($class);
     }
     return $metadata;
 }
 /**
  * @group DDC-1845
  */
 public function testQuoteMetadata()
 {
     $cmf = new ClassMetadataFactory();
     $driver = $this->createAnnotationDriver(array(__DIR__ . '/../../Models/Quote/'));
     $em = $this->_createEntityManager($driver);
     $cmf->setEntityManager($em);
     $userMetadata = $cmf->getMetadataFor('Doctrine\\Tests\\Models\\Quote\\User');
     $phoneMetadata = $cmf->getMetadataFor('Doctrine\\Tests\\Models\\Quote\\Phone');
     $groupMetadata = $cmf->getMetadataFor('Doctrine\\Tests\\Models\\Quote\\Group');
     $addressMetadata = $cmf->getMetadataFor('Doctrine\\Tests\\Models\\Quote\\Address');
     // Phone Class Metadata
     $this->assertTrue($phoneMetadata->fieldMappings['number']['quoted']);
     $this->assertEquals('phone-number', $phoneMetadata->fieldMappings['number']['columnName']);
     $user = $phoneMetadata->associationMappings['user'];
     $this->assertTrue($user['joinColumns'][0]['quoted']);
     $this->assertEquals('user-id', $user['joinColumns'][0]['name']);
     $this->assertEquals('user-id', $user['joinColumns'][0]['referencedColumnName']);
     // User Group Metadata
     $this->assertTrue($groupMetadata->fieldMappings['id']['quoted']);
     $this->assertTrue($groupMetadata->fieldMappings['name']['quoted']);
     $this->assertEquals('user-id', $userMetadata->fieldMappings['id']['columnName']);
     $this->assertEquals('user-name', $userMetadata->fieldMappings['name']['columnName']);
     $user = $groupMetadata->associationMappings['parent'];
     $this->assertTrue($user['joinColumns'][0]['quoted']);
     $this->assertEquals('parent-id', $user['joinColumns'][0]['name']);
     $this->assertEquals('group-id', $user['joinColumns'][0]['referencedColumnName']);
     // Address Class Metadata
     $this->assertTrue($addressMetadata->fieldMappings['id']['quoted']);
     $this->assertTrue($addressMetadata->fieldMappings['zip']['quoted']);
     $this->assertEquals('address-id', $addressMetadata->fieldMappings['id']['columnName']);
     $this->assertEquals('address-zip', $addressMetadata->fieldMappings['zip']['columnName']);
     $user = $addressMetadata->associationMappings['user'];
     $this->assertTrue($user['joinColumns'][0]['quoted']);
     $this->assertEquals('user-id', $user['joinColumns'][0]['name']);
     $this->assertEquals('user-id', $user['joinColumns'][0]['referencedColumnName']);
     // User Class Metadata
     $this->assertTrue($userMetadata->fieldMappings['id']['quoted']);
     $this->assertTrue($userMetadata->fieldMappings['name']['quoted']);
     $this->assertEquals('user-id', $userMetadata->fieldMappings['id']['columnName']);
     $this->assertEquals('user-name', $userMetadata->fieldMappings['name']['columnName']);
     $address = $userMetadata->associationMappings['address'];
     $this->assertTrue($address['joinColumns'][0]['quoted']);
     $this->assertEquals('address-id', $address['joinColumns'][0]['name']);
     $this->assertEquals('address-id', $address['joinColumns'][0]['referencedColumnName']);
     $groups = $userMetadata->associationMappings['groups'];
     $this->assertTrue($groups['joinTable']['quoted']);
     $this->assertTrue($groups['joinTable']['joinColumns'][0]['quoted']);
     $this->assertEquals('quote-users-groups', $groups['joinTable']['name']);
     $this->assertEquals('user-id', $groups['joinTable']['joinColumns'][0]['name']);
     $this->assertEquals('user-id', $groups['joinTable']['joinColumns'][0]['referencedColumnName']);
     $this->assertTrue($groups['joinTable']['inverseJoinColumns'][0]['quoted']);
     $this->assertEquals('group-id', $groups['joinTable']['inverseJoinColumns'][0]['name']);
     $this->assertEquals('group-id', $groups['joinTable']['inverseJoinColumns'][0]['referencedColumnName']);
 }
 /**
  * @param array $association
  * @param array $ownerId
  *
  * @return CollectionCacheKey
  */
 protected function buildCollectionCacheKey(array $association, $ownerId)
 {
     /** @var ClassMetadata $metadata */
     $metadata = $this->metadataFactory->getMetadataFor($association['sourceEntity']);
     return new CollectionCacheKey($metadata->rootEntityName, $association['fieldName'], $ownerId);
 }
 /**
  * @group DDC-1590
  */
 public function testMethodsAndPropertiesAreNotDuplicatedInChildClasses()
 {
     $cmf = new ClassMetadataFactory();
     $em = $this->_getTestEntityManager();
     $cmf->setEntityManager($em);
     $ns = $this->_namespace;
     $nsdir = $this->_tmpDir . '/' . $ns;
     $content = str_replace('namespace Doctrine\\Tests\\Models\\DDC1590', 'namespace ' . $ns, file_get_contents(__DIR__ . '/../../Models/DDC1590/DDC1590User.php'));
     $fname = $nsdir . "/DDC1590User.php";
     file_put_contents($fname, $content);
     require $fname;
     $metadata = $cmf->getMetadataFor($ns . '\\DDC1590User');
     $this->_generator->writeEntityClass($metadata, $this->_tmpDir);
     // class DDC1590User extends DDC1590Entity { ... }
     $source = file_get_contents($fname);
     // class _DDC1590User extends DDC1590Entity { ... }
     $source2 = str_replace('class DDC1590User', 'class _DDC1590User', $source);
     $fname2 = $nsdir . "/_DDC1590User.php";
     file_put_contents($fname2, $source2);
     require $fname2;
     // class __DDC1590User { ... }
     $source3 = str_replace('class DDC1590User extends DDC1590Entity', 'class __DDC1590User', $source);
     $fname3 = $nsdir . "/__DDC1590User.php";
     file_put_contents($fname3, $source3);
     require $fname3;
     // class _DDC1590User extends DDC1590Entity { ... }
     $rc2 = new \ReflectionClass($ns . '\\_DDC1590User');
     $this->assertTrue($rc2->hasProperty('name'));
     $this->assertTrue($rc2->hasProperty('id'));
     $this->assertTrue($rc2->hasProperty('created_at'));
     $this->assertTrue($rc2->hasMethod('getName'));
     $this->assertTrue($rc2->hasMethod('setName'));
     $this->assertTrue($rc2->hasMethod('getId'));
     $this->assertFalse($rc2->hasMethod('setId'));
     $this->assertTrue($rc2->hasMethod('getCreatedAt'));
     $this->assertTrue($rc2->hasMethod('setCreatedAt'));
     // class __DDC1590User { ... }
     $rc3 = new \ReflectionClass($ns . '\\__DDC1590User');
     $this->assertTrue($rc3->hasProperty('name'));
     $this->assertFalse($rc3->hasProperty('id'));
     $this->assertFalse($rc3->hasProperty('created_at'));
     $this->assertTrue($rc3->hasMethod('getName'));
     $this->assertTrue($rc3->hasMethod('setName'));
     $this->assertFalse($rc3->hasMethod('getId'));
     $this->assertFalse($rc3->hasMethod('setId'));
     $this->assertFalse($rc3->hasMethod('getCreatedAt'));
     $this->assertFalse($rc3->hasMethod('setCreatedAt'));
 }
 public function testAddDefaultDiscriminatorMap()
 {
     $cmf = new ClassMetadataFactory();
     $driver = $this->createAnnotationDriver(array(__DIR__ . '/../../Models/JoinedInheritanceType/'));
     $em = $this->_createEntityManager($driver);
     $cmf->setEntityManager($em);
     $rootMetadata = $cmf->getMetadataFor('Doctrine\\Tests\\Models\\JoinedInheritanceType\\RootClass');
     $childMetadata = $cmf->getMetadataFor('Doctrine\\Tests\\Models\\JoinedInheritanceType\\ChildClass');
     $anotherChildMetadata = $cmf->getMetadataFor('Doctrine\\Tests\\Models\\JoinedInheritanceType\\AnotherChildClass');
     $rootDiscriminatorMap = $rootMetadata->discriminatorMap;
     $childDiscriminatorMap = $childMetadata->discriminatorMap;
     $anotherChildDiscriminatorMap = $anotherChildMetadata->discriminatorMap;
     $rootClass = 'Doctrine\\Tests\\Models\\JoinedInheritanceType\\RootClass';
     $childClass = 'Doctrine\\Tests\\Models\\JoinedInheritanceType\\ChildClass';
     $anotherChildClass = 'Doctrine\\Tests\\Models\\JoinedInheritanceType\\AnotherChildClass';
     $rootClassKey = array_search($rootClass, $rootDiscriminatorMap);
     $childClassKey = array_search($childClass, $rootDiscriminatorMap);
     $anotherChildClassKey = array_search($anotherChildClass, $rootDiscriminatorMap);
     $this->assertEquals('rootclass', $rootClassKey);
     $this->assertEquals('childclass', $childClassKey);
     $this->assertEquals('anotherchildclass', $anotherChildClassKey);
     $this->assertEquals($childDiscriminatorMap, $rootDiscriminatorMap);
     $this->assertEquals($anotherChildDiscriminatorMap, $rootDiscriminatorMap);
     // ClassMetadataFactory::addDefaultDiscriminatorMap shouldn't be called again, because the
     // discriminator map is already cached
     $cmf = $this->getMock('Doctrine\\ORM\\Mapping\\ClassMetadataFactory', array('addDefaultDiscriminatorMap'));
     $cmf->setEntityManager($em);
     $cmf->expects($this->never())->method('addDefaultDiscriminatorMap');
     $rootMetadata = $cmf->getMetadataFor('Doctrine\\Tests\\Models\\JoinedInheritanceType\\RootClass');
 }