/**
  * @expectedException Prezent\Doctrine\Translatable\Mapping\MappingException
  */
 public function testClassMetadataValidation()
 {
     $classMetadata = new ClassMetadata('Prezent\\Tests\\Fixture\\BadMappingTranslation');
     $classMetadata->initializeReflection(new RuntimeReflectionService());
     $eventArgs = new LoadClassMetadataEventArgs($classMetadata, $this->getEntityManager());
     $this->getTranslatableListener()->loadClassMetadata($eventArgs);
 }
Ejemplo n.º 2
0
 /**
  * @group DDC-268
  */
 public function testColumnWithMissingTypeDefaultsToString()
 {
     $cm = new ClassMetadata('Doctrine\\Tests\\ORM\\Mapping\\ColumnWithoutType');
     $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $annotationDriver = $this->_loadDriver();
     $annotationDriver->loadMetadataForClass('Doctrine\\Tests\\ORM\\Mapping\\InvalidColumn', $cm);
     $this->assertEquals('string', $cm->fieldMappings['id']['type']);
 }
Ejemplo n.º 3
0
 /**
  * @group DDC-1771
  */
 public function testSkipAbstractClassesOnGeneration()
 {
     $cm = new ClassMetadata(__NAMESPACE__ . '\\AbstractClass');
     $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $this->assertNotNull($cm->reflClass);
     $num = $this->proxyFactory->generateProxyClasses(array($cm));
     $this->assertEquals(0, $num, "No proxies generated.");
 }
 public function createClassMetadata($entityClassName)
 {
     $mappingDriver = $this->_loadDriver();
     $class = new ClassMetadata($entityClassName);
     $class->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $mappingDriver->loadMetadataForClass($entityClassName, $class);
     return $class;
 }
Ejemplo n.º 5
0
 public function testGetTableName()
 {
     $cm = $this->createClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
     $cm->setPrimaryTable(array('name' => '`cms_user`'));
     $this->assertEquals('"cms_user"', $this->strategy->getTableName($cm, $this->platform));
     $cm = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
     $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $cm->setPrimaryTable(array('name' => 'cms_user'));
     $this->assertEquals('cms_user', $this->strategy->getTableName($cm, $this->platform));
 }
Ejemplo n.º 6
0
 public function testClassTableInheritanceDiscriminatorMap()
 {
     $className = 'Doctrine\\Tests\\ORM\\Mapping\\CTI';
     $mappingDriver = $this->_loadDriver();
     $class = new ClassMetadata($className);
     $class->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $mappingDriver->loadMetadataForClass($className, $class);
     $expectedMap = array('foo' => 'Doctrine\\Tests\\ORM\\Mapping\\CTIFoo', 'bar' => 'Doctrine\\Tests\\ORM\\Mapping\\CTIBar', 'baz' => 'Doctrine\\Tests\\ORM\\Mapping\\CTIBaz');
     $this->assertEquals(3, count($class->discriminatorMap));
     $this->assertEquals($expectedMap, $class->discriminatorMap);
 }
Ejemplo n.º 7
0
 public function createClassMetadata(GClass $gClass)
 {
     // da wir gClass mehrmals im Test evalen könnten, erzeugen wir einen unique hash für den classname und übergeben den
     // der class metadata
     $className = uniqid($gClass->getClassName());
     $gClass->setClassName($className);
     $gClass->createDocBlock()->addAnnotation(Annotation::createDC('Entity'));
     $classWriter = new ClassWriter($gClass);
     $classWriter->setUseStyle('lines');
     $classWriter->addImport(new GClass('Doctrine\\ORM\\Mapping'), 'ORM');
     // braucht einen AnnotationReader nicht SimpleAnnotationReader
     $classWriter->write($file = $this->newFile('entity.' . $gClass->getClassName() . '.php'));
     require $file;
     $cm = new ClassMetadata($gClass->getFQN());
     $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $this->annotationDriver->loadMetadataForClass($gClass->getFQN(), $cm);
     $file->delete();
     return $cm;
 }
 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'));
 }
Ejemplo n.º 9
0
 public function testDoctrineProxy()
 {
     $className = 'Saxulum\\Tests\\Accessor\\Fixtures\\Entity\\Entity';
     $proxyDirectory = __DIR__ . '/../proxy/';
     $proxyNamespace = 'Proxy';
     $proxyClassName = $proxyNamespace . '\\__CG__\\' . $className;
     $proxyClassFilename = $proxyDirectory . str_replace('\\', '_', $proxyClassName) . '.php';
     if (!is_dir($proxyDirectory)) {
         mkdir($proxyDirectory, 0777, true);
     }
     $reflectionService = new RuntimeReflectionService();
     $classMetadata = new ClassMetadata(get_class(new Entity()));
     $classMetadata->initializeReflection($reflectionService);
     $proxyGenerator = new ProxyGenerator($proxyDirectory, $proxyNamespace);
     $proxyGenerator->generateProxyClass($classMetadata, $proxyClassFilename);
     require $proxyClassFilename;
     /** @var Entity $proxy */
     $proxy = new $proxyClassName();
     $proxy->setName('test');
     $this->assertEquals('test', $proxy->getName());
     unlink($proxyClassFilename);
     //rmdir($proxyDirectory);
 }
Ejemplo n.º 10
0
 /**
  * @group DDC-1746
  */
 public function testInvalidCascade()
 {
     $cm = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
     $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $this->setExpectedException("Doctrine\\ORM\\Mapping\\MappingException", "Invalid cascade option(s) specified: 'invalid'. Only 'remove', 'persist', 'refresh', 'merge' and 'detach' are allowed.");
     $cm->mapManyToOne(array('fieldName' => 'address', 'targetEntity' => 'UnknownClass', 'cascade' => array('invalid')));
 }
 /**
  * @group ImproveErrorMessages
  */
 public function testTargetEntityNotFound()
 {
     $cm = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
     $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $cm->mapManyToOne(array('fieldName' => 'address', 'targetEntity' => 'UnknownClass'));
     $this->setExpectedException("Doctrine\\ORM\\Mapping\\MappingException", "The target-entity Doctrine\\Tests\\Models\\CMS\\UnknownClass cannot be found in 'Doctrine\\Tests\\Models\\CMS\\CmsUser#address'.");
     $cm->validateAssocations();
 }
 /**
  * Returns the class names of additional entities that are directly associated with
  * one of the entities that is explicitly mentioned in the given configuration.
  *
  * @param Configuration $config
  * @param string[] $entityClasses Classes whose associations are checked.
  * @return string[] Associated entity classes.
  */
 protected function getDirectlyAssociatedEntities(Configuration $config, $entityClasses)
 {
     if (count($entityClasses) === 0) {
         return array();
     }
     $associatedEntities = array();
     foreach ($entityClasses as $entityClass) {
         /* @var $entityClass string */
         $metadata = new ClassMetadata($entityClass);
         $metadata->initializeReflection($this->reflectionService);
         $config->getMetadataDriverImpl()->loadMetadataForClass($entityClass, $metadata);
         foreach ($metadata->getAssociationNames() as $name) {
             /* @var $name string */
             $associatedEntity = $metadata->getAssociationTargetClass($name);
             $associatedEntities[] = $metadata->fullyQualifiedClassName($associatedEntity);
         }
         if (count($metadata->discriminatorMap) > 0) {
             $childClasses = array_values($metadata->discriminatorMap);
             $associatedEntities = array_merge($associatedEntities, $childClasses);
         }
         // Add parent classes that are involved in some kind of entity inheritance.
         foreach ($this->reflectionService->getParentClasses($entityClass) as $parentClass) {
             if (!$config->getMetadataDriverImpl()->isTransient($parentClass)) {
                 $associatedEntities[] = $parentClass;
             }
         }
     }
     return array_unique($associatedEntities);
 }
Ejemplo n.º 13
0
 /**
  * @param   string $className
  * @return \Doctrine\ORM\Mapping\ClassMetadata
  */
 private function createClassMetadata($className)
 {
     $class = new ClassMetadata($className);
     $class->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     return $class;
 }
 public function setUp()
 {
     $this->cm = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
     $this->cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $this->builder = new ClassMetadataBuilder($this->cm);
 }
Ejemplo n.º 15
0
 /**
  * @group DDC-3120
  */
 public function testCanInstantiateInternalPhpClassSubclass()
 {
     $classMetadata = new ClassMetadata(__NAMESPACE__ . '\\MyArrayObjectEntity');
     $classMetadata->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $this->assertInstanceOf(__NAMESPACE__ . '\\MyArrayObjectEntity', $classMetadata->newInstance());
 }
Ejemplo n.º 16
0
 /**
  * @group DDC-2662
  */
 public function testQuotedSequenceName()
 {
     $cm = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
     $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $cm->setSequenceGeneratorDefinition(array('sequenceName' => '`foo`'));
     $this->assertEquals(array('sequenceName' => 'foo', 'quoted' => true), $cm->sequenceGeneratorDefinition);
 }
