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
|
<?php
declare(strict_types=1);
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\MappingException;
use Doctrine\Tests\OrmTestCase;
use Generator;
use PHPUnit\Framework\Attributes\DataProvider;
class GH10450Test extends OrmTestCase
{
/** @param class-string $className */
#[DataProvider('classesThatOverrideFieldNames')]
public function testDuplicatePrivateFieldsShallBeRejected(string $className): void
{
$em = $this->getTestEntityManager();
$this->expectException(MappingException::class);
$em->getClassMetadata($className);
}
public static function classesThatOverrideFieldNames(): Generator
{
yield 'Entity class that redeclares a private field inherited from a base entity' => [GH10450EntityChildPrivate::class];
yield 'Entity class that redeclares a private field inherited from a mapped superclass' => [GH10450MappedSuperclassChildPrivate::class];
yield 'Entity class that redeclares a protected field inherited from a base entity' => [GH10450EntityChildProtected::class];
yield 'Entity class that redeclares a protected field inherited from a mapped superclass' => [GH10450MappedSuperclassChildProtected::class];
}
}
#[ORM\Entity]
#[ORM\InheritanceType('JOINED')]
#[ORM\DiscriminatorMap(['base' => GH10450BaseEntityPrivate::class, 'child' => GH10450EntityChildPrivate::class])]
#[ORM\DiscriminatorColumn(name: 'type')]
class GH10450BaseEntityPrivate
{
#[ORM\Column(type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue]
private int $id;
#[ORM\Column(type: 'text', name: 'base')]
private string $field;
}
#[ORM\Entity]
class GH10450EntityChildPrivate extends GH10450BaseEntityPrivate
{
#[ORM\Column(type: 'text', name: 'child')]
private string $field;
}
#[ORM\MappedSuperclass]
class GH10450BaseMappedSuperclassPrivate
{
#[ORM\Column(type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue]
private int $id;
#[ORM\Column(type: 'text', name: 'base')]
private string $field;
}
#[ORM\Entity]
class GH10450MappedSuperclassChildPrivate extends GH10450BaseMappedSuperclassPrivate
{
#[ORM\Column(type: 'text', name: 'child')]
private string $field;
}
#[ORM\Entity]
#[ORM\InheritanceType('JOINED')]
#[ORM\DiscriminatorMap(['base' => GH10450BaseEntityProtected::class, 'child' => GH10450EntityChildProtected::class])]
#[ORM\DiscriminatorColumn(name: 'type')]
class GH10450BaseEntityProtected
{
#[ORM\Column(type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue]
protected int $id;
#[ORM\Column(type: 'text', name: 'base')]
protected string $field;
}
#[ORM\Entity]
class GH10450EntityChildProtected extends GH10450BaseEntityProtected
{
#[ORM\Column(type: 'text', name: 'child')]
protected string $field;
}
#[ORM\MappedSuperclass]
class GH10450BaseMappedSuperclassProtected
{
#[ORM\Column(type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue]
protected int $id;
#[ORM\Column(type: 'text', name: 'base')]
protected string $field;
}
#[ORM\Entity]
class GH10450MappedSuperclassChildProtected extends GH10450BaseMappedSuperclassProtected
{
#[ORM\Column(type: 'text', name: 'child')]
protected string $field;
}
|