More ClassMetadataFactory tests
This commit is contained in:
parent
c2ab01bf7e
commit
7363fc3ec0
5 changed files with 58 additions and 19 deletions
|
@ -340,6 +340,7 @@ class Doctrine_ORM_Mapping_ClassMetadata
|
|||
public function __construct($entityName)
|
||||
{
|
||||
$this->_entityName = $entityName;
|
||||
$this->_tableName = $this->_entityName;
|
||||
$this->_rootEntityName = $entityName;
|
||||
$this->_reflectionClass = new ReflectionClass($entityName);
|
||||
$reflectionProps = $this->_reflectionClass->getProperties();
|
||||
|
|
|
@ -132,6 +132,7 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory
|
|||
$subClass->setInheritanceType($parent->getInheritanceType());
|
||||
$subClass->setDiscriminatorMap($parent->getDiscriminatorMap());
|
||||
$subClass->setDiscriminatorColumn($parent->getDiscriminatorColumn());
|
||||
$subClass->setIdGeneratorType($parent->getIdGeneratorType());
|
||||
$this->_addInheritedFields($subClass, $parent);
|
||||
$this->_addInheritedRelations($subClass, $parent);
|
||||
$this->_loadClassMetadata($subClass, $subclassName);
|
||||
|
@ -205,12 +206,6 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory
|
|||
|
||||
// load user-specified mapping metadata through the driver
|
||||
$this->_driver->loadMetadataForClass($name, $class);
|
||||
|
||||
// set default table name, if necessary
|
||||
$tableName = $class->getTableName();
|
||||
if ( ! isset($tableName)) {
|
||||
$class->setTableName(Doctrine::tableize($class->getClassName()));
|
||||
}
|
||||
|
||||
// Complete Id generator mapping. If AUTO is specified we choose the generator
|
||||
// most appropriate for the target platform.
|
||||
|
|
|
@ -28,7 +28,9 @@ class Doctrine_ORM_Mapping_Driver_AnnotationDriver {
|
|||
throw new Doctrine_ORM_Exceptions_MappingException("$className is no entity.");
|
||||
}
|
||||
|
||||
$metadata->setTableName($entityAnnot->tableName);
|
||||
if ($entityAnnot->tableName) {
|
||||
$metadata->setTableName($entityAnnot->tableName);
|
||||
}
|
||||
$metadata->setCustomRepositoryClass($entityAnnot->repositoryClass);
|
||||
|
||||
if ($inheritanceTypeAnnot = $annotClass->getAnnotation('DoctrineInheritanceType')) {
|
||||
|
|
|
@ -47,8 +47,8 @@ class Orm_EntityPersisterTest extends Doctrine_OrmTestCase
|
|||
$inserts = $this->_connMock->getInserts();
|
||||
//check
|
||||
$this->assertEquals(1, count($inserts));
|
||||
$this->assertTrue(isset($inserts['forum_avatar']));
|
||||
$this->assertEquals(1, count($inserts['forum_avatar']));
|
||||
$this->assertTrue(isset($inserts['ForumAvatar']));
|
||||
$this->assertEquals(1, count($inserts['ForumAvatar']));
|
||||
$this->assertEquals(null, $user->avatar->id);
|
||||
$user->avatar->id = 0; // Fake that we got an id
|
||||
|
||||
|
@ -58,18 +58,18 @@ class Orm_EntityPersisterTest extends Doctrine_OrmTestCase
|
|||
//check
|
||||
$this->assertEquals(2, count($inserts));
|
||||
$this->assertEquals(null, $user->id);
|
||||
$this->assertTrue(isset($inserts['forum_user']));
|
||||
$this->assertEquals(1, count($inserts['forum_user']));
|
||||
$this->assertEquals(3, count($inserts['forum_user'][0]));
|
||||
$this->assertTrue(isset($inserts['ForumUser']));
|
||||
$this->assertEquals(1, count($inserts['ForumUser']));
|
||||
$this->assertEquals(3, count($inserts['ForumUser'][0]));
|
||||
//username column
|
||||
$this->assertTrue(isset($inserts['forum_user'][0]['username']));
|
||||
$this->assertEquals('romanb', $inserts['forum_user'][0]['username']);
|
||||
$this->assertTrue(isset($inserts['ForumUser'][0]['username']));
|
||||
$this->assertEquals('romanb', $inserts['ForumUser'][0]['username']);
|
||||
//avatar_id join column
|
||||
$this->assertTrue(isset($inserts['forum_user'][0]['avatar_id']));
|
||||
$this->assertEquals(0, $inserts['forum_user'][0]['avatar_id']);
|
||||
$this->assertTrue(isset($inserts['ForumUser'][0]['avatar_id']));
|
||||
$this->assertEquals(0, $inserts['ForumUser'][0]['avatar_id']);
|
||||
//dtype discriminator column
|
||||
$this->assertTrue(isset($inserts['forum_user'][0]['dtype']));
|
||||
$this->assertEquals('user', $inserts['forum_user'][0]['dtype']);
|
||||
$this->assertTrue(isset($inserts['ForumUser'][0]['dtype']));
|
||||
$this->assertEquals('user', $inserts['ForumUser'][0]['dtype']);
|
||||
}
|
||||
|
||||
}
|
|
@ -13,12 +13,43 @@ require_once 'lib/mocks/Doctrine_MetadataDriverMock.php';
|
|||
* @author robo
|
||||
*/
|
||||
class Orm_Mapping_ClassMetadataFactoryTest extends Doctrine_OrmTestCase {
|
||||
|
||||
public function testGetMetadataForSingleClass() {
|
||||
//TODO
|
||||
$mockPlatform = new Doctrine_DatabasePlatformMock();
|
||||
$mockDriver = new Doctrine_MetadataDriverMock();
|
||||
|
||||
// Self-made metadata
|
||||
$cm1 = new Doctrine_ORM_Mapping_ClassMetadata('CMFTest_Entity1');
|
||||
// Add a mapped field
|
||||
$cm1->mapField(array('fieldName' => 'name', 'type' => 'string'));
|
||||
// and a mapped association
|
||||
$cm1->mapOneToOne(array('fieldName' => 'other', 'targetEntity' => 'Other', 'mappedBy' => 'this'));
|
||||
// and an id generator type
|
||||
$cm1->setIdGeneratorType('auto');
|
||||
|
||||
// SUT
|
||||
$cmf = new ClassMetadataFactoryTestSubject($mockDriver, $mockPlatform);
|
||||
$cmf->setMetadataForClass('CMFTest_Entity1', $cm1);
|
||||
|
||||
// Prechecks
|
||||
$this->assertEquals(array(), $cm1->getParentClasses());
|
||||
$this->assertEquals('none', $cm1->getInheritanceType());
|
||||
$this->assertTrue($cm1->hasField('name'));
|
||||
$this->assertEquals(1, count($cm1->getAssociationMappings()));
|
||||
$this->assertEquals('auto', $cm1->getIdGeneratorType());
|
||||
|
||||
// Go
|
||||
$cm1 = $cmf->getMetadataFor('CMFTest_Entity1');
|
||||
|
||||
$this->assertEquals(array(), $cm1->getParentClasses());
|
||||
$this->assertTrue($cm1->hasField('name'));
|
||||
// The default fallback for id generation is the table strategy
|
||||
$this->assertEquals('table', $cm1->getIdGeneratorType());
|
||||
}
|
||||
|
||||
public function testGetMetadataForClassInHierarchy() {
|
||||
$mockPlatform = new Doctrine_DatabasePlatformMock();
|
||||
$mockPlatform->setPrefersIdentityColumns(true);
|
||||
$mockDriver = new Doctrine_MetadataDriverMock();
|
||||
|
||||
// Self-made metadata
|
||||
|
@ -28,6 +59,9 @@ class Orm_Mapping_ClassMetadataFactoryTest extends Doctrine_OrmTestCase {
|
|||
$cm1->mapField(array('fieldName' => 'name', 'type' => 'string'));
|
||||
// and a mapped association
|
||||
$cm1->mapOneToOne(array('fieldName' => 'other', 'targetEntity' => 'Other', 'mappedBy' => 'this'));
|
||||
// and an id generator type
|
||||
$cm1->setIdGeneratorType('auto');
|
||||
|
||||
$cm2 = new Doctrine_ORM_Mapping_ClassMetadata('CMFTest_Entity2');
|
||||
$cm3 = new Doctrine_ORM_Mapping_ClassMetadata('CMFTest_Entity3');
|
||||
|
||||
|
@ -48,6 +82,8 @@ class Orm_Mapping_ClassMetadataFactoryTest extends Doctrine_OrmTestCase {
|
|||
$this->assertEquals(1, count($cm1->getAssociationMappings()));
|
||||
$this->assertEquals(0, count($cm2->getAssociationMappings()));
|
||||
$this->assertEquals(0, count($cm3->getAssociationMappings()));
|
||||
$this->assertEquals('none', $cm2->getIdGeneratorType());
|
||||
$this->assertEquals('none', $cm3->getIdGeneratorType());
|
||||
|
||||
// Go
|
||||
$cm3 = $cmf->getMetadataFor('CMFTest_Entity3');
|
||||
|
@ -70,6 +106,11 @@ class Orm_Mapping_ClassMetadataFactoryTest extends Doctrine_OrmTestCase {
|
|||
$this->assertEquals(1, count($cm3->getAssociationMappings()));
|
||||
$this->assertTrue($cm2->hasAssociation('other'));
|
||||
$this->assertTrue($cm3->hasAssociation('other'));
|
||||
// Id generator 'auto' should have been resolved to 'identity' as preferred by our
|
||||
// mock platform (see above). And it should be inherited.
|
||||
$this->assertEquals('identity', $cm1->getIdGeneratorType());
|
||||
$this->assertEquals('identity', $cm2->getIdGeneratorType());
|
||||
$this->assertEquals('identity', $cm3->getIdGeneratorType());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue