[2.0] DDC-115 - Proper fix of global namespace problem was in the ClassMetadataInfo, a namespace plus seperator was appended for reasons of shortcuts. However this broke associations in global namespace. Changes to ClassMetadataFactory were reverted and fix plus tests applied to ClassMetadataInfo.
This commit is contained in:
parent
705a477067
commit
884131e51f
@ -102,10 +102,6 @@ class ClassMetadataFactory
|
||||
*/
|
||||
public function getMetadataFor($className)
|
||||
{
|
||||
if($className[0] == "\\") {
|
||||
$className = substr($className, 1);
|
||||
}
|
||||
|
||||
if ( ! isset($this->_loadedMetadata[$className])) {
|
||||
$cacheKey = "$className\$CLASSMETADATA";
|
||||
if ($this->_cacheDriver) {
|
||||
@ -130,10 +126,6 @@ class ClassMetadataFactory
|
||||
*/
|
||||
public function hasMetadataFor($className)
|
||||
{
|
||||
if($className[0] == "\\") {
|
||||
$className = substr($className, 1);
|
||||
}
|
||||
|
||||
return isset($this->_loadedMetadata[$className]);
|
||||
}
|
||||
|
||||
@ -147,10 +139,6 @@ class ClassMetadataFactory
|
||||
*/
|
||||
public function setMetadataFor($className, $class)
|
||||
{
|
||||
if($className[0] == "\\") {
|
||||
$className = substr($className, 1);
|
||||
}
|
||||
|
||||
$this->_loadedMetadata[$className] = $class;
|
||||
}
|
||||
|
||||
|
@ -1032,7 +1032,7 @@ class ClassMetadataInfo
|
||||
public function setSubclasses(array $subclasses)
|
||||
{
|
||||
foreach ($subclasses as $subclass) {
|
||||
if (strpos($subclass, '\\') === false) {
|
||||
if (strpos($subclass, '\\') === false && strlen($this->namespace)) {
|
||||
$this->subClasses[] = $this->namespace . '\\' . $subclass;
|
||||
} else {
|
||||
$this->subClasses[] = $subclass;
|
||||
@ -1203,7 +1203,7 @@ class ClassMetadataInfo
|
||||
private function _completeAssociationMapping(array $mapping)
|
||||
{
|
||||
$mapping['sourceEntity'] = $this->name;
|
||||
if (isset($mapping['targetEntity']) && strpos($mapping['targetEntity'], '\\') === false) {
|
||||
if (isset($mapping['targetEntity']) && strpos($mapping['targetEntity'], '\\') === false && strlen($this->namespace) > 0) {
|
||||
$mapping['targetEntity'] = $this->namespace . '\\' . $mapping['targetEntity'];
|
||||
}
|
||||
return $mapping;
|
||||
@ -1480,7 +1480,7 @@ class ClassMetadataInfo
|
||||
public function setDiscriminatorMap(array $map)
|
||||
{
|
||||
foreach ($map as $value => $className) {
|
||||
if (strpos($className, '\\') === false) {
|
||||
if (strpos($className, '\\') === false && strlen($this->namespace)) {
|
||||
$className = $this->namespace . '\\' . $className;
|
||||
}
|
||||
$this->discriminatorMap[$value] = $className;
|
||||
|
@ -59,7 +59,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase
|
||||
$this->assertEquals(ClassMetadata::GENERATOR_TYPE_SEQUENCE, $cm1->generatorType);
|
||||
}
|
||||
|
||||
public function testGetMetadataGlobalNamespaceModel()
|
||||
public function testHasGetMetadata_NamespaceSeperatorIsNotNormalized()
|
||||
{
|
||||
require_once __DIR__."/../../Models/Global/GlobalNamespaceModel.php";
|
||||
|
||||
@ -72,11 +72,13 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
$mf = $entityManager->getMetadataFactory();
|
||||
$m1 = $mf->getMetadataFor("DoctrineGlobal_Article");
|
||||
$h1 = $mf->hasMetadataFor("DoctrineGlobal_Article");
|
||||
$h2 = $mf->hasMetadataFor("\DoctrineGlobal_Article");
|
||||
$m2 = $mf->getMetadataFor("\DoctrineGlobal_Article");
|
||||
|
||||
$this->assertSame($m1, $m2);
|
||||
$this->assertTrue($h2);
|
||||
$this->assertNotSame($m1, $m2);
|
||||
$this->assertFalse($h2);
|
||||
$this->assertTrue($h1);
|
||||
}
|
||||
|
||||
protected function _createEntityManager($metadataDriver)
|
||||
|
@ -65,4 +65,52 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
|
||||
$cm->mapField(array('fieldName' => 'name', 'type' => 'string', 'length' => 50));
|
||||
$this->assertFalse($cm->isNullable('name'), "By default a field should not be nullable.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-115
|
||||
*/
|
||||
public function testMapAssocationInGlobalNamespace()
|
||||
{
|
||||
require_once __DIR__."/../../Models/Global/GlobalNamespaceModel.php";
|
||||
|
||||
$cm = new ClassMetadata('DoctrineGlobal_Article');
|
||||
$cm->mapManyToMany(array(
|
||||
'fieldName' => 'author',
|
||||
'targetEntity' => 'DoctrineGlobal_User',
|
||||
'joinTable' => array(
|
||||
'name' => 'bar',
|
||||
'joinColumns' => array(array('name' => 'bar_id', 'referencedColumnName' => 'id')),
|
||||
'inverseJoinColumns' => array(array('name' => 'baz_id', 'referencedColumnName' => 'id')),
|
||||
),
|
||||
));
|
||||
|
||||
$this->assertEquals("DoctrineGlobal_User", $cm->associationMappings['author']->targetEntityName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-115
|
||||
*/
|
||||
public function testSetDiscriminatorMapInGlobalNamespace()
|
||||
{
|
||||
require_once __DIR__."/../../Models/Global/GlobalNamespaceModel.php";
|
||||
|
||||
$cm = new ClassMetadata('DoctrineGlobal_User');
|
||||
$cm->setDiscriminatorMap(array('descr' => 'DoctrineGlobal_Article', 'foo' => 'DoctrineGlobal_User'));
|
||||
|
||||
$this->assertEquals("DoctrineGlobal_Article", $cm->discriminatorMap['descr']);
|
||||
$this->assertEquals("DoctrineGlobal_User", $cm->discriminatorMap['foo']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-115
|
||||
*/
|
||||
public function testSetSubClassesInGlobalNamespace()
|
||||
{
|
||||
require_once __DIR__."/../../Models/Global/GlobalNamespaceModel.php";
|
||||
|
||||
$cm = new ClassMetadata('DoctrineGlobal_User');
|
||||
$cm->setSubclasses(array('DoctrineGlobal_Article'));
|
||||
|
||||
$this->assertEquals("DoctrineGlobal_Article", $cm->subClasses[0]);
|
||||
}
|
||||
}
|
@ -60,7 +60,7 @@ class ConvertDoctrine1SchemaTest extends \Doctrine\Tests\OrmTestCase
|
||||
$this->assertEquals(3, count($metadatas['User']->fieldMappings));
|
||||
|
||||
$this->assertEquals('Profile', $metadatas['Profile']->associationMappings['User']->sourceEntityName);
|
||||
$this->assertEquals('\User', $metadatas['Profile']->associationMappings['User']->targetEntityName);
|
||||
$this->assertEquals('User', $metadatas['Profile']->associationMappings['User']->targetEntityName);
|
||||
|
||||
$this->assertEquals('username', $metadatas['User']->primaryTable['indexes']['username']['columns'][0]);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user