Skip to content

Commit

Permalink
Merge pull request #666 from FabioBatSilva/DDC-2429
Browse files Browse the repository at this point in the history
[DDC-2429] Fix xsd definition
  • Loading branch information
beberlei committed May 26, 2013
2 parents 20b5ab2 + 1e95110 commit 6548947
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 62 deletions.
51 changes: 39 additions & 12 deletions doctrine-mapping.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<xs:element name="cascade-merge" type="orm:emptyType" minOccurs="0"/>
<xs:element name="cascade-remove" type="orm:emptyType" minOccurs="0"/>
<xs:element name="cascade-refresh" type="orm:emptyType" minOccurs="0"/>
<xs:element name="cascade-detach" type="orm:emptyType" minOccurs="0"/>
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"/>
</xs:sequence>
<xs:anyAttribute namespace="##other"/>
Expand Down Expand Up @@ -86,23 +87,26 @@
</xs:complexType>

<xs:complexType name="named-native-query">
<xs:sequence>
<xs:element name="query" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="query" type="xs:string" use="required"/>
<xs:attribute name="result-class" type="xs:string" />
<xs:attribute name="result-set-mapping" type="xs:string" />
</xs:complexType>

<xs:complexType name="named-native-queries">
<xs:sequence>
<xs:element name="named-native-query" type="orm:named-native-query" minOccurs="1" maxOccurs="unbounded" />
<xs:any minOccurs="1" maxOccurs="unbounded" namespace="##other"/>
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="entity-listener">
<xs:sequence>
<xs:element name="lifecycle-callback" type="orm:lifecycle-callback" minOccurs="0" maxOccurs="unbounded"/>
<xs:any minOccurs="1" maxOccurs="unbounded" namespace="##other"/>
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"/>
</xs:sequence>
<xs:attribute name="class" type="xs:string"/>
</xs:complexType>
Expand All @@ -127,20 +131,24 @@
<xs:element name="field-result" type="orm:field-result" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="entity-class" type="xs:string" use="required" />
<xs:attribute name="discriminator-column" type="xs:string" use="optional" />
</xs:complexType>

<xs:complexType name="sql-result-set-mapping">
<xs:sequence>
<xs:element name="entity-result" type="orm:entity-result" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="column-result" type="orm:column-result" minOccurs="0" maxOccurs="unbounded" />
<xs:any minOccurs="1" maxOccurs="unbounded" namespace="##other"/>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="entity-result" type="orm:entity-result"/>
<xs:element name="column-result" type="orm:column-result"/>
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"/>
</xs:choice>
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required" />
</xs:complexType>

<xs:complexType name="sql-result-set-mappings">
<xs:sequence>
<xs:element name="sql-result-set-mapping" type="orm:sql-result-set-mapping" minOccurs="1" maxOccurs="unbounded" />
<xs:any minOccurs="1" maxOccurs="unbounded" namespace="##other"/>
</xs:sequence>
</xs:complexType>

Expand All @@ -155,6 +163,7 @@
<xs:element name="entity-listeners" type="orm:entity-listeners" minOccurs="0" maxOccurs="1" />
<xs:element name="named-queries" type="orm:named-queries" minOccurs="0" maxOccurs="1" />
<xs:element name="named-native-queries" type="orm:named-native-queries" minOccurs="0" maxOccurs="1" />
<xs:element name="sql-result-set-mappings" type="orm:sql-result-set-mappings" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="id" type="orm:id" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="field" type="orm:field" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="one-to-one" type="orm:one-to-one" minOccurs="0" maxOccurs="unbounded"/>
Expand Down Expand Up @@ -221,6 +230,7 @@

<xs:simpleType name="generator-strategy">
<xs:restriction base="xs:token">
<xs:enumeration value="NONE"/>
<xs:enumeration value="TABLE"/>
<xs:enumeration value="SEQUENCE"/>
<xs:enumeration value="IDENTITY"/>
Expand Down Expand Up @@ -380,7 +390,7 @@
<xs:sequence>
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"/>
</xs:sequence>
<xs:attribute name="name" type="xs:NMTOKEN" use="required" />
<xs:attribute name="name" type="xs:NMTOKEN" use="optional" />
<xs:attribute name="referenced-column-name" type="xs:NMTOKEN" use="optional" default="id" />
<xs:attribute name="unique" type="xs:boolean" default="false" />
<xs:attribute name="nullable" type="xs:boolean" default="true" />
Expand Down Expand Up @@ -505,7 +515,7 @@
<xs:complexType name="association-overrides">
<xs:sequence>
<xs:element name="association-override" type="orm:association-override" minOccurs="1" maxOccurs="unbounded" />
<xs:any minOccurs="1" maxOccurs="unbounded" namespace="##other"/>
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"/>
</xs:sequence>
</xs:complexType>

