Commit 884131e5 authored by beberlei's avatar beberlei

[2.0] DDC-115 - Proper fix of global namespace problem was in the...

[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.
parent 705a4770
...@@ -102,10 +102,6 @@ class ClassMetadataFactory ...@@ -102,10 +102,6 @@ class ClassMetadataFactory
*/ */
public function getMetadataFor($className) public function getMetadataFor($className)
{ {
if($className[0] == "\\") {
$className = substr($className, 1);
}
if ( ! isset($this->_loadedMetadata[$className])) { if ( ! isset($this->_loadedMetadata[$className])) {
$cacheKey = "$className\$CLASSMETADATA"; $cacheKey = "$className\$CLASSMETADATA";
if ($this->_cacheDriver) { if ($this->_cacheDriver) {
...@@ -130,10 +126,6 @@ class ClassMetadataFactory ...@@ -130,10 +126,6 @@ class ClassMetadataFactory
*/ */
public function hasMetadataFor($className) public function hasMetadataFor($className)
{ {
if($className[0] == "\\") {
$className = substr($className, 1);
}
return isset($this->_loadedMetadata[$className]); return isset($this->_loadedMetadata[$className]);
} }
...@@ -147,10 +139,6 @@ class ClassMetadataFactory ...@@ -147,10 +139,6 @@ class ClassMetadataFactory
*/ */
public function setMetadataFor($className, $class) public function setMetadataFor($className, $class)
{ {
if($className[0] == "\\") {
$className = substr($className, 1);
}
$this->_loadedMetadata[$className] = $class; $this->_loadedMetadata[$className] = $class;
} }
......
...@@ -1032,7 +1032,7 @@ class ClassMetadataInfo ...@@ -1032,7 +1032,7 @@ class ClassMetadataInfo
public function setSubclasses(array $subclasses) public function setSubclasses(array $subclasses)
{ {
foreach ($subclasses as $subclass) { foreach ($subclasses as $subclass) {
if (strpos($subclass, '\\') === false) { if (strpos($subclass, '\\') === false && strlen($this->namespace)) {
$this->subClasses[] = $this->namespace . '\\' . $subclass; $this->subClasses[] = $this->namespace . '\\' . $subclass;
} else { } else {
$this->subClasses[] = $subclass; $this->subClasses[] = $subclass;
...@@ -1203,7 +1203,7 @@ class ClassMetadataInfo ...@@ -1203,7 +1203,7 @@ class ClassMetadataInfo
private function _completeAssociationMapping(array $mapping) private function _completeAssociationMapping(array $mapping)
{ {
$mapping['sourceEntity'] = $this->name; $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']; $mapping['targetEntity'] = $this->namespace . '\\' . $mapping['targetEntity'];
} }
return $mapping; return $mapping;
...@@ -1480,7 +1480,7 @@ class ClassMetadataInfo ...@@ -1480,7 +1480,7 @@ class ClassMetadataInfo
public function setDiscriminatorMap(array $map) public function setDiscriminatorMap(array $map)
{ {
foreach ($map as $value => $className) { foreach ($map as $value => $className) {
if (strpos($className, '\\') === false) { if (strpos($className, '\\') === false && strlen($this->namespace)) {
$className = $this->namespace . '\\' . $className; $className = $this->namespace . '\\' . $className;
} }
$this->discriminatorMap[$value] = $className; $this->discriminatorMap[$value] = $className;
......
...@@ -59,7 +59,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase ...@@ -59,7 +59,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase
$this->assertEquals(ClassMetadata::GENERATOR_TYPE_SEQUENCE, $cm1->generatorType); $this->assertEquals(ClassMetadata::GENERATOR_TYPE_SEQUENCE, $cm1->generatorType);
} }
public function testGetMetadataGlobalNamespaceModel() public function testHasGetMetadata_NamespaceSeperatorIsNotNormalized()
{ {
require_once __DIR__."/../../Models/Global/GlobalNamespaceModel.php"; require_once __DIR__."/../../Models/Global/GlobalNamespaceModel.php";
...@@ -72,11 +72,13 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase ...@@ -72,11 +72,13 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase
$mf = $entityManager->getMetadataFactory(); $mf = $entityManager->getMetadataFactory();
$m1 = $mf->getMetadataFor("DoctrineGlobal_Article"); $m1 = $mf->getMetadataFor("DoctrineGlobal_Article");
$h1 = $mf->hasMetadataFor("DoctrineGlobal_Article");
$h2 = $mf->hasMetadataFor("\DoctrineGlobal_Article"); $h2 = $mf->hasMetadataFor("\DoctrineGlobal_Article");
$m2 = $mf->getMetadataFor("\DoctrineGlobal_Article"); $m2 = $mf->getMetadataFor("\DoctrineGlobal_Article");
$this->assertSame($m1, $m2); $this->assertNotSame($m1, $m2);
$this->assertTrue($h2); $this->assertFalse($h2);
$this->assertTrue($h1);
} }
protected function _createEntityManager($metadataDriver) protected function _createEntityManager($metadataDriver)
......
...@@ -65,4 +65,52 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase ...@@ -65,4 +65,52 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
$cm->mapField(array('fieldName' => 'name', 'type' => 'string', 'length' => 50)); $cm->mapField(array('fieldName' => 'name', 'type' => 'string', 'length' => 50));
$this->assertFalse($cm->isNullable('name'), "By default a field should not be nullable."); $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]);
}
} }
\ No newline at end of file
...@@ -60,7 +60,7 @@ class ConvertDoctrine1SchemaTest extends \Doctrine\Tests\OrmTestCase ...@@ -60,7 +60,7 @@ class ConvertDoctrine1SchemaTest extends \Doctrine\Tests\OrmTestCase
$this->assertEquals(3, count($metadatas['User']->fieldMappings)); $this->assertEquals(3, count($metadatas['User']->fieldMappings));
$this->assertEquals('Profile', $metadatas['Profile']->associationMappings['User']->sourceEntityName); $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]); $this->assertEquals('username', $metadatas['User']->primaryTable['indexes']['username']['columns'][0]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment