Ejemplo n.º 1
0
 /**
  * @param \Doctrine\ORM\EntityManager $entityClassName
  * @return \Doctrine\ORM\Mapping\ClassMetadataFactory
  */
 protected function createClassMetadataFactory(\Doctrine\ORM\EntityManager $em = null)
 {
     $driver = $this->_loadDriver();
     $em = $em ?: $this->_getTestEntityManager();
     $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
     $em->getConfiguration()->setMetadataDriverImpl($driver);
     $factory->setEntityManager($em);
     return $factory;
 }
Ejemplo n.º 2
0
 public function testIdentifierWithAssociationKey()
 {
     $driver = $this->_loadDriver();
     $em = $this->_getTestEntityManager();
     $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
     $em->getConfiguration()->setMetadataDriverImpl($driver);
     $factory->setEntityManager($em);
     $class = $factory->getMetadataFor('Doctrine\\Tests\\Models\\DDC117\\DDC117Translation');
     $this->assertEquals(array('language', 'article'), $class->identifier);
     $this->assertArrayHasKey('article', $class->associationMappings);
     $this->assertArrayHasKey('id', $class->associationMappings['article']);
     $this->assertTrue($class->associationMappings['article']['id']);
 }
 /**
  * @group DDC-671
  *
  * Entities for this test are in AbstractMappingDriverTest
  */
 public function testJoinTablesWithMappedSuperclassForYamlDriver()
 {
     $yamlDriver = $this->_loadDriver();
     $yamlDriver->addPaths(array(__DIR__ . DIRECTORY_SEPARATOR . 'yaml'));
     $em = $this->_getTestEntityManager();
     $em->getConfiguration()->setMetadataDriverImpl($yamlDriver);
     $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
     $factory->setEntityManager($em);
     $classPage = new ClassMetadata('Doctrine\\Tests\\Models\\DirectoryTree\\File');
     $classPage = $factory->getMetadataFor('Doctrine\\Tests\\Models\\DirectoryTree\\File');
     $this->assertEquals('Doctrine\\Tests\\Models\\DirectoryTree\\File', $classPage->associationMappings['parentDirectory']['sourceEntity']);
     $classDirectory = new ClassMetadata('Doctrine\\Tests\\Models\\DirectoryTree\\Directory');
     $classDirectory = $factory->getMetadataFor('Doctrine\\Tests\\Models\\DirectoryTree\\Directory');
     $this->assertEquals('Doctrine\\Tests\\Models\\DirectoryTree\\Directory', $classDirectory->associationMappings['parentDirectory']['sourceEntity']);
 }
 /**
  * @group DDC-945
  */
 public function testInvalidMappedSuperClassWithManyToManyAssociation()
 {
     $annotationDriver = $this->_loadDriver();
     $em = $this->_getTestEntityManager();
     $em->getConfiguration()->setMetadataDriverImpl($annotationDriver);
     $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
     $factory->setEntityManager($em);
     $this->setExpectedException('Doctrine\\ORM\\Mapping\\MappingException', "It is illegal to put an inverse side one-to-many or many-to-many association on " . "mapped superclass 'Doctrine\\Tests\\ORM\\Mapping\\InvalidMappedSuperClass#users'");
     $usingInvalidMsc = $factory->getMetadataFor('Doctrine\\Tests\\ORM\\Mapping\\UsingInvalidMappedSuperClass');
 }
