File: GH10454Test.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 (75 lines) | stat: -rw-r--r-- 2,230 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
<?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 GH10454Test extends OrmTestCase
{
    /** @param class-string $className */
    #[DataProvider('classesThatOverrideFieldNames')]
    public function testProtectedPropertyMustNotBeInheritedAndReconfigured(string $className): void
    {
        $em = $this->getTestEntityManager();

        $this->expectException(MappingException::class);
        $this->expectExceptionMessageMatches('/Property "field" .* was already declared, but it must be declared only once/');

        $em->getClassMetadata($className);
    }

    public static function classesThatOverrideFieldNames(): Generator
    {
        yield 'Entity class that redeclares a protected field inherited from a base entity' => [GH10454EntityChildProtected::class];
        yield 'Entity class that redeclares a protected field inherited from a mapped superclass' => [GH10454MappedSuperclassChildProtected::class];
    }
}

#[ORM\Entity]
#[ORM\InheritanceType('JOINED')]
#[ORM\DiscriminatorMap(['base' => GH10454BaseEntityProtected::class, 'child' => GH10454EntityChildProtected::class])]
#[ORM\DiscriminatorColumn(name: 'type')]
class GH10454BaseEntityProtected
{
    #[ORM\Column(type: 'integer')]
    #[ORM\Id]
    #[ORM\GeneratedValue]
    protected int $id;

    #[ORM\Column(type: 'text', name: 'base')]
    protected string $field;
}

#[ORM\Entity]
class GH10454EntityChildProtected extends GH10454BaseEntityProtected
{
    #[ORM\Column(type: 'text', name: 'child')]
    protected string $field;
}

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

    #[ORM\Column(type: 'text', name: 'base')]
    protected string $field;
}

#[ORM\Entity]
class GH10454MappedSuperclassChildProtected extends GH10454BaseMappedSuperclassProtected
{
    #[ORM\Column(type: 'text', name: 'child')]
    protected string $field;
}