File: GH10450Test.php

package info (click to toggle)
doctrine 3.5.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 11,552 kB
  • sloc: php: 108,302; xml: 1,340; makefile: 35; sh: 14
file content (149 lines) | stat: -rw-r--r-- 4,100 bytes parent folder | download | duplicates (3)
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
146
147
148
149
<?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;
use PHPUnit\Framework\Attributes\RequiresPhpunit;

#[RequiresPhpunit('< 12')]
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];
    }

    public function testFieldsOfTransientClassesAreNotConsideredDuplicate(): void
    {
        $em = $this->getTestEntityManager();

        $metadata = $em->getClassMetadata(GH10450Cat::class);

        self::assertArrayHasKey('id', $metadata->fieldMappings);
    }
}

#[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;
}

abstract class GH10450AbstractEntity
{
    #[ORM\Column(type: 'integer')]
    #[ORM\Id]
    #[ORM\GeneratedValue]
    protected int $id;
}

#[ORM\Entity]
#[ORM\InheritanceType('SINGLE_TABLE')]
#[ORM\DiscriminatorMap(['cat' => GH10450Cat::class])]
#[ORM\DiscriminatorColumn(name: 'type')]
abstract class GH10450Animal extends GH10450AbstractEntity
{
    #[ORM\Column(type: 'text', name: 'base')]
    private string $field;
}

#[ORM\Entity]
class GH10450Cat extends GH10450Animal
{
}