|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
|
5
|
|
|
|
|
6
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
7
|
|
|
use Doctrine\Common\Collections\Collection; |
|
8
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
9
|
|
|
|
|
10
|
|
|
final class GH6999Test extends \Doctrine\Tests\OrmFunctionalTestCase |
|
11
|
|
|
{ |
|
12
|
|
|
public function setUp() : void |
|
13
|
|
|
{ |
|
14
|
|
|
$this->enableSecondLevelCache(); |
|
15
|
|
|
parent::setUp(); |
|
16
|
|
|
|
|
17
|
|
|
$this->setUpEntitySchema([GH6999Parent::class, GH6999Child::class]); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @group 6999 |
|
22
|
|
|
*/ |
|
23
|
|
|
public function testCollectionChange() : void |
|
24
|
|
|
{ |
|
25
|
|
|
$parent = new GH6999Parent(); |
|
26
|
|
|
$children = []; |
|
27
|
|
|
|
|
28
|
|
|
for ($i = 0; $i < 3; $i++) { |
|
29
|
|
|
$child = new GH6999Child(); |
|
30
|
|
|
$child->parent = $parent; |
|
31
|
|
|
|
|
32
|
|
|
$children[] = $child; |
|
33
|
|
|
|
|
34
|
|
|
$this->_em->persist($child); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
$parent->children = new ArrayCollection($children); |
|
38
|
|
|
|
|
39
|
|
|
$this->_em->persist($parent); |
|
40
|
|
|
$this->_em->flush(); |
|
41
|
|
|
$this->_em->clear(); |
|
42
|
|
|
|
|
43
|
|
|
/** @var GH6999Parent $parent */ |
|
44
|
|
|
$parent = $this->_em->find(GH6999Parent::class, $parent->id); |
|
45
|
|
|
|
|
46
|
|
|
$this->assertEquals(3, $parent->children->count()); |
|
47
|
|
|
|
|
48
|
|
|
$parent->children = clone $parent->children; |
|
49
|
|
|
|
|
50
|
|
|
$this->assertEquals(3, $parent->children->count()); |
|
51
|
|
|
|
|
52
|
|
|
$this->_em->persist($parent); |
|
53
|
|
|
$this->_em->flush(); |
|
54
|
|
|
$this->_em->clear(); |
|
55
|
|
|
|
|
56
|
|
|
/** @var GH6999Parent $parent */ |
|
57
|
|
|
$parent = $this->_em->find(GH6999Parent::class, $parent->id); |
|
58
|
|
|
|
|
59
|
|
|
$this->assertEquals(3, $parent->children->count(), 'The number of children should stay the same. As it did in 2.5.'); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @Entity() |
|
65
|
|
|
*/ |
|
66
|
|
|
class GH6999Parent |
|
67
|
|
|
{ |
|
68
|
|
|
/** |
|
69
|
|
|
* @Id |
|
70
|
|
|
* @GeneratedValue |
|
71
|
|
|
* @Column(type="integer") |
|
72
|
|
|
* |
|
73
|
|
|
* @var int |
|
74
|
|
|
*/ |
|
75
|
|
|
public $id; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @var GH6999Child[]|Collection |
|
79
|
|
|
* |
|
80
|
|
|
* @OneToMany(targetEntity="GH6999Child", orphanRemoval=true, mappedBy="parent") |
|
81
|
|
|
*/ |
|
82
|
|
|
public $children; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @Entity() |
|
87
|
|
|
*/ |
|
88
|
|
|
class GH6999Child |
|
89
|
|
|
{ |
|
90
|
|
|
/** |
|
91
|
|
|
* @Id |
|
92
|
|
|
* @GeneratedValue |
|
93
|
|
|
* @Column(type="integer") |
|
94
|
|
|
* |
|
95
|
|
|
* @var int |
|
96
|
|
|
*/ |
|
97
|
|
|
public $id; |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @var GH6999Parent |
|
101
|
|
|
* |
|
102
|
|
|
* @ManyToOne(targetEntity="GH6999Parent", inversedBy="children") |
|
103
|
|
|
*/ |
|
104
|
|
|
public $parent; |
|
105
|
|
|
} |
|
106
|
|
|
|