Failed Conditions
Pull Request — 2.6 (#6798)
by Zacharias
08:39
created

GH4252Address::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\Common\Collections\Collection;
7
8
/**
9
 * @group GH-4252
10
 */
11
class GH4252Test extends \Doctrine\Tests\OrmFunctionalTestCase
12
{
13
    protected function setUp()
14
    {
15
        parent::setUp();
16
17
        $this->_schemaTool->createSchema(array(
18
            $this->_em->getClassMetadata(GH4252City::class),
19
            $this->_em->getClassMetadata(GH4252Resident::class),
20
            $this->_em->getClassMetadata(GH4252Address::class),
21
        ));
22
    }
23
24
    public function testIssue()
25
    {
26
        $city = new GH4252City([new GH4252Resident([new GH4252Address()])]);
27
28
        $this->_em->persist($city);
29
        $this->_em->flush();
30
        $this->_em->clear();
31
32
        /** @var GH4252City $city */
33
        $city = $this->_em->find(GH4252City::class, $city->getId());
34
        $city->setFlag(false);
35
        /** @var GH4252Resident $resident */
36
        $resident = $city->getResidents()->first();
37
        $resident->setFlag(false);
38
        /** @var GH4252Address $address */
39
        $address = $resident->getAddresses()->first();
40
        $address->setFlag(false);
41
42
        $this->_em->refresh($city);
43
44
        $resident = $city->getResidents()->first();
45
        $address = $resident->getAddresses()->first();
46
47
        $this->assertTrue($city->getFlag());
48
        $this->assertTrue($resident->getFlag());
49
        $this->assertTrue($address->getFlag());
50
    }
51
}
52
53
/**
54
 * @Entity
55
 */
56
class GH4252City
57
{
58
    /**
59
     * @var int
60
     * @Id @Column(type="integer") @GeneratedValue
61
     */
62
    private $id;
63
64
    /**
65
     * @var bool
66
     * @Column(type="boolean")
67
     */
68
    private $flag;
69
70
    /**
71
     * @var GH4252Resident[]|Collection
72
     *
73
     * @OneToMany(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\GH4252Resident", mappedBy="city", cascade={"persist","refresh"})
74
     */
75
    private $residents;
76
77
    public function __construct(array $residents)
78
    {
79
        $this->residents = new ArrayCollection();
80
        foreach ($residents as $resident) {
81
            $this->residents->add($resident);
82
            $resident->setCity($this);
83
        }
84
        $this->flag = true;
85
    }
86
87
    public function getId() : int
88
    {
89
        return $this->id;
90
    }
91
92
    public function getFlag() : bool
93
    {
94
        return $this->flag;
95
    }
96
97
    public function setFlag(bool $flag) : void
98
    {
99
        $this->flag = $flag;
100
    }
101
102
    public function getResidents() : Collection
103
    {
104
        return $this->residents;
105
    }
106
}
107
108
/**
109
 * @Entity
110
 */
111
class GH4252Resident
112
{
113
    /**
114
     * @var int
115
     * @Id @Column(type="integer") @GeneratedValue
116
     */
117
    private $id;
118
119
    /**
120
     * @var GH4252City
121
     * @ManyToOne(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\GH4252City", inversedBy="residents")
122
     */
123
    private $city;
124
125
    /**
126
     * @var bool
127
     * @Column(type="boolean")
128
     */
129
    private $flag;
130
131
    /**
132
     * @var GH4252Address[]|Collection
133
     *
134
     * @ManyToMany(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\GH4252Address", fetch="EXTRA_LAZY", cascade={"persist","refresh"})
135
     */
136
    private $addresses;
137
138
    public function __construct(array $addresses)
139
    {
140
        $this->addresses = new ArrayCollection();
141
        foreach ($addresses as $address) {
142
            $this->addresses->add($address);
143
        }
144
        $this->flag = true;
145
    }
146
147
    public function getId() : int
148
    {
149
        return $this->id;
150
    }
151
152
    public function getCity() : GH4252City
153
    {
154
        return $this->city;
155
    }
156
157
    public function setCity(GH4252City $city) : void
158
    {
159
        $this->city = $city;
160
    }
161
162
    public function getFlag() : bool
163
    {
164
        return $this->flag;
165
    }
166
167
    public function setFlag(bool $flag) : void
168
    {
169
        $this->flag = $flag;
170
    }
171
172
    public function getAddresses() : Collection
173
    {
174
        return $this->addresses;
175
    }
176
}
177
178
/** @Entity */
179
class GH4252Address
180
{
181
    /**
182
     * @var int
183
     * @Id @Column(type="integer") @GeneratedValue
184
     */
185
    private $id;
186
187
    /**
188
     * @var bool
189
     * @Column(type="boolean")
190
     */
191
    private $flag;
192
193
    public function __construct()
194
    {
195
        $this->flag = true;
196
    }
197
198
    public function getId() : int
199
    {
200
        return $this->id;
201
    }
202
203
    public function getFlag() : bool
204
    {
205
        return $this->flag;
206
    }
207
208
    public function setFlag(bool $flag) : void
209
    {
210
        $this->flag = $flag;
211
    }
212
}
213