1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ODM\CouchDB\Functional; |
4
|
|
|
|
5
|
|
|
class RepositoryTest extends \Doctrine\Tests\ODM\CouchDB\CouchDBFunctionalTestCase |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @var DocumentManager |
9
|
|
|
*/ |
10
|
|
|
private $dm; |
11
|
|
|
|
12
|
|
|
private $type; |
13
|
|
|
|
14
|
|
|
public function setUp() |
15
|
|
|
{ |
16
|
|
|
$this->type = 'Doctrine\Tests\Models\CMS\CmsUser'; |
17
|
|
|
$this->dm = $this->createDocumentManager(); |
|
|
|
|
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function testFindMany() |
21
|
|
|
{ |
22
|
|
|
$this->dm = $this->createDocumentManager(); |
|
|
|
|
23
|
|
|
|
24
|
|
|
$user1 = new \Doctrine\Tests\Models\CMS\CmsUser(); |
25
|
|
|
$user1->username = "beberlei"; |
26
|
|
|
$user1->status = "active"; |
27
|
|
|
$user1->name = "Benjamin"; |
28
|
|
|
|
29
|
|
|
$user2 = new \Doctrine\Tests\Models\CMS\CmsUser(); |
30
|
|
|
$user2->username = "lsmith"; |
31
|
|
|
$user2->status = "active"; |
32
|
|
|
$user2->name = "Lukas"; |
33
|
|
|
|
34
|
|
|
$this->dm = $this->createDocumentManager(); |
35
|
|
|
$this->dm->persist($user1); |
36
|
|
|
$this->dm->persist($user2); |
37
|
|
|
$this->dm->flush(); |
38
|
|
|
|
39
|
|
|
$users = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findMany(array($user1->id, $user2->id)); |
40
|
|
|
$this->assertCount(2, $users); |
41
|
|
|
$this->assertSame($user1, $users[0]); |
42
|
|
|
$this->assertSame($user2, $users[1]); |
43
|
|
|
|
44
|
|
|
$users = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findMany(array($user1->id, $user2->id), 1, 0); |
45
|
|
|
$this->assertCount(1, $users); |
46
|
|
|
$this->assertSame($user1, $users[0]); |
47
|
|
|
|
48
|
|
|
$users = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findMany(array($user1->id, $user2->id), 1, 1); |
49
|
|
|
$this->assertCount(1, $users); |
50
|
|
|
$this->assertSame($user2, $users[1]); |
51
|
|
|
|
52
|
|
|
$this->dm->clear(); |
53
|
|
|
|
54
|
|
|
$users = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findMany(array($user1->id, $user2->id)); |
55
|
|
|
$this->assertEquals($user1->id, $users[0]->id); |
56
|
|
|
$this->assertEquals($user2->id, $users[1]->id); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testFindAll() |
60
|
|
|
{ |
61
|
|
View Code Duplication |
for ($i = 0; $i < 10; $i++) { |
|
|
|
|
62
|
|
|
$user = new \Doctrine\Tests\Models\CMS\CmsUser(); |
63
|
|
|
$user->username = "beberlei" . $i; |
64
|
|
|
$user->status = "active"; |
65
|
|
|
$user->name = "Benjamin" . $i; |
66
|
|
|
|
67
|
|
|
$this->dm->persist($user); |
68
|
|
|
} |
69
|
|
|
for ($i = 0; $i < 10; $i++) { |
70
|
|
|
$group = new \Doctrine\Tests\Models\CMS\CmsGroup(); |
71
|
|
|
$group->name = "Group" . $i; |
72
|
|
|
$this->dm->persist($group); |
73
|
|
|
} |
74
|
|
|
$this->dm->flush(); |
75
|
|
|
|
76
|
|
|
$users = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findAll(); |
77
|
|
|
$this->assertCount(10, $users); |
78
|
|
|
$this->assertContainsOnly('Doctrine\Tests\Models\CMS\CmsUser', $users); |
79
|
|
|
|
80
|
|
|
$groups = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findAll(); |
81
|
|
|
$this->assertCount(0, $groups, "No results, group is not indexed!"); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function testLoadManyWithMissingIds() |
85
|
|
|
{ |
86
|
|
|
$this->dm = $this->createDocumentManager(); |
|
|
|
|
87
|
|
|
$users = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findMany(array('missing-id-1', 'missing-id-2')); |
88
|
|
|
$this->assertEmpty($users); |
89
|
|
|
|
90
|
|
|
$user1 = new \Doctrine\Tests\Models\CMS\CmsUser(); |
91
|
|
|
$user1->username = "beberlei"; |
92
|
|
|
$user1->status = "active"; |
93
|
|
|
$user1->name = "Benjamin"; |
94
|
|
|
$this->dm = $this->createDocumentManager(); |
95
|
|
|
$this->dm->persist($user1); |
96
|
|
|
$this->dm->flush(); |
97
|
|
|
$this->dm->clear(); |
98
|
|
|
|
99
|
|
|
$users = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findMany(array($user1->id, 'missing-id-2')); |
100
|
|
|
$this->assertCount(1, $users); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function testFindBy() |
104
|
|
|
{ |
105
|
|
View Code Duplication |
for ($i = 0; $i < 10; $i++) { |
|
|
|
|
106
|
|
|
$user = new \Doctrine\Tests\Models\CMS\CmsUser(); |
107
|
|
|
$user->username = "beberlei" . $i; |
108
|
|
|
$user->status = ($i % 2 == 0) ? "active" : "inactive"; |
109
|
|
|
$user->name = "Benjamin"; |
110
|
|
|
|
111
|
|
|
$this->dm->persist($user); |
112
|
|
|
} |
113
|
|
|
$this->dm->flush(); |
114
|
|
|
|
115
|
|
|
$users = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findBy(array('status' => 'active')); |
116
|
|
|
|
117
|
|
|
$this->assertCount(5, $users); |
118
|
|
|
$this->assertContainsOnly('Doctrine\Tests\Models\CMS\CmsUser', $users); |
119
|
|
|
|
120
|
|
|
$users = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findBy(array('status' => 'active'), null, 2); |
121
|
|
|
$this->assertCount(2, $users); |
122
|
|
|
|
123
|
|
|
$users = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findBy(array('status' => 'inactive')); |
124
|
|
|
|
125
|
|
|
$this->assertCount(5, $users); |
126
|
|
|
$this->assertContainsOnly('Doctrine\Tests\Models\CMS\CmsUser', $users); |
127
|
|
|
|
128
|
|
|
$users = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findBy(array('status' => 'active', 'username' => 'beberlei0')); |
129
|
|
|
$this->assertCount(1, $users); |
130
|
|
|
|
131
|
|
|
$users = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findBy(array('status' => 'active', 'name' => 'Benjamin'), null, 2); |
132
|
|
|
$this->assertCount(2, $users); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function testFindByManyConstraints() |
136
|
|
|
{ |
137
|
|
View Code Duplication |
for ($i = 0; $i < 10; $i++) { |
|
|
|
|
138
|
|
|
$user = new \Doctrine\Tests\Models\CMS\CmsUser(); |
139
|
|
|
$user->username = "beberlei" . $i; |
140
|
|
|
$user->status = ($i % 2 == 0) ? "active" : "inactive"; |
141
|
|
|
$user->name = "Benjamin" . $i; |
142
|
|
|
|
143
|
|
|
$this->dm->persist($user); |
144
|
|
|
} |
145
|
|
|
$this->dm->flush(); |
146
|
|
|
|
147
|
|
|
$users = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findBy(array('username' => 'beberlei0')); |
148
|
|
|
$this->assertCount(1, $users); |
149
|
|
|
$this->assertEquals('beberlei0', $users[0]->username); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
View Code Duplication |
public function testFindByIdUsesIdentityMap() |
|
|
|
|
153
|
|
|
{ |
154
|
|
|
$this->dm = $this->createDocumentManager(); |
|
|
|
|
155
|
|
|
|
156
|
|
|
$user = new \Doctrine\Tests\Models\CMS\CmsUser(); |
157
|
|
|
$user->username = "beberlei"; |
158
|
|
|
$user->status = "active"; |
159
|
|
|
$user->name = "Benjamin"; |
160
|
|
|
|
161
|
|
|
$this->dm->persist($user); |
162
|
|
|
$this->dm->flush(); |
163
|
|
|
$this->dm->clear(); |
164
|
|
|
|
165
|
|
|
$user1 = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->find($user->id); |
166
|
|
|
$user2 = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->find($user->id); |
167
|
|
|
|
168
|
|
|
$this->assertSame($user1, $user2); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function testFindByReusesIdentities() |
172
|
|
|
{ |
173
|
|
|
$this->dm = $this->createDocumentManager(); |
|
|
|
|
174
|
|
|
|
175
|
|
|
$user = new \Doctrine\Tests\Models\CMS\CmsUser(); |
176
|
|
|
$user->username = "beberlei"; |
177
|
|
|
$user->status = "active"; |
178
|
|
|
$user->name = "Benjamin"; |
179
|
|
|
|
180
|
|
|
$this->dm->persist($user); |
181
|
|
|
$this->dm->flush(); |
182
|
|
|
$this->dm->clear(); |
183
|
|
|
|
184
|
|
|
$user1 = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findOneBy(array('username' => 'beberlei')); |
185
|
|
|
$user2 = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findOneBy(array('username' => 'beberlei')); |
186
|
|
|
|
187
|
|
|
$this->assertSame($user1, $user2); |
188
|
|
|
} |
189
|
|
|
} |
190
|
|
|
|
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..