Completed
Pull Request — master (#7825)
by
unknown
61:48
created

GH5998Test::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 3
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\ORM\Functional\Ticket;
6
7
use Doctrine\DBAL\LockMode;
8
use Doctrine\ORM\Annotation as ORM;
9
use Doctrine\Tests\OrmFunctionalTestCase;
10
11
/**
12
 * @group GH-5998
13
 */
14
class GH5998Test extends OrmFunctionalTestCase
15
{
16
    protected function setUp() : void
17
    {
18
        parent::setUp();
19
        $this->schemaTool->createSchema([
20
            $this->em->getClassMetadata(GH5998JTI::class),
21
            $this->em->getClassMetadata(GH5998JTIChild::class),
22
            $this->em->getClassMetadata(GH5998STI::class),
23
            $this->em->getClassMetadata(GH5998Related::class),
24
        ]);
25
    }
26
27
    /**
28
     * Verifies that MappedSuperclasses work within an inheritance hierarchy.
29
     */
30
    public function testIssue()
31
    {
32
        // Test JTI
33
        $this->classTests(GH5998JTIChild::class);
34
        // Test STI
35
        $this->classTests(GH5998STIChild::class);
36
    }
37
38
    private function classTests($className)
39
    {
40
        // Test insert
41
        $child = new $className('Sam', 0, 1);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
42
        $child->rel = new GH5998Related();
43
        $this->em->persist($child);
44
        $this->em->persist($child->rel);
45
        $this->em->flush();
46
        $this->em->clear();
47
48
        // Test find
49
        $child = $this->em->getRepository($className)->find(1);
50
        self::assertNotNull($child);
51
52
        // Test lock and update
53
        $this->em->transactional(static function ($em) use ($child) {
54
            $em->lock($child, LockMode::NONE);
55
            $child->firstName = 'Bob';
56
            $child->status    = 0;
57
        });
58
        $this->em->clear();
59
        $child = $this->em->getRepository($className)->find(1);
60
        self::assertEquals($child->firstName, 'Bob');
61
        self::assertEquals($child->status, 0);
62
63
        // Test delete
64
        $this->em->remove($child);
65
        $this->em->flush();
66
        $child = $this->em->getRepository($className)->find(1);
67
        self::assertNull($child);
68
    }
69
}
70
71
/**
72
 * @ORM\MappedSuperclass
73
 */
74
class GH5998Common
75
{
76
    /**
77
     * @ORM\Id
78
     * @ORM\Column(type="integer")
79
     * @ORM\GeneratedValue
80
     */
81
    public $id;
82
    /**
83
     * @ORM\ManyToOne(targetEntity=GH5998Related::class)
84
     * @ORM\JoinColumn(name="related_id", referencedColumnName="id")
85
     */
86
    public $rel;
87
}
88
89
/**
90
 * @ORM\Entity
91
 * @ORM\InheritanceType("JOINED")
92
 * @ORM\DiscriminatorMap({"child" = GH5998JTIChild::class})
93
 */
94
abstract class GH5998JTI extends GH5998Common
95
{
96
    /** @ORM\Column(type="string", length=255) */
97
    public $firstName;
98
}
99
100
/**
101
 * @ORM\MappedSuperclass
102
 */
103
class GH5998JTICommon extends GH5998JTI
104
{
105
    /** @ORM\Column(type="integer") */
106
    public $status;
107
}
108
109
/**
110
 * @ORM\Entity
111
 */
112
class GH5998JTIChild extends GH5998JTICommon
113
{
114
    /** @ORM\Column(type="integer") */
115
    public $type;
116
117
    public function __construct(string $firstName, int $type, int $status)
118
    {
119
        $this->firstName = $firstName;
120
        $this->type      = $type;
121
        $this->status    = $status;
122
    }
123
}
124
125
/**
126
 * @ORM\Entity
127
 * @ORM\InheritanceType("SINGLE_TABLE")
128
 * @ORM\DiscriminatorMap({"child" = GH5998STIChild::class})
129
 */
130
abstract class GH5998STI extends GH5998Common
131
{
132
    /** @ORM\Column(type="string", length=255) */
133
    public $firstName;
134
}
135
136
/**
137
 * @ORM\MappedSuperclass
138
 */
139
class GH5998STICommon extends GH5998STI
140
{
141
    /** @ORM\Column(type="integer") */
142
    public $status;
143
}
144
145
/**
146
 * @ORM\Entity
147
 */
148
class GH5998STIChild extends GH5998STICommon
149
{
150
    /** @ORM\Column(type="integer") */
151
    public $type;
152
153
    public function __construct(string $firstName, int $type, int $status)
154
    {
155
        $this->firstName = $firstName;
156
        $this->type      = $type;
157
        $this->status    = $status;
158
    }
159
}
160
161
/**
162
 * @ORM\Entity
163
 */
164
class GH5998Related
165
{
166
    /**
167
     * @ORM\Id
168
     * @ORM\Column(type="integer")
169
     * @ORM\GeneratedValue
170
     */
171
    public $id;
172
}
173