Ejemplo n.º 5
0
 /**
  * @group DDC-1476
  */
 public function testDefaultFieldType()
 {
     $driver = $this->_loadDriver();
     $em = $this->_getTestEntityManager();
     $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
     $em->getConfiguration()->setMetadataDriverImpl($driver);
     $factory->setEntityManager($em);
     $class = $factory->getMetadataFor('Doctrine\\Tests\\Models\\DDC1476\\DDC1476EntityWithDefaultFieldType');
     $this->assertArrayHasKey('id', $class->fieldMappings);
     $this->assertArrayHasKey('name', $class->fieldMappings);
     $this->assertArrayHasKey('type', $class->fieldMappings['id']);
     $this->assertArrayHasKey('type', $class->fieldMappings['name']);
     $this->assertEquals('string', $class->fieldMappings['id']['type']);
     $this->assertEquals('string', $class->fieldMappings['name']['type']);
     $this->assertArrayHasKey('fieldName', $class->fieldMappings['id']);
     $this->assertArrayHasKey('fieldName', $class->fieldMappings['name']);
     $this->assertEquals('id', $class->fieldMappings['id']['fieldName']);
     $this->assertEquals('name', $class->fieldMappings['name']['fieldName']);
     $this->assertArrayHasKey('columnName', $class->fieldMappings['id']);
     $this->assertArrayHasKey('columnName', $class->fieldMappings['name']);
     $this->assertEquals('id', $class->fieldMappings['id']['columnName']);
     $this->assertEquals('name', $class->fieldMappings['name']['columnName']);
     $this->assertEquals(ClassMetadataInfo::GENERATOR_TYPE_NONE, $class->generatorType);
 }
 /**
  * @group DDC-559
  */
 public function testNamingStrategy()
 {
     $driver = $this->_loadDriver();
     $em = $this->_getTestEntityManager();
     $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
     $em->getConfiguration()->setMetadataDriverImpl($driver);
     $factory->setEntityManager($em);
     $this->assertInstanceOf('Doctrine\\ORM\\Mapping\\DefaultNamingStrategy', $em->getConfiguration()->getNamingStrategy());
     $em->getConfiguration()->setNamingStrategy(new \Doctrine\ORM\Mapping\UnderscoreNamingStrategy(CASE_UPPER));
     $this->assertInstanceOf('Doctrine\\ORM\\Mapping\\UnderscoreNamingStrategy', $em->getConfiguration()->getNamingStrategy());
     $class = $factory->getMetadataFor('Doctrine\\Tests\\Models\\DDC1476\\DDC1476EntityWithDefaultFieldType');
     $this->assertEquals('ID', $class->columnNames['id']);
     $this->assertEquals('NAME', $class->columnNames['name']);
     $this->assertEquals('DDC1476ENTITY_WITH_DEFAULT_FIELD_TYPE', $class->table['name']);
 }
Ejemplo n.º 7
0
 public function testInvalidFetchOptionThrowsException()
 {
     $annotationDriver = $this->_loadDriver();
     $em = $this->_getTestEntityManager();
     $em->getConfiguration()->setMetadataDriverImpl($annotationDriver);
     $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
     $factory->setEntityManager($em);
     $this->setExpectedException('Doctrine\\Common\\Annotations\\AnnotationException', '[Enum Error] Attribute "fetch" of @Doctrine\\ORM\\Mapping\\OneToMany declared on property Doctrine\\Tests\\ORM\\Mapping\\InvalidFetchOption::$collection accept only [LAZY, EAGER, EXTRA_LAZY], but got eager.');
     $cm = $factory->getMetadataFor('Doctrine\\Tests\\ORM\\Mapping\\InvalidFetchOption');
 }
Ejemplo n.º 8
0
 /**
  * @group DDC-1034
  */
 public function testInheritanceSkipsParentLifecycleCallbacks()
 {
     $annotationDriver = $this->_loadDriver();
     
     $cm = new ClassMetadata('Doctrine\Tests\ORM\Mapping\AnnotationChild');
     $em = $this->_getTestEntityManager();
     $em->getConfiguration()->setMetadataDriverImpl($annotationDriver);
     $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
     $factory->setEntityManager($em);
     
     $cm = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\AnnotationChild');
     $this->assertEquals(array("postLoad" => array("postLoad"), "preUpdate" => array("preUpdate")), $cm->lifecycleCallbacks);
     
     $cm = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\AnnotationParent');
     $this->assertEquals(array("postLoad" => array("postLoad"), "preUpdate" => array("preUpdate")), $cm->lifecycleCallbacks);
 }
 /**
  * @group DDC-1156
  */
 public function testMappedSuperclassInMiddleOfInheritanceHierachy()
 {
     $annotationDriver = $this->_loadDriver();
     $em = $this->_getTestEntityManager();
     $em->getConfiguration()->setMetadataDriverImpl($annotationDriver);
     $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
     $factory->setEntityManager($em);
     $cm = $factory->getMetadataFor('Doctrine\\Tests\\ORM\\Mapping\\ChildEntity');
 }
Ejemplo n.º 10
0
 public function testInvalidFetchOptionThrowsException()
 {
     $annotationDriver = $this->_loadDriver();
     $em = $this->_getTestEntityManager();
     $em->getConfiguration()->setMetadataDriverImpl($annotationDriver);
     $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
     $factory->setEntityManager($em);
     $this->setExpectedException('Doctrine\\ORM\\Mapping\\MappingException', "Entity 'Doctrine\\Tests\\ORM\\Mapping\\InvalidFetchOption' has a mapping with invalid fetch mode 'eager");
     $cm = $factory->getMetadataFor('Doctrine\\Tests\\ORM\\Mapping\\InvalidFetchOption');
 }