File: DDC279Test.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 (129 lines) | stat: -rw-r--r-- 2,989 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
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\DiscriminatorColumn;
use Doctrine\ORM\Mapping\DiscriminatorMap;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\InheritanceType;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\OneToOne;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Attributes\Group;

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

        $this->createSchemaForModels(
            DDC279EntityXAbstract::class,
            DDC279EntityX::class,
            DDC279EntityY::class,
            DDC279EntityZ::class,
        );
    }

    #[Group('DDC-279')]
    public function testDDC279(): void
    {
        $x = new DDC279EntityX();
        $y = new DDC279EntityY();
        $z = new DDC279EntityZ();

        $x->data = 'X';
        $y->data = 'Y';
        $z->data = 'Z';

        $x->y = $y;
        $y->z = $z;

        $this->_em->persist($x);
        $this->_em->persist($y);
        $this->_em->persist($z);

        $this->_em->flush();
        $this->_em->clear();

        $query = $this->_em->createQuery(
            'SELECT x, y, z FROM Doctrine\Tests\ORM\Functional\Ticket\DDC279EntityX x ' .
            'INNER JOIN x.y y INNER JOIN y.z z WHERE x.id = ?1',
        )->setParameter(1, $x->id);

        $result = $query->getResult();

        $expected1 = 'Y';
        $expected2 = 'Z';

        self::assertCount(1, $result);

        self::assertEquals($expected1, $result[0]->y->data);
        self::assertEquals($expected2, $result[0]->y->z->data);
    }
}


#[Entity]
#[InheritanceType('JOINED')]
#[DiscriminatorColumn(name: 'discr', type: 'string')]
#[DiscriminatorMap(['DDC279EntityX' => 'DDC279EntityX'])]
abstract class DDC279EntityXAbstract
{
    /** @var int */
    #[Id]
    #[GeneratedValue]
    #[Column(name: 'id', type: 'integer')]
    public $id;

    /** @var string */
    #[Column(type: 'string', length: 255)]
    public $data;
}

#[Entity]
class DDC279EntityX extends DDC279EntityXAbstract
{
    /** @var DDC279EntityY */
    #[OneToOne(targetEntity: 'DDC279EntityY')]
    #[JoinColumn(name: 'y_id', referencedColumnName: 'id')]
    public $y;
}

#[Entity]
class DDC279EntityY
{
    /** @var int */
    #[Id]
    #[GeneratedValue]
    #[Column(name: 'id', type: 'integer')]
    public $id;

    /** @var string */
    #[Column(type: 'string', length: 255)]
    public $data;

    /** @var DDC279EntityZ */
    #[OneToOne(targetEntity: 'DDC279EntityZ')]
    #[JoinColumn(name: 'z_id', referencedColumnName: 'id')]
    public $z;
}

#[Entity]
class DDC279EntityZ
{
    /** @var int */
    #[Id]
    #[GeneratedValue]
    #[Column(name: 'id', type: 'integer')]
    public $id;

    /** @var string */
    #[Column(type: 'string', length: 255)]
    public $data;
}