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\ORM\Annotation as ORM; |
9
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
10
|
|
|
|
11
|
|
|
final class GH7761Test extends OrmFunctionalTestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* {@inheritDoc} |
15
|
|
|
*/ |
16
|
|
|
protected function setUp() : void |
17
|
|
|
{ |
18
|
|
|
parent::setUp(); |
19
|
|
|
|
20
|
|
|
$this->setUpEntitySchema([ |
21
|
|
|
GH7761Entity::class, |
22
|
|
|
GH7761ChildEntity::class, |
23
|
|
|
]); |
24
|
|
|
|
25
|
|
|
$parent = new GH7761Entity(); |
26
|
|
|
$child = new GH7761ChildEntity(); |
27
|
|
|
$parent->children->add($child); |
28
|
|
|
|
29
|
|
|
$this->em->persist($parent); |
30
|
|
|
$this->em->persist($child); |
31
|
|
|
$this->em->flush(); |
32
|
|
|
$this->em->clear(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testCollectionClearDoesNotClearIfNotPersisted() : void |
36
|
|
|
{ |
37
|
|
|
/** @var GH7761Entity $entity */ |
38
|
|
|
$entity = $this->em->find(GH7761Entity::class, 1); |
39
|
|
|
$entity->children->clear(); |
40
|
|
|
$this->em->persist(new GH7761Entity()); |
41
|
|
|
$this->em->flush(); |
42
|
|
|
|
43
|
|
|
$this->em->clear(); |
44
|
|
|
|
45
|
|
|
$entity = $this->em->find(GH7761Entity::class, 1); |
46
|
|
|
self::assertCount(1, $entity->children); |
47
|
|
|
|
48
|
|
|
$this->em->clear(); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @ORM\Entity |
54
|
|
|
* @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT") |
55
|
|
|
*/ |
56
|
|
|
class GH7761Entity |
57
|
|
|
{ |
58
|
|
|
/** |
59
|
|
|
* @ORM\Id |
60
|
|
|
* @ORM\Column(type="integer") |
61
|
|
|
* @ORM\GeneratedValue |
62
|
|
|
*/ |
63
|
|
|
public $id; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @ORM\ManyToMany(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\GH7761ChildEntity", cascade={"all"}) |
67
|
|
|
* @ORM\JoinTable(name="gh7761_to_child", |
68
|
|
|
* joinColumns={@ORM\JoinColumn(name="entity_id")}, |
69
|
|
|
* inverseJoinColumns={@ORM\JoinColumn(name="child_id")} |
70
|
|
|
* ) |
71
|
|
|
*/ |
72
|
|
|
public $children; |
73
|
|
|
|
74
|
|
|
public function __construct() |
75
|
|
|
{ |
76
|
|
|
$this->children = new ArrayCollection(); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @ORM\Entity |
82
|
|
|
* @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT") |
83
|
|
|
*/ |
84
|
|
|
class GH7761ChildEntity |
85
|
|
|
{ |
86
|
|
|
/** |
87
|
|
|
* @ORM\Id |
88
|
|
|
* @ORM\Column(type="integer") |
89
|
|
|
* @ORM\GeneratedValue |
90
|
|
|
*/ |
91
|
|
|
public $id; |
92
|
|
|
} |
93
|
|
|
|