1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
6
|
|
|
|
7
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
8
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
9
|
|
|
|
10
|
|
|
final class GH7761Test extends OrmFunctionalTestCase |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* {@inheritDoc} |
14
|
|
|
*/ |
15
|
|
|
protected function setUp() : void |
16
|
|
|
{ |
17
|
|
|
parent::setUp(); |
18
|
|
|
|
19
|
|
|
$this->setUpEntitySchema([ |
20
|
|
|
GH7761Entity::class, |
21
|
|
|
GH7761ChildEntity::class, |
22
|
|
|
]); |
23
|
|
|
|
24
|
|
|
$parent = new GH7761Entity(); |
25
|
|
|
$child = new GH7761ChildEntity(); |
26
|
|
|
$parent->children->add($child); |
27
|
|
|
|
28
|
|
|
$this->_em->persist($parent); |
29
|
|
|
$this->_em->persist($child); |
30
|
|
|
$this->_em->flush(); |
31
|
|
|
$this->_em->clear(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
protected function tearDown() |
35
|
|
|
{ |
36
|
|
|
$this->_em->clear(); |
37
|
|
|
parent::tearDown(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @group GH-7862 |
42
|
|
|
*/ |
43
|
|
|
public function testCollectionClearDoesNotClearIfNotPersisted() : void |
44
|
|
|
{ |
45
|
|
|
/** @var GH7761Entity $entity */ |
46
|
|
|
$entity = $this->_em->find(GH7761Entity::class, 1); |
47
|
|
|
$entity->children->clear(); |
48
|
|
|
$this->_em->persist(new GH7761Entity()); |
49
|
|
|
$this->_em->flush(); |
50
|
|
|
|
51
|
|
|
$this->_em->clear(); |
52
|
|
|
|
53
|
|
|
$entity = $this->_em->find(GH7761Entity::class, 1); |
54
|
|
|
self::assertCount(1, $entity->children); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testCollectionClearDoesClearIfPersisted() : void |
58
|
|
|
{ |
59
|
|
|
/** @var GH7761Entity $entity */ |
60
|
|
|
$entity = $this->_em->find(GH7761Entity::class, 1); |
61
|
|
|
$entity->children->clear(); |
62
|
|
|
$this->_em->persist($entity); |
63
|
|
|
$this->_em->flush(); |
64
|
|
|
|
65
|
|
|
$this->_em->clear(); |
66
|
|
|
|
67
|
|
|
$entity = $this->_em->find(GH7761Entity::class, 1); |
68
|
|
|
self::assertCount(0, $entity->children); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @Entity |
74
|
|
|
* @ChangeTrackingPolicy("DEFERRED_EXPLICIT") |
75
|
|
|
*/ |
76
|
|
|
class GH7761Entity |
77
|
|
|
{ |
78
|
|
|
/** |
79
|
|
|
* @Id |
80
|
|
|
* @Column(type="integer") |
81
|
|
|
* @GeneratedValue |
82
|
|
|
*/ |
83
|
|
|
public $id; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @ManyToMany(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\GH7761ChildEntity", cascade={"all"}) |
87
|
|
|
* @JoinTable(name="gh7761_to_child", |
88
|
|
|
* joinColumns={@JoinColumn(name="entity_id")}, |
89
|
|
|
* inverseJoinColumns={@JoinColumn(name="child_id")} |
90
|
|
|
* ) |
91
|
|
|
*/ |
92
|
|
|
public $children; |
93
|
|
|
|
94
|
|
|
public function __construct() |
95
|
|
|
{ |
96
|
|
|
$this->children = new ArrayCollection(); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @Entity |
102
|
|
|
* @ChangeTrackingPolicy("DEFERRED_EXPLICIT") |
103
|
|
|
*/ |
104
|
|
|
class GH7761ChildEntity |
105
|
|
|
{ |
106
|
|
|
/** |
107
|
|
|
* @Id |
108
|
|
|
* @Column(type="integer") |
109
|
|
|
* @GeneratedValue |
110
|
|
|
*/ |
111
|
|
|
public $id; |
112
|
|
|
} |
113
|
|
|
|