Skip to content

Commit

Permalink
allow classname in 'value' attribute of xml discriminator-mapping field
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoFeltrin committed May 13, 2024
1 parent 029ca61 commit a8b11a1
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doctrine-mapping.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"/>
</xs:choice>
<xs:attribute name="value" type="xs:NMTOKEN" use="required"/>
<xs:attribute name="value" type="orm:type" use="required"/>
<xs:attribute name="class" type="orm:fqcn" use="required"/>
<xs:anyAttribute namespace="##other"/>
</xs:complexType>
Expand Down
10 changes: 10 additions & 0 deletions tests/Tests/Models/Customer/CustomerType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

Check failure on line 1 in tests/Tests/Models/Customer/CustomerType.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (8.2)

Missing declare(strict_types=1).

namespace Doctrine\Tests\Models\Customer;

class CustomerType
{
public function __construct(public string $name)
{
}
}

Check failure on line 10 in tests/Tests/Models/Customer/CustomerType.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (8.2)

Expected 1 newline at end of file; 0 found
13 changes: 13 additions & 0 deletions tests/Tests/Models/Customer/ExternalCustomer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\Models\Customer;

final class ExternalCustomer extends CustomerType
{
public function __construct(string $name)
{
parent::__construct($name);
}
}
13 changes: 13 additions & 0 deletions tests/Tests/Models/Customer/InternalCustomer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\Models\Customer;

final class InternalCustomer extends CustomerType
{
public function __construct(string $name)
{
parent::__construct($name);
}
}
15 changes: 15 additions & 0 deletions tests/Tests/ORM/Mapping/XmlMappingDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Persistence\Mapping\MappingException as PersistenceMappingException;
use Doctrine\Persistence\Mapping\RuntimeReflectionService;
use Doctrine\Tests\Models\Customer\CustomerType;
use Doctrine\Tests\Models\DDC117\DDC117Translation;
use Doctrine\Tests\Models\DDC3293\DDC3293User;
use Doctrine\Tests\Models\DDC3293\DDC3293UserPrefixed;
Expand Down Expand Up @@ -301,6 +302,20 @@ public function testClassNameInFieldOrId(): void
self::assertEquals(ProjectName::class, $name->type);
}

public function testClassNameMappingDiscriminatorValue(): void
{
$driver = new XmlDriver(

Check failure on line 307 in tests/Tests/ORM/Mapping/XmlMappingDriverTest.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (8.2)

Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space
__DIR__ . '/xml',
XmlDriver::DEFAULT_FILE_EXTENSION,
true,
);
$xmlElement = $driver->getElement(CustomerType::class);
self::assertEquals(
'Doctrine\Tests\Models\Customer\InternalCustomer',
$xmlElement->children()->{'discriminator-map'}->{'discriminator-mapping'}[0]->attributes()['value']

Check failure on line 315 in tests/Tests/ORM/Mapping/XmlMappingDriverTest.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (8.2)

Multi-line function calls must have a trailing comma after the last parameter.
);
}

public function testDisablingXmlValidationIsPossible(): void
{
$this->expectNotToPerformAssertions();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?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\Customer\CustomerType" table="customers">
<field name="name" column="name"/>
<discriminator-column name="type" type="string"/>
<discriminator-map>
<discriminator-mapping value="Doctrine\Tests\Models\Customer\InternalCustomer" class="Doctrine\Tests\Models\Customer\InternalCustomer" />
<discriminator-mapping value="Doctrine\Tests\Models\Customer\ExternalCustomer" class="Doctrine\Tests\Models\Customer\ExternalCustomer" />
</discriminator-map>
</entity>
</doctrine-mapping>

0 comments on commit a8b11a1

Please sign in to comment.