Skip to content

Commit

Permalink
Merge pull request #10630 from monadial/fix/fqcn-type-in-xml-mapping
Browse files Browse the repository at this point in the history
Fixed xsd schema for support FQCN type
  • Loading branch information
greg0ire authored Apr 16, 2023
2 parents 2977933 + 5ac6fad commit fceb279
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 3 deletions.
13 changes: 10 additions & 3 deletions doctrine-mapping.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"/>
</xs:choice>
<xs:attribute name="name" type="xs:NMTOKEN" use="required" />
<xs:attribute name="type" type="xs:NMTOKEN" default="string" />
<xs:attribute name="type" type="orm:type" default="string" />
<xs:attribute name="column" type="orm:columntoken" />
<xs:attribute name="length" type="xs:NMTOKEN" />
<xs:attribute name="unique" type="xs:boolean" default="false" />
Expand Down Expand Up @@ -414,7 +414,7 @@
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"/>
</xs:choice>
<xs:attribute name="name" type="xs:NMTOKEN" use="required" />
<xs:attribute name="type" type="xs:NMTOKEN" />
<xs:attribute name="type" type="orm:type" />
<xs:attribute name="column" type="orm:columntoken" />
<xs:attribute name="length" type="xs:NMTOKEN" />
<xs:attribute name="association-key" type="xs:boolean" default="false" />
Expand Down Expand Up @@ -446,6 +446,13 @@
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="type" id="type">
<xs:restriction base="xs:token">
<xs:pattern value="([a-zA-Z_u01-uff][a-zA-Z0-9_u01-uff]+)|(\c+)" id="type.class.pattern">
</xs:pattern>
</xs:restriction>
</xs:simpleType>

<xs:complexType name="inverse-join-columns">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="join-column" type="orm:join-column" minOccurs="1" maxOccurs="unbounded" />
Expand Down Expand Up @@ -630,7 +637,7 @@
<xs:element name="options" type="orm:options" minOccurs="0" />
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"/>
</xs:choice>
<xs:attribute name="type" type="xs:NMTOKEN" default="string" />
<xs:attribute name="type" type="orm:type" default="string" />
<xs:attribute name="column" type="orm:columntoken" />
<xs:attribute name="length" type="xs:NMTOKEN" />
<xs:attribute name="unique" type="xs:boolean" default="false" />
Expand Down
24 changes: 24 additions & 0 deletions tests/Doctrine/Tests/Models/Project/Project.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\Models\Project;

class Project
{
/**
* @var string
*/
private $id;

/**
* @var string
*/
private $name;

public function __construct(string $id, string $name)
{
$this->id = $id;
$this->name = $name;
}
}
18 changes: 18 additions & 0 deletions tests/Doctrine/Tests/Models/Project/ProjectId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\Models\Project;

class ProjectId
{
/**
* @var string
*/
private $id;

public function __construct(string $id)
{
$this->id = $id;
}
}
24 changes: 24 additions & 0 deletions tests/Doctrine/Tests/Models/Project/ProjectInvalidMapping.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\Models\Project;

class ProjectInvalidMapping
{
/**
* @var string
*/
private $id;

/**
* @var string
*/
private $name;

public function __construct(string $id, string $name)
{
$this->id = $id;
$this->name = $name;
}
}
18 changes: 18 additions & 0 deletions tests/Doctrine/Tests/Models/Project/ProjectName.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\Models\Project;

final class ProjectName
{
/**
* @var string
*/
private $name;

public function __construct(string $name)
{
$this->name = $name;
}
}
25 changes: 25 additions & 0 deletions tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
use Doctrine\Tests\Models\Generic\BooleanModel;
use Doctrine\Tests\Models\GH7141\GH7141Article;
use Doctrine\Tests\Models\GH7316\GH7316Article;
use Doctrine\Tests\Models\Project\Project;
use Doctrine\Tests\Models\Project\ProjectId;
use Doctrine\Tests\Models\Project\ProjectInvalidMapping;
use Doctrine\Tests\Models\Project\ProjectName;
use Doctrine\Tests\Models\ValueObjects\Name;
use Doctrine\Tests\Models\ValueObjects\Person;

Expand Down Expand Up @@ -239,6 +243,10 @@ public static function dataInvalidSchema(): array
UserMissingAttributes::class,
['The attribute \'name\' is required but missing' => 1],
],
[
ProjectInvalidMapping::class,
['attribute \'type\': [facet \'pattern\'] The value' => 2],
],
];
}

Expand Down Expand Up @@ -279,6 +287,23 @@ public function testInvalidEntityOrMappedSuperClassShouldMentionParentClasses():

$this->createClassMetadata(DDC889Class::class);
}

public function testClassNameInFieldOrId(): void
{
$class = new ClassMetadata(Project::class);
$class->initializeReflection(new RuntimeReflectionService());

$driver = $this->loadDriver();
$driver->loadMetadataForClass(Project::class, $class);

/** @var array{type: string} $id */
$id = $class->getFieldMapping('id');
/** @var array{type: string} $name */
$name = $class->getFieldMapping('name');

self::assertEquals(ProjectId::class, $id['type']);
self::assertEquals(ProjectName::class, $name['type']);
}
}

class CTI
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?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="Doctrine\Tests\Models\Project\Project" table="project">
<id name="id" type="Doctrine\Tests\Models\Project\ProjectId" column="id">
<generator strategy="NONE"/>
</id>
<field name="name" type="Doctrine\Tests\Models\Project\ProjectName" column="name"/>
</entity>
</doctrine-mapping>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?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="Doctrine\Tests\Models\Project\ProjectInvalidMapping" table="project">
<id name="id" type="Doctrine/Tests/Models/Project/Project/ProjectId" column="id">
<generator strategy="NONE"/>
</id>
<field name="name" type="Doctrine/Tests/Models/Project/Project/ProjectName" column="name"/>
</entity>
</doctrine-mapping>

0 comments on commit fceb279

Please sign in to comment.