Expand All @@ -521,16 +531,33 @@
<xs:complexType name="attribute-overrides">
<xs:sequence>
<xs:element name="attribute-override" type="orm:attribute-override" minOccurs="1" maxOccurs="unbounded" />
<xs:any minOccurs="1" maxOccurs="unbounded" namespace="##other"/>
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="attribute-override">
<xs:sequence>
<xs:element name="field" type="orm:field" minOccurs="1" />
<xs:any minOccurs="1" maxOccurs="unbounded" namespace="##other"/>
<xs:element name="field" type="orm:attribute-override-field" minOccurs="1" />
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"/>
</xs:sequence>
<xs:attribute name="name" type="xs:NMTOKEN" use="required" />
</xs:complexType>

<xs:complexType name="attribute-override-field">
<xs:sequence>
<xs:element name="options" type="orm:options" minOccurs="0" />
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"/>
</xs:sequence>
<xs:attribute name="type" type="xs:NMTOKEN" default="string" />
<xs:attribute name="column" type="xs:NMTOKEN" />
<xs:attribute name="length" type="xs:NMTOKEN" />
<xs:attribute name="unique" type="xs:boolean" default="false" />
<xs:attribute name="nullable" type="xs:boolean" default="false" />
<xs:attribute name="version" type="xs:boolean" />
<xs:attribute name="column-definition" type="xs:string" />
<xs:attribute name="precision" type="xs:integer" use="optional" />
<xs:attribute name="scale" type="xs:integer" use="optional" />
<xs:anyAttribute namespace="##other"/>
</xs:complexType>

</xs:schema>
21 changes: 15 additions & 6 deletions tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,32 @@ public function testInvalidMappingFileException()
/**
* @param string $xmlMappingFile
* @dataProvider dataValidSchema
* @group DDC-2429
*/
public function testValidateXmlSchema($xmlMappingFile)
{
$xsdSchemaFile = __DIR__ . "/../../../../../doctrine-mapping.xsd";
$xsdSchemaFile = __DIR__ . '/../../../../../doctrine-mapping.xsd';
$dom = new \DOMDocument('UTF-8');

$dom = new \DOMDocument('UTF-8');
$dom->load($xmlMappingFile);

$this->assertTrue($dom->schemaValidate($xsdSchemaFile));
}

