Skip to content

Commit

Permalink
Merge branch 'hotfix/#1204-metadata-xml-exporter-should-export-sequen…
Browse files Browse the repository at this point in the history
…ce-generator-info'

Close #1204
  • Loading branch information
Ocramius committed Dec 4, 2014
2 parents 798a8b6 + c35f131 commit 8d4b46d
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ public function exportClassMetadata(ClassMetadataInfo $metadata)
if ($idGeneratorType = $this->_getIdGeneratorTypeString($metadata->generatorType)) {
$generatorXml = $idXml->addChild('generator');
$generatorXml->addAttribute('strategy', $idGeneratorType);

$this->exportSequenceInformation($idXml, $metadata);
}
}
}
Expand Down Expand Up @@ -411,6 +413,29 @@ private function exportTableOptions(\SimpleXMLElement $parentXml, array $options
}
}

/**
* Export sequence information (if available/configured) into the current identifier XML node
*
* @param \SimpleXMLElement $identifierXmlNode
* @param ClassMetadataInfo $metadata
*
* @return void
*/
private function exportSequenceInformation(\SimpleXMLElement $identifierXmlNode, ClassMetadataInfo $metadata)
{
$sequenceDefinition = $metadata->sequenceGeneratorDefinition;

if (! ($metadata->generatorType === ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE && $sequenceDefinition)) {
return;
}

$sequenceGeneratorXml = $identifierXmlNode->addChild('sequence-generator');

$sequenceGeneratorXml->addAttribute('sequence-name', $sequenceDefinition['sequenceName']);
$sequenceGeneratorXml->addAttribute('allocation-size', $sequenceDefinition['allocationSize']);
$sequenceGeneratorXml->addAttribute('initial-value', $sequenceDefinition['initialValue']);
}

/**
* @param \SimpleXMLElement $simpleXml
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
*/

namespace Doctrine\Tests\ORM\Tools\Export;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Tools\Export\Driver\XmlExporter;

/**
* Test case for XmlClassMetadataExporterTest
Expand All @@ -37,4 +40,44 @@ protected function _getType()
{
return 'xml';
}

/**
* @group DDC-3428
*/
public function testSequenceGenerator() {
$exporter = new XmlExporter();
$metadata = new ClassMetadata('entityTest');

$metadata->mapField(array(
"fieldName" => 'id',
"type" => 'integer',
"columnName" => 'id',
"id" => true,
));

$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE);
$metadata->setSequenceGeneratorDefinition(array(
'sequenceName' => 'seq_entity_test_id',
'allocationSize' => 5,
'initialValue' => 1
));

$expectedFileContent = <<<'XML'
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping
xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
>
<entity name="entityTest">
<id name="id" type="integer" column="id">
<generator strategy="SEQUENCE"/>
<sequence-generator sequence-name="seq_entity_test_id" allocation-size="5" initial-value="1"/>
</id>
</entity>
</doctrine-mapping>
XML;

$this->assertXmlStringEqualsXmlString($expectedFileContent, $exporter->exportClassMetadata($metadata));
}
}

0 comments on commit 8d4b46d

Please sign in to comment.