1
0
mirror of synced 2024-12-14 15:16:04 +03:00

DCOM-93 - Factor out ClassMetadata constructor into delegate method initializeReflection

This commit is contained in:
Benjamin Eberlei 2012-01-02 17:06:22 +01:00
parent 1cecc9c429
commit c7d8c9f34e
8 changed files with 81 additions and 45 deletions

View File

@ -62,12 +62,15 @@ class ClassMetadata extends ClassMetadataInfo implements IClassMetadata
* *
* @param string $entityName The name of the entity class the new instance is used for. * @param string $entityName The name of the entity class the new instance is used for.
*/ */
public function __construct($entityName) public function initializeReflection($reflService)
{ {
$this->reflClass = new ReflectionClass($entityName); $this->reflClass = $reflService->getClass($this->name);
$this->namespace = $this->reflClass->getNamespaceName(); $this->namespace = $reflService->getClassNamespace($this->name);
$this->table['name'] = $this->reflClass->getShortName(); $this->table['name'] = $reflService->getClassShortName($this->name);
parent::__construct($this->reflClass->getName()); // do not use $entityName, possible case-problems
if ($this->reflClass) {
$this->name = $this->rootEntityName = $this->reflClass->getName();
}
} }
/** /**
@ -324,37 +327,6 @@ class ClassMetadata extends ClassMetadataInfo implements IClassMetadata
return $serialized; return $serialized;
} }
/**
* Restores some state that can not be serialized/unserialized.
*
* @param ReflectionService $reflService
* @return void
*/
public function wakeupReflection($reflService)
{
// Restore ReflectionClass and properties
$this->reflClass = $reflService->getClass($this->name);
foreach ($this->fieldMappings as $field => $mapping) {
$reflField = isset($mapping['declared'])
? $reflService->getAccessibleProperty($mapping['declared'], $field)
: $reflService->getAccessibleProperty($this->name, $field);
$this->reflFields[$field] = $reflField;
}
foreach ($this->associationMappings as $field => $mapping) {
$reflField = isset($mapping['declared'])
? $reflService->getAccessibleProperty($mapping['declared'], $field)
: $reflService->getAccessibleProperty($this->name, $field);
$this->reflFields[$field] = $reflField;
}
}
public function initializeReflection($reflService)
{
}
/** /**
* Creates a new instance of the mapped class, without invoking the constructor. * Creates a new instance of the mapped class, without invoking the constructor.
* *

View File

@ -588,5 +588,6 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
*/ */
protected function initializeReflection(ClassMetadataInfo $class, ReflectionService $reflService) protected function initializeReflection(ClassMetadataInfo $class, ReflectionService $reflService)
{ {
$class->initializeReflection($reflService);
} }
} }

View File

@ -18,6 +18,7 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
$mappingDriver = $this->_loadDriver(); $mappingDriver = $this->_loadDriver();
$class = new ClassMetadata($entityClassName); $class = new ClassMetadata($entityClassName);
$class->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$mappingDriver->loadMetadataForClass($entityClassName, $class); $mappingDriver->loadMetadataForClass($entityClassName, $class);
return $class; return $class;

View File

@ -40,6 +40,7 @@ class ClassMetadataBuilderTest extends \Doctrine\Tests\OrmTestCase
public function setUp() public function setUp()
{ {
$this->cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $this->cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$this->cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$this->builder = new ClassMetadataBuilder($this->cm); $this->builder = new ClassMetadataBuilder($this->cm);
} }

View File

