[2.0] DDC-367 - Fixed Bug with <discriminator-map /> XML Driver Parsing
This commit is contained in:
parent
a1a8093888
commit
cbd8133308
@ -85,7 +85,11 @@ class XmlDriver extends AbstractFileDriver
|
||||
|
||||
// Evaluate <discriminator-map...>
|
||||
if (isset($xmlRoot->{'discriminator-map'})) {
|
||||
$metadata->setDiscriminatorMap((array)$xmlRoot->{'discriminator-map'});
|
||||
$map = array();
|
||||
foreach ($xmlRoot->{'discriminator-map'}->{'discriminator-mapping'} AS $discrMapElement) {
|
||||
$map[(string)$discrMapElement['value']] = (string)$discrMapElement['class'];
|
||||
}
|
||||
$metadata->setDiscriminatorMap($map);
|
||||
}
|
||||
|
||||
// Evaluate <change-tracking-policy...>
|
||||
|
@ -14,4 +14,31 @@ class XmlMappingDriverTest extends AbstractMappingDriverTest
|
||||
{
|
||||
return new XmlDriver(__DIR__ . DIRECTORY_SEPARATOR . 'xml');
|
||||
}
|
||||
}
|
||||
|
||||
public function testClassTableInheritanceDiscriminatorMap()
|
||||
{
|
||||
$className = 'Doctrine\Tests\ORM\Mapping\CTI';
|
||||
$mappingDriver = $this->_loadDriver();
|
||||
|
||||
$class = new ClassMetadata($className);
|
||||
$mappingDriver->loadMetadataForClass($className, $class);
|
||||
|
||||
$expectedMap = array(
|
||||
"foo" => "Doctrine\Tests\ORM\Mapping\CTIFoo",
|
||||
"bar" => "Doctrine\Tests\ORM\Mapping\CTIBar",
|
||||
"baz" => "Doctrine\Tests\ORM\Mapping\CTIBaz",
|
||||
);
|
||||
|
||||
$this->assertEquals(3, count($class->discriminatorMap));
|
||||
$this->assertEquals($expectedMap, $class->discriminatorMap);
|
||||
}
|
||||
}
|
||||
|
||||
class CTI
|
||||
{
|
||||
public $id;
|
||||
}
|
||||
|
||||
class CTIFoo extends CTI {}
|
||||
class CTIBar extends CTI {}
|
||||
class CTIBaz extends CTI {}
|
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
<entity name="Doctrine\Tests\ORM\Mapping\CTI">
|
||||
<discriminiator-column name="discr" type="string" length=""/>
|
||||
<discriminator-map>
|
||||
<discriminator-mapping value="foo" class="CTIFoo"/>
|
||||
<discriminator-mapping value="bar" class="CTIBar"/>
|
||||
<discriminator-mapping value="baz" class="CTIBaz"/>
|
||||
</discriminator-map>
|
||||
<id name="id" type="integer" column="id">
|
||||
<generator strategy="AUTO"/>
|
||||
</id>
|
||||
</entity>
|
||||
</doctrine-mapping>
|
Loading…
Reference in New Issue
Block a user