File: GH8415Test.php

package info (click to toggle)
doctrine 3.3.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 11,236 kB
  • sloc: php: 105,633; xml: 1,312; makefile: 35; sh: 14
file content (93 lines) | stat: -rw-r--r-- 2,428 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
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Tests\OrmFunctionalTestCase;

class GH8415Test extends OrmFunctionalTestCase
{
    protected function setUp(): void
    {
        parent::setUp();

        $this->setUpEntitySchema([
            GH8415BaseClass::class,
            GH8415MiddleMappedSuperclass::class,
            GH8415LeafClass::class,
            GH8415AssociationTarget::class,
        ]);
    }

    public function testAssociationIsBasedOnBaseClass(): void
    {
        $target            = new GH8415AssociationTarget();
        $leaf              = new GH8415LeafClass();
        $leaf->baseField   = 'base';
        $leaf->middleField = 'middle';
        $leaf->leafField   = 'leaf';
        $leaf->target      = $target;

        $this->_em->persist($target);
        $this->_em->persist($leaf);
        $this->_em->flush();
        $this->_em->clear();

        $query  = $this->_em->createQuery('SELECT leaf FROM Doctrine\Tests\ORM\Functional\Ticket\GH8415LeafClass leaf JOIN leaf.target t');
        $result = $query->getOneOrNullResult();

        $this->assertInstanceOf(GH8415LeafClass::class, $result);
        $this->assertSame('base', $result->baseField);
        $this->assertSame('middle', $result->middleField);
        $this->assertSame('leaf', $result->leafField);
    }
}

#[ORM\Entity]
class GH8415AssociationTarget
{
    /** @var int */
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    public $id;
}

#[ORM\Entity]
#[ORM\InheritanceType('JOINED')]
#[ORM\DiscriminatorColumn(name: 'discriminator', type: 'string')]
#[ORM\DiscriminatorMap(['1' => GH8415BaseClass::class, '2' => GH8415LeafClass::class])]
class GH8415BaseClass
{
    /** @var int */
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    public $id;

    /** @var GH8415AssociationTarget */
    #[ORM\ManyToOne(targetEntity: GH8415AssociationTarget::class)]
    public $target;

    /** @var string */
    #[ORM\Column(type: 'string')]
    public $baseField;
}

#[ORM\MappedSuperclass]
class GH8415MiddleMappedSuperclass extends GH8415BaseClass
{
    /** @var string */
    #[ORM\Column(type: 'string')]
    public $middleField;
}

#[ORM\Entity]
class GH8415LeafClass extends GH8415MiddleMappedSuperclass
{
    /** @var string */
    #[ORM\Column(type: 'string')]
    public $leafField;
}