@ -27,6 +27,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase
// Self-made metadata // Self-made metadata
$cm1 = new ClassMetadata('Doctrine\Tests\ORM\Mapping\TestEntity1'); $cm1 = new ClassMetadata('Doctrine\Tests\ORM\Mapping\TestEntity1');
$cm1->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$cm1->setPrimaryTable(array('name' => '`group`')); $cm1->setPrimaryTable(array('name' => '`group`'));
// Add a mapped field // Add a mapped field
$cm1->mapField(array('fieldName' => 'name', 'type' => 'varchar')); $cm1->mapField(array('fieldName' => 'name', 'type' => 'varchar'));
@ -43,9 +44,9 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase
$cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_AUTO); $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_AUTO);
// SUT // SUT
$cmf = new ClassMetadataFactoryTestSubject(); $cmf = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
$cmf->setEntityManager($entityManager); $cmf->setEntityManager($entityManager);
$cmf->setMetadataForClass('Doctrine\Tests\ORM\Mapping\TestEntity1', $cm1); $cmf->setMetadataFor('Doctrine\Tests\ORM\Mapping\TestEntity1', $cm1);
// Prechecks // Prechecks
$this->assertEquals(array(), $cm1->parentClasses); $this->assertEquals(array(), $cm1->parentClasses);
@ -53,15 +54,16 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase
$this->assertTrue($cm1->hasField('name')); $this->assertTrue($cm1->hasField('name'));
$this->assertEquals(2, count($cm1->associationMappings)); $this->assertEquals(2, count($cm1->associationMappings));
$this->assertEquals(ClassMetadata::GENERATOR_TYPE_AUTO, $cm1->generatorType); $this->assertEquals(ClassMetadata::GENERATOR_TYPE_AUTO, $cm1->generatorType);
$this->assertEquals('group', $cm1->table['name']);
// Go // Go
$cm1 = $cmf->getMetadataFor('Doctrine\Tests\ORM\Mapping\TestEntity1'); $cmMap1 = $cmf->getMetadataFor('Doctrine\Tests\ORM\Mapping\TestEntity1');
$this->assertEquals('group', $cm1->table['name']); $this->assertSame($cm1, $cmMap1);
$this->assertTrue($cm1->table['quoted']); $this->assertEquals('group', $cmMap1->table['name']);
$this->assertEquals(array(), $cm1->parentClasses); $this->assertTrue($cmMap1->table['quoted']);
$this->assertTrue($cm1->hasField('name')); $this->assertEquals(array(), $cmMap1->parentClasses);
$this->assertEquals(ClassMetadata::GENERATOR_TYPE_SEQUENCE, $cm1->generatorType); $this->assertTrue($cmMap1->hasField('name'));
} }
public function testHasGetMetadata_NamespaceSeperatorIsNotNormalized() public function testHasGetMetadata_NamespaceSeperatorIsNotNormalized()

View File

