|
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
|
|
|
public function testCollectionClearDoesNotClearIfNotPersisted() : void |
|
35
|
|
|
{ |
|
36
|
|
|
/** @var GH7761Entity $entity */ |
|
37
|
|
|
$entity = $this->_em->find(GH7761Entity::class, 1); |
|
38
|
|
|
$entity->children->clear(); |
|
39
|
|
|
$this->_em->persist(new GH7761Entity()); |
|
40
|
|
|
$this->_em->flush(); |
|
41
|
|
|
|
|
42
|
|
|
$this->_em->clear(); |
|
43
|
|
|
|
|
44
|
|
|
$entity = $this->_em->find(GH7761Entity::class, 1); |
|
45
|
|
|
self::assertCount(1, $entity->children); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @group GH-7862 |
|
50
|
|
|
*/ |
|
51
|
|
|
public function testCollectionClearDoesClearIfPersisted() : void |
|
52
|
|
|
{ |
|
53
|
|
|
/** @var GH7761Entity $entity */ |
|
54
|
|
|
$entity = $this->_em->find(GH7761Entity::class, 1); |
|
55
|
|
|
$entity->children->clear(); |
|
56
|
|
|
$this->_em->persist($entity); |
|
57
|
|
|
$this->_em->flush(); |
|
58
|
|
|
|
|
59
|
|
|
$this->_em->clear(); |
|
60
|
|
|
|
|
61
|
|
|
$entity = $this->_em->find(GH7761Entity::class, 1); |
|
62
|
|
|
self::assertCount(0, $entity->children); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @Entity |
|
68
|
|
|
* @ChangeTrackingPolicy("DEFERRED_EXPLICIT") |
|
69
|
|
|
*/ |
|
70
|
|
|
class GH7761Entity |
|
71
|
|
|
{ |
|
72
|
|
|
/** |
|
73
|
|
|
* @Id |
|
74
|
|
|
* @Column(type="integer") |
|
75
|
|
|
* @GeneratedValue |
|
76
|
|
|
*/ |
|
77
|
|
|
public $id; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @ManyToMany(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\GH7761ChildEntity", cascade={"all"}) |
|
81
|
|
|
* @JoinTable(name="gh7761_to_child", |
|
82
|
|
|
* joinColumns={@JoinColumn(name="entity_id")}, |
|
83
|
|
|
* inverseJoinColumns={@JoinColumn(name="child_id")} |
|
84
|
|
|
* ) |
|
85
|
|
|
*/ |
|
86
|
|
|
public $children; |
|
87
|
|
|
|
|
88
|
|
|
public function __construct() |
|
89
|
|
|
{ |
|
90
|
|
|
$this->children = new ArrayCollection(); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @Entity |
|
96
|
|
|
* @ChangeTrackingPolicy("DEFERRED_EXPLICIT") |
|
97
|
|
|
*/ |
|
98
|
|
|
class GH7761ChildEntity |
|
99
|
|
|
{ |
|
100
|
|
|
/** |
|
101
|
|
|
* @Id |
|
102
|
|
|
* @Column(type="integer") |
|
103
|
|
|
* @GeneratedValue |
|
104
|
|
|
*/ |
|
105
|
|
|
public $id; |
|
106
|
|
|
} |
|
107
|
|
|
|