1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ODM\CouchDB\Functional; |
4
|
|
|
|
5
|
|
|
use Doctrine\ODM\CouchDB\Mapping\ClassMetadata; |
6
|
|
|
|
7
|
|
|
class CascadePersistTest extends \Doctrine\Tests\ODM\CouchDB\CouchDBFunctionalTestCase |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var DocumentManager |
11
|
|
|
*/ |
12
|
|
|
private $dm; |
13
|
|
|
|
14
|
|
View Code Duplication |
public function setUp() |
15
|
|
|
{ |
16
|
|
|
$this->dm = $this->createDocumentManager(); |
|
|
|
|
17
|
|
|
|
18
|
|
|
$class = $this->dm->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
19
|
|
|
$class->associationsMappings['groups']['cascade'] = ClassMetadata::CASCADE_PERSIST; |
20
|
|
|
|
21
|
|
|
$class = $this->dm->getClassMetadata('Doctrine\Tests\Models\CMS\CmsGroup'); |
22
|
|
|
$class->associationsMappings['users']['cascade'] = ClassMetadata::CASCADE_PERSIST; |
23
|
|
|
|
24
|
|
|
$class = $this->dm->getClassMetadata('Doctrine\Tests\Models\CMS\CmsArticle'); |
25
|
|
|
$class->associationsMappings['user']['cascade'] = ClassMetadata::CASCADE_PERSIST; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testCascadePersistCollection() |
29
|
|
|
{ |
30
|
|
|
$group1 = new \Doctrine\Tests\Models\CMS\CmsGroup(); |
31
|
|
|
$group1->name = "Test!"; |
32
|
|
|
|
33
|
|
|
$group2 = new \Doctrine\Tests\Models\CMS\CmsGroup(); |
34
|
|
|
$group2->name = "Test!"; |
35
|
|
|
|
36
|
|
|
$user = new \Doctrine\Tests\Models\CMS\CmsUser(); |
37
|
|
|
$user->username = "beberlei"; |
38
|
|
|
$user->name = "Benjamin"; |
39
|
|
|
$user->addGroup($group1); |
40
|
|
|
$user->addGroup($group2); |
41
|
|
|
|
42
|
|
|
$this->dm->persist($user); |
43
|
|
|
|
44
|
|
|
$this->assertTrue($this->dm->contains($group1)); |
45
|
|
|
$this->assertTrue($this->dm->contains($group2)); |
46
|
|
|
|
47
|
|
|
$this->dm->flush(); |
48
|
|
|
$this->dm->clear(); |
49
|
|
|
|
50
|
|
|
$pUser = $this->dm->find('Doctrine\Tests\Models\CMS\CmsUser', $user->id); |
51
|
|
|
$this->assertCount(2, $pUser->groups); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
View Code Duplication |
public function testCascadePersistForManagedEntity() |
55
|
|
|
{ |
56
|
|
|
$user = new \Doctrine\Tests\Models\CMS\CmsUser(); |
57
|
|
|
$user->username = "beberlei"; |
58
|
|
|
$user->name = "Benjamin"; |
59
|
|
|
$this->dm->persist($user); |
60
|
|
|
$this->dm->flush(); |
61
|
|
|
|
62
|
|
|
$group1 = new \Doctrine\Tests\Models\CMS\CmsGroup(); |
63
|
|
|
$group1->name = "Test!"; |
64
|
|
|
|
65
|
|
|
$group2 = new \Doctrine\Tests\Models\CMS\CmsGroup(); |
66
|
|
|
$group2->name = "Test!"; |
67
|
|
|
|
68
|
|
|
$user->addGroup($group1); |
69
|
|
|
$user->addGroup($group2); |
70
|
|
|
$this->dm->persist($user); |
71
|
|
|
|
72
|
|
|
$this->assertTrue($this->dm->contains($group1)); |
73
|
|
|
$this->assertTrue($this->dm->contains($group2)); |
74
|
|
|
|
75
|
|
|
$this->dm->flush(); |
76
|
|
|
$this->dm->clear(); |
77
|
|
|
|
78
|
|
|
$pUser = $this->dm->find('Doctrine\Tests\Models\CMS\CmsUser', $user->id); |
79
|
|
|
$this->assertCount(2, $pUser->groups); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testCascadePersistSingleDocument() |
83
|
|
|
{ |
84
|
|
|
$user = new \Doctrine\Tests\Models\CMS\CmsUser(); |
85
|
|
|
$user->username = "beberlei"; |
86
|
|
|
$user->name = "Benjamin"; |
87
|
|
|
|
88
|
|
|
$article = new \Doctrine\Tests\Models\CMS\CmsArticle(); |
89
|
|
|
$article->text = "foo"; |
90
|
|
|
$article->topic = "bar"; |
91
|
|
|
$article->user = $user; |
92
|
|
|
|
93
|
|
|
$this->dm->persist($article); |
94
|
|
|
|
95
|
|
|
$this->assertTrue($this->dm->contains($user)); |
96
|
|
|
|
97
|
|
|
$this->dm->flush(); |
98
|
|
|
$this->dm->clear(); |
99
|
|
|
|
100
|
|
|
$article = $this->dm->find('Doctrine\Tests\Models\CMS\CmsArticle', $article->id); |
101
|
|
|
$this->assertEquals($user->id, $article->user->getId()); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
View Code Duplication |
public function testCascadeManagedDocumentCollectionDuringFlush() |
105
|
|
|
{ |
106
|
|
|
$user = new \Doctrine\Tests\Models\CMS\CmsUser(); |
107
|
|
|
$user->username = "beberlei"; |
108
|
|
|
$user->name = "Benjamin"; |
109
|
|
|
$this->dm->persist($user); |
110
|
|
|
$this->dm->flush(); |
111
|
|
|
$this->dm->clear(); |
112
|
|
|
|
113
|
|
|
$group1 = new \Doctrine\Tests\Models\CMS\CmsGroup(); |
114
|
|
|
$group1->name = "Test!"; |
115
|
|
|
|
116
|
|
|
$group2 = new \Doctrine\Tests\Models\CMS\CmsGroup(); |
117
|
|
|
$group2->name = "Test!"; |
118
|
|
|
|
119
|
|
|
$user = $this->dm->find('Doctrine\Tests\Models\CMS\CmsUser', $user->id); |
120
|
|
|
$user->addGroup($group1); |
121
|
|
|
$user->addGroup($group2); |
122
|
|
|
|
123
|
|
|
$this->assertFalse($this->dm->contains($group1)); |
124
|
|
|
$this->assertFalse($this->dm->contains($group2)); |
125
|
|
|
|
126
|
|
|
$this->dm->flush(); |
127
|
|
|
$this->dm->clear(); |
128
|
|
|
|
129
|
|
|
$pUser = $this->dm->find('Doctrine\Tests\Models\CMS\CmsUser', $user->id); |
130
|
|
|
$this->assertCount(2, $pUser->groups); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function testCascadeManagedDocumentReferenceDuringFlush() |
134
|
|
|
{ |
135
|
|
|
$article = new \Doctrine\Tests\Models\CMS\CmsArticle(); |
136
|
|
|
$article->text = "foo"; |
137
|
|
|
$article->topic = "bar"; |
138
|
|
|
|
139
|
|
|
$this->dm->persist($article); |
140
|
|
|
|
141
|
|
|
$user = new \Doctrine\Tests\Models\CMS\CmsUser(); |
142
|
|
|
$user->username = "beberlei"; |
143
|
|
|
$user->name = "Benjamin"; |
144
|
|
|
$article->user = $user; |
145
|
|
|
|
146
|
|
|
$this->assertFalse($this->dm->contains($user)); |
147
|
|
|
|
148
|
|
|
$this->dm->flush(); |
149
|
|
|
$this->dm->clear(); |
150
|
|
|
|
151
|
|
|
$article = $this->dm->find('Doctrine\Tests\Models\CMS\CmsArticle', $article->id); |
152
|
|
|
$this->assertEquals($user->id, $article->user->getId()); |
153
|
|
|
} |
154
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..