@ -13,6 +13,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
public function testClassMetadataInstanceSerialization() public function testClassMetadataInstanceSerialization()
{ {
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
// Test initial state // Test initial state
$this->assertTrue(count($cm->getReflectionProperties()) == 0); $this->assertTrue(count($cm->getReflectionProperties()) == 0);
@ -61,6 +62,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
public function testFieldIsNullable() public function testFieldIsNullable()
{ {
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
// Explicit Nullable // Explicit Nullable
$cm->mapField(array('fieldName' => 'status', 'nullable' => true, 'type' => 'string', 'length' => 50)); $cm->mapField(array('fieldName' => 'status', 'nullable' => true, 'type' => 'string', 'length' => 50));
@ -83,6 +85,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
require_once __DIR__."/../../Models/Global/GlobalNamespaceModel.php"; require_once __DIR__."/../../Models/Global/GlobalNamespaceModel.php";
$cm = new ClassMetadata('DoctrineGlobal_Article'); $cm = new ClassMetadata('DoctrineGlobal_Article');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$cm->mapManyToMany(array( $cm->mapManyToMany(array(
'fieldName' => 'author', 'fieldName' => 'author',
'targetEntity' => 'DoctrineGlobal_User', 'targetEntity' => 'DoctrineGlobal_User',
@ -99,6 +102,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
public function testMapManyToManyJoinTableDefaults() public function testMapManyToManyJoinTableDefaults()
{ {
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$cm->mapManyToMany( $cm->mapManyToMany(
array( array(
'fieldName' => 'groups', 'fieldName' => 'groups',
@ -118,6 +122,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
public function testSerializeManyToManyJoinTableCascade() public function testSerializeManyToManyJoinTableCascade()
{ {
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$cm->mapManyToMany( $cm->mapManyToMany(
array( array(
'fieldName' => 'groups', 'fieldName' => 'groups',
@ -139,6 +144,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
require_once __DIR__."/../../Models/Global/GlobalNamespaceModel.php"; require_once __DIR__."/../../Models/Global/GlobalNamespaceModel.php";
$cm = new ClassMetadata('DoctrineGlobal_User'); $cm = new ClassMetadata('DoctrineGlobal_User');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$cm->setDiscriminatorMap(array('descr' => 'DoctrineGlobal_Article', 'foo' => 'DoctrineGlobal_User')); $cm->setDiscriminatorMap(array('descr' => 'DoctrineGlobal_Article', 'foo' => 'DoctrineGlobal_User'));
$this->assertEquals("DoctrineGlobal_Article", $cm->discriminatorMap['descr']); $this->assertEquals("DoctrineGlobal_Article", $cm->discriminatorMap['descr']);
@ -153,6 +159,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
require_once __DIR__."/../../Models/Global/GlobalNamespaceModel.php"; require_once __DIR__."/../../Models/Global/GlobalNamespaceModel.php";
$cm = new ClassMetadata('DoctrineGlobal_User'); $cm = new ClassMetadata('DoctrineGlobal_User');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$cm->setSubclasses(array('DoctrineGlobal_Article')); $cm->setSubclasses(array('DoctrineGlobal_Article'));
$this->assertEquals("DoctrineGlobal_Article", $cm->subClasses[0]); $this->assertEquals("DoctrineGlobal_Article", $cm->subClasses[0]);
@ -168,6 +175,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
$field['type'] = 'string'; $field['type'] = 'string';
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->setExpectedException('Doctrine\ORM\Mapping\MappingException');
$cm->setVersionMapping($field); $cm->setVersionMapping($field);
@ -176,6 +184,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
public function testGetSingleIdentifierFieldName_MultipleIdentifierEntity_ThrowsException() public function testGetSingleIdentifierFieldName_MultipleIdentifierEntity_ThrowsException()
{ {
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$cm->isIdentifierComposite = true; $cm->isIdentifierComposite = true;
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->setExpectedException('Doctrine\ORM\Mapping\MappingException');
@ -185,6 +194,8 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
public function testDuplicateAssociationMappingException() public function testDuplicateAssociationMappingException()
{ {
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$a1 = array('fieldName' => 'foo', 'sourceEntity' => 'stdClass', 'targetEntity' => 'stdClass', 'mappedBy' => 'foo'); $a1 = array('fieldName' => 'foo', 'sourceEntity' => 'stdClass', 'targetEntity' => 'stdClass', 'mappedBy' => 'foo');
$a2 = array('fieldName' => 'foo', 'sourceEntity' => 'stdClass', 'targetEntity' => 'stdClass', 'mappedBy' => 'foo'); $a2 = array('fieldName' => 'foo', 'sourceEntity' => 'stdClass', 'targetEntity' => 'stdClass', 'mappedBy' => 'foo');
@ -196,6 +207,8 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
public function testDuplicateColumnName_ThrowsMappingException() public function testDuplicateColumnName_ThrowsMappingException()
{ {
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$cm->mapField(array('fieldName' => 'name', 'columnName' => 'name')); $cm->mapField(array('fieldName' => 'name', 'columnName' => 'name'));
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->setExpectedException('Doctrine\ORM\Mapping\MappingException');
@ -205,6 +218,8 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
public function testDuplicateColumnName_DiscriminatorColumn_ThrowsMappingException() public function testDuplicateColumnName_DiscriminatorColumn_ThrowsMappingException()
{ {
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$cm->mapField(array('fieldName' => 'name', 'columnName' => 'name')); $cm->mapField(array('fieldName' => 'name', 'columnName' => 'name'));
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->setExpectedException('Doctrine\ORM\Mapping\MappingException');
@ -214,6 +229,8 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
public function testDuplicateColumnName_DiscriminatorColumn2_ThrowsMappingException() public function testDuplicateColumnName_DiscriminatorColumn2_ThrowsMappingException()
{ {
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$cm->setDiscriminatorColumn(array('name' => 'name')); $cm->setDiscriminatorColumn(array('name' => 'name'));
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->setExpectedException('Doctrine\ORM\Mapping\MappingException');
@ -223,6 +240,8 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
public function testDuplicateFieldAndAssocationMapping1_ThrowsException() public function testDuplicateFieldAndAssocationMapping1_ThrowsException()
{ {
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$cm->mapField(array('fieldName' => 'name', 'columnName' => 'name')); $cm->mapField(array('fieldName' => 'name', 'columnName' => 'name'));
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->setExpectedException('Doctrine\ORM\Mapping\MappingException');
@ -232,6 +251,8 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
public function testDuplicateFieldAndAssocationMapping2_ThrowsException() public function testDuplicateFieldAndAssocationMapping2_ThrowsException()
{ {
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$cm->mapOneToOne(array('fieldName' => 'name', 'targetEntity' => 'CmsUser')); $cm->mapOneToOne(array('fieldName' => 'name', 'targetEntity' => 'CmsUser'));
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->setExpectedException('Doctrine\ORM\Mapping\MappingException');
@ -244,6 +265,8 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
public function testGetTemporaryTableNameSchema() public function testGetTemporaryTableNameSchema()
{ {
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$cm->setTableName('foo.bar'); $cm->setTableName('foo.bar');
$this->assertEquals('foo_bar_id_tmp', $cm->getTemporaryIdTableName()); $this->assertEquals('foo_bar_id_tmp', $cm->getTemporaryIdTableName());
@ -252,6 +275,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
public function testDefaultTableName() public function testDefaultTableName()
{ {
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
// When table's name is not given // When table's name is not given
$primaryTable = array(); $primaryTable = array();
@ -261,6 +285,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
$this->assertEquals('CmsUser', $cm->table['name']); $this->assertEquals('CmsUser', $cm->table['name']);
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
// When joinTable's name is not given // When joinTable's name is not given
$cm->mapManyToMany(array( $cm->mapManyToMany(array(
'fieldName' => 'user', 'fieldName' => 'user',
@ -274,6 +299,8 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
public function testDefaultJoinColumnName() public function testDefaultJoinColumnName()
{ {
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
// this is really dirty, but it's the simpliest way to test whether // this is really dirty, but it's the simpliest way to test whether
// joinColumn's name will be automatically set to user_id // joinColumn's name will be automatically set to user_id
$cm->mapOneToOne(array( $cm->mapOneToOne(array(
@ -283,6 +310,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
$this->assertEquals('user_id', $cm->associationMappings['user']['joinColumns'][0]['name']); $this->assertEquals('user_id', $cm->associationMappings['user']['joinColumns'][0]['name']);
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$cm->mapManyToMany(array( $cm->mapManyToMany(array(
'fieldName' => 'user', 'fieldName' => 'user',
'targetEntity' => 'CmsUser', 'targetEntity' => 'CmsUser',
@ -300,6 +328,8 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
public function testSetMultipleIdentifierSetsComposite() public function testSetMultipleIdentifierSetsComposite()
{ {
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$cm->mapField(array('fieldName' => 'name')); $cm->mapField(array('fieldName' => 'name'));
$cm->mapField(array('fieldName' => 'username')); $cm->mapField(array('fieldName' => 'username'));
@ -313,6 +343,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
public function testMappingNotFound() public function testMappingNotFound()
{ {
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException', "No mapping found for field 'foo' on class 'Doctrine\Tests\Models\CMS\CmsUser'."); $this->setExpectedException('Doctrine\ORM\Mapping\MappingException', "No mapping found for field 'foo' on class 'Doctrine\Tests\Models\CMS\CmsUser'.");
$cm->getFieldMapping('foo'); $cm->getFieldMapping('foo');
@ -324,6 +355,8 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
public function testJoinTableMappingDefaults() public function testJoinTableMappingDefaults()
{ {
$cm = new ClassMetadata('DoctrineGlobal_Article'); $cm = new ClassMetadata('DoctrineGlobal_Article');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$cm->mapManyToMany(array('fieldName' => 'author', 'targetEntity' => 'Doctrine\Tests\Models\CMS\CmsUser')); $cm->mapManyToMany(array('fieldName' => 'author', 'targetEntity' => 'Doctrine\Tests\Models\CMS\CmsUser'));
$this->assertEquals('doctrineglobal_article_cmsuser', $cm->associationMappings['author']['joinTable']['name']); $this->assertEquals('doctrineglobal_article_cmsuser', $cm->associationMappings['author']['joinTable']['name']);
@ -335,6 +368,8 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
public function testMapIdentifierAssociation() public function testMapIdentifierAssociation()
{ {
$cm = new ClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); $cm = new ClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$cm->mapOneToOne(array( $cm->mapOneToOne(array(
'fieldName' => 'article', 'fieldName' => 'article',
'id' => true, 'id' => true,
@ -352,6 +387,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
public function testOrphanRemovalIdentifierAssociation() public function testOrphanRemovalIdentifierAssociation()
{ {
$cm = new ClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); $cm = new ClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException', 'The orphan removal option is not allowed on an association that'); $this->setExpectedException('Doctrine\ORM\Mapping\MappingException', 'The orphan removal option is not allowed on an association that');
$cm->mapOneToOne(array( $cm->mapOneToOne(array(
@ -369,6 +405,8 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
public function testInverseIdentifierAssocation() public function testInverseIdentifierAssocation()
{ {
$cm = new ClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); $cm = new ClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException', 'An inverse association is not allowed to be identifier in'); $this->setExpectedException('Doctrine\ORM\Mapping\MappingException', 'An inverse association is not allowed to be identifier in');
$cm->mapOneToOne(array( $cm->mapOneToOne(array(
@ -386,6 +424,8 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
public function testIdentifierAssocationManyToMany() public function testIdentifierAssocationManyToMany()
{ {
$cm = new ClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); $cm = new ClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException', 'Many-to-many or one-to-many associations are not allowed to be identifier in'); $this->setExpectedException('Doctrine\ORM\Mapping\MappingException', 'Many-to-many or one-to-many associations are not allowed to be identifier in');
$cm->mapManyToMany(array( $cm->mapManyToMany(array(
@ -404,12 +444,16 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException', $this->setExpectedException('Doctrine\ORM\Mapping\MappingException',
"The field or association mapping misses the 'fieldName' attribute in entity 'Doctrine\Tests\Models\CMS\CmsUser'."); "The field or association mapping misses the 'fieldName' attribute in entity 'Doctrine\Tests\Models\CMS\CmsUser'.");
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$cm->mapField(array('fieldName' => '')); $cm->mapField(array('fieldName' => ''));
} }
public function testRetrievalOfNamedQueries() public function testRetrievalOfNamedQueries()
{ {
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$this->assertEquals(0, count($cm->getNamedQueries())); $this->assertEquals(0, count($cm->getNamedQueries()));
@ -424,6 +468,8 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
public function testExistanceOfNamedQuery() public function testExistanceOfNamedQuery()
{ {
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$cm->addNamedQuery(array( $cm->addNamedQuery(array(
'name' => 'all', 'name' => 'all',
@ -437,6 +483,8 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
public function testRetrieveOfNamedQuery() public function testRetrieveOfNamedQuery()
{ {
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$cm->addNamedQuery(array( $cm->addNamedQuery(array(
'name' => 'userById', 'name' => 'userById',
@ -449,6 +497,8 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
public function testNamingCollisionNamedQueryShouldThrowException() public function testNamingCollisionNamedQueryShouldThrowException()
{ {
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->setExpectedException('Doctrine\ORM\Mapping\MappingException');
@ -470,6 +520,8 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
{ {
$user = new \Doctrine\Tests\Models\CMS\CmsUser(); $user = new \Doctrine\Tests\Models\CMS\CmsUser();
$cm = new ClassMetadata('DOCTRINE\TESTS\MODELS\CMS\CMSUSER'); $cm = new ClassMetadata('DOCTRINE\TESTS\MODELS\CMS\CMSUSER');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->name); $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->name);
} }
@ -479,6 +531,8 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
public function testLifecycleCallbackNotFound() public function testLifecycleCallbackNotFound()
{ {
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$this->setExpectedException("Doctrine\ORM\Mapping\MappingException", "Entity 'Doctrine\Tests\Models\CMS\CmsUser' has no method 'notfound' to be registered as lifecycle callback."); $this->setExpectedException("Doctrine\ORM\Mapping\MappingException", "Entity 'Doctrine\Tests\Models\CMS\CmsUser' has no method 'notfound' to be registered as lifecycle callback.");
$cm->addLifecycleCallback('notfound', 'postLoad'); $cm->addLifecycleCallback('notfound', 'postLoad');
@ -490,6 +544,8 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
public function testTargetEntityNotFound() public function testTargetEntityNotFound()
{ {
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$this->setExpectedException("Doctrine\ORM\Mapping\MappingException", "The target-entity Doctrine\Tests\Models\CMS\UnknownClass cannot be found in 'Doctrine\Tests\Models\CMS\CmsUser#address'."); $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->mapManyToOne(array('fieldName' => 'address', 'targetEntity' => 'UnknownClass')); $cm->mapManyToOne(array('fieldName' => 'address', 'targetEntity' => 'UnknownClass'));

View File

@ -21,6 +21,7 @@ class XmlMappingDriverTest extends AbstractMappingDriverTest
$mappingDriver = $this->_loadDriver(); $mappingDriver = $this->_loadDriver();
$class = new ClassMetadata($className); $class = new ClassMetadata($className);
$class->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$mappingDriver->loadMetadataForClass($className, $class); $mappingDriver->loadMetadataForClass($className, $class);
$expectedMap = array( $expectedMap = array(

View File

@ -127,6 +127,7 @@ class ProxyClassGeneratorTest extends \Doctrine\Tests\OrmTestCase
$className = "\DoctrineOrmTestEntity"; $className = "\DoctrineOrmTestEntity";
$proxyName = "DoctrineOrmTestEntityProxy"; $proxyName = "DoctrineOrmTestEntityProxy";
$classMetadata = new \Doctrine\ORM\Mapping\ClassMetadata($className); $classMetadata = new \Doctrine\ORM\Mapping\ClassMetadata($className);
$classMetadata->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$classMetadata->mapField(array('fieldName' => 'id', 'type' => 'integer')); $classMetadata->mapField(array('fieldName' => 'id', 'type' => 'integer'));
$classMetadata->setIdentifier(array('id')); $classMetadata->setIdentifier(array('id'));
@ -143,6 +144,7 @@ class ProxyClassGeneratorTest extends \Doctrine\Tests\OrmTestCase
$className = "\Doctrine\Tests\ORM\Proxy\SleepClass"; $className = "\Doctrine\Tests\ORM\Proxy\SleepClass";
$proxyName = "DoctrineTestsORMProxySleepClassProxy"; $proxyName = "DoctrineTestsORMProxySleepClassProxy";
$classMetadata = new \Doctrine\ORM\Mapping\ClassMetadata($className); $classMetadata = new \Doctrine\ORM\Mapping\ClassMetadata($className);
$classMetadata->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$classMetadata->mapField(array('fieldName' => 'id', 'type' => 'integer')); $classMetadata->mapField(array('fieldName' => 'id', 'type' => 'integer'));
$classMetadata->setIdentifier(array('id')); $classMetadata->setIdentifier(array('id'));