Ejemplo n.º 17
0
 /**
  * @group DDC-964
  * @expectedException        Doctrine\ORM\Mapping\MappingException
  * @expectedExceptionMessage The column type of attribute 'name' on class 'Doctrine\Tests\Models\DDC964\DDC964Guest' could not be changed.
  */
 public function testInvalidOverrideAttributeFieldTypeException()
 {
     $cm = new ClassMetadata('Doctrine\\Tests\\Models\\DDC964\\DDC964Guest');
     $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $cm->mapField(array('fieldName' => 'name', 'type' => 'string'));
     $cm->setAttributeOverride('name', array('type' => 'date'));
 }
Ejemplo n.º 18
0
 /**
  * @group DDC-1663
  */
 public function testAddNamedNativeQueryResultClass()
 {
     $cm = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
     $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $cm->addNamedNativeQuery(array('name' => 'find-all', 'resultClass' => '__CLASS__', 'query' => 'SELECT * FROM cms_users'));
     $queryMapping = $cm->getNamedNativeQuery('find-all');
     $rsm = new \Doctrine\ORM\Query\ResultSetMappingBuilder($this->_em);
     $rsm->addNamedNativeQueryMapping($cm, $queryMapping);
     $this->assertEquals('c0', $rsm->getEntityAlias('id'));
     $this->assertEquals('c0', $rsm->getEntityAlias('name'));
     $this->assertEquals('c0', $rsm->getEntityAlias('status'));
     $this->assertEquals('c0', $rsm->getEntityAlias('username'));
     $this->assertEquals('Doctrine\\Tests\\Models\\CMS\\CmsUser', $rsm->getClassName('c0'));
     $this->assertEquals('Doctrine\\Tests\\Models\\CMS\\CmsUser', $rsm->getDeclaringClass('id'));
     $this->assertEquals('Doctrine\\Tests\\Models\\CMS\\CmsUser', $rsm->getDeclaringClass('name'));
     $this->assertEquals('Doctrine\\Tests\\Models\\CMS\\CmsUser', $rsm->getDeclaringClass('status'));
     $this->assertEquals('Doctrine\\Tests\\Models\\CMS\\CmsUser', $rsm->getDeclaringClass('username'));
 }
 /**
  * @param string $class
  * @return ClassMetadata
  */
 protected function _createValidClassMetadata()
 {
     // 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);
     return $cm1;
 }
Ejemplo n.º 20
0
 /**
  * @group DDC-3272
  */
 public function testMappedSuperclassAnnotationGeneration()
 {
     $metadata = new ClassMetadataInfo($this->_namespace . '\\EntityGeneratorBook');
     $metadata->namespace = $this->_namespace;
     $metadata->isMappedSuperclass = true;
     $this->_generator->setAnnotationPrefix('ORM\\');
     $this->_generator->writeEntityClass($metadata, $this->_tmpDir);
     $this->newInstance($metadata);
     // force instantiation (causes autoloading to kick in)
     $driver = new AnnotationDriver(new AnnotationReader(), array());
     $cm = new ClassMetadata($metadata->name);
     $cm->initializeReflection(new RuntimeReflectionService());
     $driver->loadMetadataForClass($cm->name, $cm);
     $this->assertTrue($cm->isMappedSuperclass);
 }
Ejemplo n.º 21
0
 /**
  * @group DDC-984
  * @group DDC-559
  * @group DDC-1575
  */
 public function testFullyQualifiedClassNameShouldBeGivenToNamingStrategy()
 {
     $namingStrategy = new MyNamespacedNamingStrategy();
     $addressMetadata = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsAddress', $namingStrategy);
     $articleMetadata = new ClassMetadata('DoctrineGlobal_Article', $namingStrategy);
     $routingMetadata = new ClassMetadata('Doctrine\\Tests\\Models\\Routing\\RoutingLeg', $namingStrategy);
     $addressMetadata->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $articleMetadata->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $routingMetadata->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $addressMetadata->mapManyToMany(array('fieldName' => 'user', 'targetEntity' => 'CmsUser'));
     $articleMetadata->mapManyToMany(array('fieldName' => 'author', 'targetEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser'));
     $this->assertEquals('routing_routingleg', $routingMetadata->table['name']);
     $this->assertEquals('cms_cmsaddress_cms_cmsuser', $addressMetadata->associationMappings['user']['joinTable']['name']);
     $this->assertEquals('doctrineglobal_article_cms_cmsuser', $articleMetadata->associationMappings['author']['joinTable']['name']);
 }