static public function dataValidSchema()
{
return array(
array(__DIR__ . "/xml/Doctrine.Tests.ORM.Mapping.CTI.dcm.xml"),
array(__DIR__ . "/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml"),
array(__DIR__ . "/xml/CatNoId.dcm.xml"),
$list = glob(__DIR__ . '/xml/*.xml');
$invalid = array(
'Doctrine.Tests.Models.DDC889.DDC889Class.dcm'
);

$list = array_filter($list, function($item) use ($invalid){
return ! in_array(pathinfo($item, PATHINFO_FILENAME), $invalid);
});

return array_map(function($item){
return array($item);
}, $list);
}

/**
Expand Down
40 changes: 40 additions & 0 deletions tests/Doctrine/Tests/ORM/Mapping/xml/DDC2429Book.orm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd">

<mapped-superclass name="SocialLibrary\ReadBundle\Entity\Book">
<id name="id" type="integer">
<generator strategy="AUTO" />
</id>
<field name="volume" column="volume" type="integer" nullable="true" />
<field name="language" column="language" type="string" length="8" nullable="true" />
<field name="isbn10" column="isbn10" type="string" length="11" unique="true" nullable="true" />
<field name="isbn13" column="isbn13" type="string" length="14" unique="true" nullable="true" />
<many-to-one field="serie" target-entity="SocialLibrary\ReadBundle\Entity\Serie" inversed-by="volumes">
<join-column name="serie_id" referenced-column-name="id" />
</many-to-one>
<many-to-many field="owners" target-entity="Application\Sonata\UserBundle\Entity\User">
<join-table name="book__owner">
<join-columns>
<join-column name="object_id" referenced-column-name="id" />
</join-columns>
<inverse-join-columns>
<join-column name="owner_id" referenced-column-name="id" />
</inverse-join-columns>
</join-table>
</many-to-many>
<many-to-many field="creators" target-entity="SocialLibrary\BaseBundle\Entity\ObjectCreator">
<join-table name="book__creator">
<join-columns>
<join-column name="object_id" referenced-column-name="id" />
</join-columns>
<inverse-join-columns>
<join-column name="creator_id" referenced-column-name="id" />
</inverse-join-columns>
</join-table>
</many-to-many>
</mapped-superclass>

</doctrine-mapping>
42 changes: 42 additions & 0 deletions tests/Doctrine/Tests/ORM/Mapping/xml/DDC2429Novel.orm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<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="SocialLibrary\ReadBundle\Entity\Novel" table="novel__novel" repository-class="SocialLibrary\ReadBundle\Repository\NovelRepository">
<association-overrides>
<association-override name="owners">
<join-table name="novel__owner">
<join-columns>
<join-column name="object_id" />
</join-columns>
<inverse-join-columns>
<join-column name="owner_id" />
</inverse-join-columns>
</join-table>
</association-override>
<association-override name="creators">
<join-table name="novel__creator">
<join-columns>
<join-column name="object_id" />
</join-columns>
<inverse-join-columns>
<join-column name="creator_id" />
</inverse-join-columns>
</join-table>
</association-override>
<association-override name="serie">
<join-columns>
<join-column name="novel_serie_id" referenced-column-name="id" />
</join-columns>
</association-override>
</association-overrides>

<attribute-overrides>
<attribute-override name="volume">
<field column="novel__volume" type="integer" nullable="true" />
</attribute-override>
</attribute-overrides>
</entity>

</doctrine-mapping>
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<?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://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<entity name="Doctrine\Tests\Models\CMS\CmsAddress" table="cms_users">
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="Doctrine\Tests\Models\CMS\CmsAddress" table="cms_users">

<entity-listeners>
<entity-listener class="CmsAddressListener"/>
</entity-listeners>
Expand All @@ -15,7 +13,7 @@
<named-native-query name="find-all" result-set-mapping="mapping-find-all">
<query>SELECT id, country, city FROM cms_addresses</query>
</named-native-query>

<named-native-query name="find-by-id" result-class="CmsAddress">
<query>SELECT * FROM cms_addresses WHERE id = ?</query>
</named-native-query>
Expand Down Expand Up @@ -46,14 +44,15 @@
<id name="id" type="integer" column="id">
<generator strategy="AUTO"/>
</id>

<field name="country" column="country" type="string" length="50"/>
<field name="city" column="city" type="string" length="50"/>
<field name="zip" column="zip" type="string" length="50"/>

<one-to-one field="user" target-entity="CmsUser" inversed-by="address">
<join-column referenced-column-name="id" />
</one-to-one>

</entity>

</doctrine-mapping>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<named-native-query name="fetchIdAndUsernameWithResultClass" result-class="CmsUser">
<query>SELECT id, username FROM cms_users WHERE username = ?</query>
</named-native-query>

<named-native-query name="fetchAllColumns" result-class="CmsUser">
<query>SELECT * FROM cms_users WHERE username = ?</query>
</named-native-query>
Expand Down Expand Up @@ -90,20 +90,7 @@
<field name="status" column="status" type="string" length="50" unique="true"/>
<field name="username" column="username" type="string" length="255" unique="true"/>
<field name="name" column="name" type="string" length="255"/>

<one-to-many field="phonenumbers" target-entity="CmsPhonenumber" mapped-by="user" orphan-removal="true">
<cascade>
<cascade-persist/>
<cascade-merge/>
</cascade>
</one-to-many>

<one-to-many field="articles" target-entity="CmsArticle" mapped-by="user">
<cascade>
<cascade-detach/>
</cascade>
</one-to-many>

<one-to-one field="address" target-entity="CmsAddress" inversed-by="user" orphan-removal="true">
<cascade>
<cascade-persist/>
Expand All @@ -117,12 +104,25 @@
</cascade>
<join-column referenced-column-name="id" nullable="true" />
</one-to-one>

<one-to-many field="phonenumbers" target-entity="CmsPhonenumber" mapped-by="user" orphan-removal="true">
<cascade>
<cascade-persist/>
<cascade-merge/>
</cascade>
</one-to-many>

<one-to-many field="articles" target-entity="CmsArticle" mapped-by="user">
<cascade>
<cascade-detach/>
</cascade>
</one-to-many>

<many-to-many field="groups" target-entity="CmsGroup">
<cascade>
<cascade-persist/>
<cascade-detach/>
<cascade-merge/>
<cascade-detach/>
</cascade>
<join-table name="cms_users_groups">
<join-columns>
Expand All @@ -133,7 +133,7 @@
</inverse-join-columns>
</join-table>
</many-to-many>

</entity>

</doctrine-mapping>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

<entity name="Doctrine\Tests\Models\Company\CompanyPerson" table="company_persons" inheritance-type="JOINED">

<discriminator-map >
<discriminator-mapping value="person" class="CompanyPerson" />
<discriminator-mapping value="manager" class="CompanyManager" />
<discriminator-mapping value="employee" class="CompanyEmployee" />
</discriminator-map>

<named-native-queries>
<named-native-query name="fetchAllWithResultClass" result-class="__CLASS__">
<query>SELECT id, name, discr FROM company_persons ORDER BY name</query>
Expand All @@ -26,12 +32,6 @@
</sql-result-set-mapping>
</sql-result-set-mappings>

<discriminator-map >
<discriminator-mapping value="person" class="CompanyPerson" />
<discriminator-mapping value="manager" class="CompanyManager" />
<discriminator-mapping value="employee" class="CompanyEmployee" />
</discriminator-map>

<id name="id" type="integer" column="id">
<generator strategy="AUTO"/>
</id>
Expand Down
Loading

0 comments on commit 6548947

Please sign in to comment.