1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
<?php
declare(strict_types=1);
namespace Doctrine\Tests\ORM\Tools\Export;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Tools\Export\Driver\XmlExporter;
/**
* Test case for XmlClassMetadataExporterTest
*
* @link http://www.phpdoctrine.org
*/
class XmlClassMetadataExporterTest extends ClassMetadataExporterTestCase
{
protected function getType(): string
{
return 'xml';
}
/** @group DDC-3428 */
public function testSequenceGenerator(): void
{
$exporter = new XmlExporter();
$metadata = new ClassMetadata('entityTest');
$metadata->mapField(
[
'fieldName' => 'id',
'type' => 'integer',
'columnName' => 'id',
'id' => true,
]
);
$metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_SEQUENCE);
$metadata->setSequenceGeneratorDefinition(
[
'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 https://www.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;
self::assertXmlStringEqualsXmlString($expectedFileContent, $exporter->exportClassMetadata($metadata));
}
/**
* @group 1214
* @group 1216
* @group DDC-3439
*/
public function testFieldOptionsExport(): void
{
$exporter = new XmlExporter();
$metadata = new ClassMetadata('entityTest');
$metadata->mapField(
[
'fieldName' => 'myField',
'type' => 'string',
'columnName' => 'my_field',
'options' => [
'default' => 'default_string',
'comment' => 'The comment for the field',
],
]
);
$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 https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="entityTest">
<field name="myField" type="string" column="my_field">
<options>
<option name="default">default_string</option>
<option name="comment">The comment for the field</option>
</options>
</field>
</entity>
</doctrine-mapping>
XML;
self::assertXmlStringEqualsXmlString($expectedFileContent, $exporter->exportClassMetadata($metadata));
}
public function testPolicyExport(): void
{
$exporter = new XmlExporter();
$metadata = new ClassMetadata('entityTest');
// DEFERRED_IMPLICIT
$metadata->setChangeTrackingPolicy(ClassMetadata::CHANGETRACKING_DEFERRED_IMPLICIT);
$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 https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="entityTest"/>
</doctrine-mapping>
XML;
self::assertXmlStringEqualsXmlString($expectedFileContent, $exporter->exportClassMetadata($metadata));
// DEFERRED_EXPLICIT
$metadata->setChangeTrackingPolicy(ClassMetadata::CHANGETRACKING_DEFERRED_EXPLICIT);
$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 https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="entityTest" change-tracking-policy="DEFERRED_EXPLICIT"/>
</doctrine-mapping>
XML;
self::assertXmlStringEqualsXmlString($expectedFileContent, $exporter->exportClassMetadata($metadata));
// NOTIFY
$metadata->setChangeTrackingPolicy(ClassMetadata::CHANGETRACKING_NOTIFY);
$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 https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="entityTest" change-tracking-policy="NOTIFY"/>
</doctrine-mapping>
XML;
self::assertXmlStringEqualsXmlString($expectedFileContent, $exporter->exportClassMetadata($metadata));
}
}
|