diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php index 14ff8322d..1d539c9f2 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php @@ -171,6 +171,8 @@ class XmlExporter extends AbstractExporter if ($idGeneratorType = $this->_getIdGeneratorTypeString($metadata->generatorType)) { $generatorXml = $idXml->addChild('generator'); $generatorXml->addAttribute('strategy', $idGeneratorType); + + $this->exportSequenceInformation($idXml, $metadata); } } } @@ -411,6 +413,29 @@ class XmlExporter extends AbstractExporter } } + /** + * 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 * diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/XmlClassMetadataExporterTest.php b/tests/Doctrine/Tests/ORM/Tools/Export/XmlClassMetadataExporterTest.php index e5392ddcc..0fe58b4ec 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/XmlClassMetadataExporterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/XmlClassMetadataExporterTest.php @@ -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 @@ -37,4 +40,44 @@ class XmlClassMetadataExporterTest extends AbstractClassMetadataExporterTest { 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; + + $this->assertXmlStringEqualsXmlString($expectedFileContent, $exporter->exportClassMetadata($metadata)); + } }