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
|
|
|
class GH7589Test extends OrmFunctionalTestCase |
11
|
|
|
{ |
12
|
|
|
public function setUp() |
13
|
|
|
{ |
14
|
|
|
parent::setUp(); |
15
|
|
|
$this->_schemaTool->createSchema( |
16
|
|
|
[ |
17
|
|
|
$this->_em->getClassMetadata(GH7589User::class), |
18
|
|
|
$this->_em->getClassMetadata(GH7589Article::class), |
19
|
|
|
] |
20
|
|
|
); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testPersistedThenRemovedEntityIsRemoved() |
24
|
|
|
{ |
25
|
|
|
$user = new GH7589User(1); |
26
|
|
|
$article = new GH7589Article(1, $user); |
27
|
|
|
|
28
|
|
|
$this->_em->persist($user); |
29
|
|
|
$this->_em->persist($article); |
30
|
|
|
|
31
|
|
|
$this->_em->remove($article); |
32
|
|
|
|
33
|
|
|
$this->_em->flush(); |
34
|
|
|
|
35
|
|
|
$this->assertNull($this->_em->find(GH7589Article::class, 1), 'Entity should not be persisted.'); |
36
|
|
|
$this->assertCount(0, $user->getArticles(), 'Entity should be removed from inverse association collection.'); |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @Entity |
42
|
|
|
*/ |
43
|
|
|
class GH7589User |
44
|
|
|
{ |
45
|
|
|
/** |
46
|
|
|
* @Id |
47
|
|
|
* @Column(type="integer") |
48
|
|
|
*/ |
49
|
|
|
private $id; |
50
|
|
|
|
51
|
|
|
/** @OneToMany(targetEntity="GH7589Article", mappedBy="user") */ |
52
|
|
|
private $articles; |
53
|
|
|
|
54
|
|
|
public function __construct(int $id) |
55
|
|
|
{ |
56
|
|
|
$this->id = $id; |
57
|
|
|
$this->articles = new ArrayCollection(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function addArticle(GH7589Article $article) : void |
61
|
|
|
{ |
62
|
|
|
$this->articles->add($article); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getArticles() : array |
66
|
|
|
{ |
67
|
|
|
return $this->articles->getValues(); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @Entity |
73
|
|
|
*/ |
74
|
|
|
class GH7589Article |
75
|
|
|
{ |
76
|
|
|
/** |
77
|
|
|
* @Id |
78
|
|
|
* @Column(type="integer") |
79
|
|
|
*/ |
80
|
|
|
private $id; |
81
|
|
|
|
82
|
|
|
/** @ManyToOne(targetEntity="GH7589User", inversedBy="articles") */ |
83
|
|
|
private $user; |
84
|
|
|
|
85
|
|
|
public function __construct(int $id, GH7589User $user) |
86
|
|
|
{ |
87
|
|
|
$this->id = $id; |
88
|
|
|
$this->user = $user; |
89
|
|
|
$this->user->addArticle($this); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|