Commit cbd81333 authored by beberlei's avatar beberlei

[2.0] DDC-367 - Fixed Bug with <discriminator-map /> XML Driver Parsing

parent a1a80938
......@@ -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 {}
\ No newline at end of file
<?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>
\ No newline at end of file
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