Failed Conditions
Pull Request — develop (#6935)
by Michael
65:23
created

testMatchingCriteriaStartsWithComparison()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
dl 15
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\ORM\Functional;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Criteria;
9
use Doctrine\DBAL\Connection;
10
use Doctrine\DBAL\LockMode;
11
use Doctrine\ORM\EntityRepository;
12
use Doctrine\ORM\OptimisticLockException;
13
use Doctrine\ORM\ORMException;
14
use Doctrine\ORM\Query;
15
use Doctrine\ORM\TransactionRequiredException;
16
use Doctrine\Tests\Models\CMS\CmsAddress;
17
use Doctrine\Tests\Models\CMS\CmsEmail;
18
use Doctrine\Tests\Models\CMS\CmsUser;
19
use Doctrine\Tests\Models\DDC753\DDC753CustomRepository;
20
use Doctrine\Tests\Models\DDC753\DDC753DefaultRepository;
21
use Doctrine\Tests\Models\DDC753\DDC753EntityWithCustomRepository;
22
use Doctrine\Tests\Models\DDC753\DDC753EntityWithDefaultCustomRepository;
23
use Doctrine\Tests\Models\DDC753\DDC753InvalidRepository;
24
use Doctrine\Tests\OrmFunctionalTestCase;
25
26
/**
27
 * @author robo
28
 */
29
class EntityRepositoryTest extends OrmFunctionalTestCase
30
{
31
    protected function setUp()
32
    {
33
        $this->useModelSet('cms');
34
        parent::setUp();
35
    }
36
37
    public function loadFixture()
38
    {
39
        $user = new CmsUser;
40
        $user->name = 'Roman';
41
        $user->username = 'romanb';
42
        $user->status = 'freak';
43
        $this->em->persist($user);
44
45
        $user2 = new CmsUser;
46
        $user2->name = 'Guilherme';
47
        $user2->username = 'gblanco';
48
        $user2->status = 'dev';
49
        $this->em->persist($user2);
50
51
        $user3 = new CmsUser;
52
        $user3->name = 'Benjamin';
53
        $user3->username = 'beberlei';
54
        $user3->status = null;
55
        $this->em->persist($user3);
56
57
        $user4 = new CmsUser;
58
        $user4->name = 'Alexander';
59
        $user4->username = 'asm89';
60
        $user4->status = 'dev';
61
        $this->em->persist($user4);
62
63
        $this->em->flush();
64
65
        $user1Id = $user->getId();
66
67
        unset($user);
68
        unset($user2);
69
        unset($user3);
70
        unset($user4);
71
72
        $this->em->clear();
73
74
        return $user1Id;
75
    }
76
77
    public function loadAssociatedFixture()
78
    {
79
        $address = new CmsAddress();
80
        $address->city = "Berlin";
81
        $address->country = "Germany";
82
        $address->street = "Foostreet";
83
        $address->zip = "12345";
84
85
        $user = new CmsUser();
86
        $user->name = 'Roman';
87
        $user->username = 'romanb';
88
        $user->status = 'freak';
89
        $user->setAddress($address);
90
91
        $this->em->persist($user);
92
        $this->em->persist($address);
93
        $this->em->flush();
94
        $this->em->clear();
95
96
        return [$user->id, $address->id];
97
    }
98
99
    public function loadFixtureUserEmail()
100
    {
101
        $user1 = new CmsUser();
102
        $user2 = new CmsUser();
103
        $user3 = new CmsUser();
104
105
        $email1 = new CmsEmail();
106
        $email2 = new CmsEmail();
107
        $email3 = new CmsEmail();
108
109
        $user1->name     = 'Test 1';
110
        $user1->username = 'test1';
111
        $user1->status   = 'active';
112
113
        $user2->name     = 'Test 2';
114
        $user2->username = 'test2';
115
        $user2->status   = 'active';
116
117
        $user3->name     = 'Test 3';
118
        $user3->username = 'test3';
119
        $user3->status   = 'active';
120
121
        $email1->email   = '[email protected]';
122
        $email2->email   = '[email protected]';
123
        $email3->email   = '[email protected]';
124
125
        $user1->setEmail($email1);
126
        $user2->setEmail($email2);
127
        $user3->setEmail($email3);
128
129
        $this->em->persist($user1);
130
        $this->em->persist($user2);
131
        $this->em->persist($user3);
132
133
        $this->em->persist($email1);
134
        $this->em->persist($email2);
135
        $this->em->persist($email3);
136
137
        $this->em->flush();
138
        $this->em->clear();
139
140
        return [$user1, $user2, $user3];
141
    }
142
143
    public function buildUser($name, $username, $status, $address)
144
    {
145
        $user = new CmsUser();
146
        $user->name     = $name;
147
        $user->username = $username;
148
        $user->status   = $status;
149
        $user->setAddress($address);
150
151
        $this->em->persist($user);
152
        $this->em->flush();
153
154
        return $user;
155
    }
156
157
    public function buildAddress($country, $city, $street, $zip)
158
    {
159
        $address = new CmsAddress();
160
        $address->country = $country;
161
        $address->city    = $city;
162
        $address->street  = $street;
163
        $address->zip     = $zip;
164
165
        $this->em->persist($address);
166
        $this->em->flush();
167
168
        return $address;
169
    }
170
171 View Code Duplication
    public function testBasicFind()
172
    {
173
        $user1Id = $this->loadFixture();
174
        $repos = $this->em->getRepository(CmsUser::class);
175
176
        $user = $repos->find($user1Id);
177
        self::assertInstanceOf(CmsUser::class,$user);
178
        self::assertEquals('Roman', $user->name);
179
        self::assertEquals('freak', $user->status);
180
    }
181
182 View Code Duplication
    public function testFindByField()
183
    {
184
        $user1Id = $this->loadFixture();
0 ignored issues
show
Unused Code introduced by
$user1Id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
185
        $repos = $this->em->getRepository(CmsUser::class);
186
187
        $users = $repos->findBy(['status' => 'dev']);
188
        self::assertCount(2, $users);
189
        self::assertInstanceOf(CmsUser::class,$users[0]);
190
        self::assertEquals('Guilherme', $users[0]->name);
191
        self::assertEquals('dev', $users[0]->status);
192
    }
193
194 View Code Duplication
    public function testFindByAssociationWithIntegerAsParameter()
195
    {
196
        $address1 = $this->buildAddress('Germany', 'Berlim', 'Foo st.', '123456');
197
        $user1    = $this->buildUser('Benjamin', 'beberlei', 'dev', $address1);
198
199
        $address2 = $this->buildAddress('Brazil', 'São Paulo', 'Bar st.', '654321');
200
        $user2    = $this->buildUser('Guilherme', 'guilhermeblanco', 'freak', $address2);
201
202
        $address3 = $this->buildAddress('USA', 'Nashville', 'Woo st.', '321654');
203
        $user3    = $this->buildUser('Jonathan', 'jwage', 'dev', $address3);
0 ignored issues
show
Unused Code introduced by
$user3 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
204
205
        unset($address1);
206
        unset($address2);
207
        unset($address3);
208
209
        $this->em->clear();
210
211
        $repository = $this->em->getRepository(CmsAddress::class);
212
        $addresses  = $repository->findBy(['user' => [$user1->getId(), $user2->getId()]]);
213
214
        self::assertCount(2, $addresses);
215
        self::assertInstanceOf(CmsAddress::class,$addresses[0]);
216
    }
217
218 View Code Duplication
    public function testFindByAssociationWithObjectAsParameter()
219
    {
220
        $address1 = $this->buildAddress('Germany', 'Berlim', 'Foo st.', '123456');
221
        $user1    = $this->buildUser('Benjamin', 'beberlei', 'dev', $address1);
222
223
        $address2 = $this->buildAddress('Brazil', 'São Paulo', 'Bar st.', '654321');
224
        $user2    = $this->buildUser('Guilherme', 'guilhermeblanco', 'freak', $address2);
225
226
        $address3 = $this->buildAddress('USA', 'Nashville', 'Woo st.', '321654');
227
        $user3    = $this->buildUser('Jonathan', 'jwage', 'dev', $address3);
0 ignored issues
show
Unused Code introduced by
$user3 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
228
229
        unset($address1);
230
        unset($address2);
231
        unset($address3);
232
233
        $this->em->clear();
234
235
        $repository = $this->em->getRepository(CmsAddress::class);
236
        $addresses  = $repository->findBy(['user' => [$user1, $user2]]);
237
238
        self::assertCount(2, $addresses);
239
        self::assertInstanceOf(CmsAddress::class,$addresses[0]);
240
    }
241
242 View Code Duplication
    public function testFindFieldByMagicCall()
243
    {
244
        $user1Id = $this->loadFixture();
0 ignored issues
show
Unused Code introduced by
$user1Id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
245
        $repos = $this->em->getRepository(CmsUser::class);
246
247
        $users = $repos->findByStatus('dev');
0 ignored issues
show
Bug introduced by
The method findByStatus() does not exist on Doctrine\Common\Persistence\ObjectRepository. Did you maybe mean findBy()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
248
        self::assertCount(2, $users);
249
        self::assertInstanceOf(CmsUser::class,$users[0]);
250
        self::assertEquals('Guilherme', $users[0]->name);
251
        self::assertEquals('dev', $users[0]->status);
252
    }
253
254
    public function testFindAll()
255
    {
256
        $user1Id = $this->loadFixture();
0 ignored issues
show
Unused Code introduced by
$user1Id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
257
        $repos = $this->em->getRepository(CmsUser::class);
258
259
        $users = $repos->findAll();
260
        self::assertCount(4, $users);
261
    }
262
263
    public function testCount()
264
    {
265
        $this->loadFixture();
266
        $repos = $this->em->getRepository(CmsUser::class);
267
268
        $userCount = $repos->count([]);
269
        self::assertSame(4, $userCount);
270
271
        $userCount = $repos->count(['status' => 'dev']);
272
        self::assertSame(2, $userCount);
273
274
        $userCount = $repos->count(['status' => 'nonexistent']);
275
        self::assertSame(0, $userCount);
276
    }
277
278
    public function testCountBy()
279
    {
280
        $this->loadFixture();
281
        $repos = $this->em->getRepository(CmsUser::class);
282
283
        $userCount = $repos->countByStatus('dev');
284
        self::assertSame(2, $userCount);
285
    }
286
287
    /**
288
     * @expectedException \Doctrine\ORM\ORMException
289
     */
290
    public function testExceptionIsThrownWhenCallingFindByWithoutParameter() {
291
        $this->em->getRepository(CmsUser::class)
0 ignored issues
show
Bug introduced by
The method findByStatus() does not exist on Doctrine\Common\Persistence\ObjectRepository. Did you maybe mean findBy()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
292
                  ->findByStatus();
293
    }
294
295
    /**
296
     * @expectedException \Doctrine\ORM\ORMException
297
     */
298
    public function testExceptionIsThrownWhenUsingInvalidFieldName() {
299
        $this->em->getRepository(CmsUser::class)
0 ignored issues
show
Bug introduced by
The method findByThisFieldDoesNotExist() does not exist on Doctrine\Common\Persistence\ObjectRepository. Did you maybe mean findBy()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
300
                  ->findByThisFieldDoesNotExist('testvalue');
301
    }
302
303
    /**
304
     * @group locking
305
     * @group DDC-178
306
     */
307
    public function testPessimisticReadLockWithoutTransaction_ThrowsException()
308
    {
309
        $this->expectException(TransactionRequiredException::class);
310
311
        $this->em->getRepository(CmsUser::class)
312
                  ->find(1, LockMode::PESSIMISTIC_READ);
0 ignored issues
show
Unused Code introduced by
The call to ObjectRepository::find() has too many arguments starting with \Doctrine\DBAL\LockMode::PESSIMISTIC_READ.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
313
    }
314
315
    /**
316
     * @group locking
317
     * @group DDC-178
318
     */
319
    public function testPessimisticWriteLockWithoutTransaction_ThrowsException()
320
    {
321
        $this->expectException(TransactionRequiredException::class);
322
323
        $this->em->getRepository(CmsUser::class)
324
                  ->find(1, LockMode::PESSIMISTIC_WRITE);
0 ignored issues
show
Unused Code introduced by
The call to ObjectRepository::find() has too many arguments starting with \Doctrine\DBAL\LockMode::PESSIMISTIC_WRITE.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
325
    }
326
327
    /**
328
     * @group locking
329
     * @group DDC-178
330
     */
331
    public function testOptimisticLockUnversionedEntity_ThrowsException()
332
    {
333
        $this->expectException(OptimisticLockException::class);
334
335
        $this->em->getRepository(CmsUser::class)
336
                  ->find(1, LockMode::OPTIMISTIC);
0 ignored issues
show
Unused Code introduced by
The call to ObjectRepository::find() has too many arguments starting with \Doctrine\DBAL\LockMode::OPTIMISTIC.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
337
    }
338
339
    /**
340
     * @group locking
341
     * @group DDC-178
342
     */
343
    public function testIdentityMappedOptimisticLockUnversionedEntity_ThrowsException()
344
    {
345
        $user = new CmsUser;
346
        $user->name = 'Roman';
347
        $user->username = 'romanb';
348
        $user->status = 'freak';
349
        $this->em->persist($user);
350
        $this->em->flush();
351
352
        $userId = $user->id;
353
354
        $this->em->find(CmsUser::class, $userId);
355
356
        $this->expectException(OptimisticLockException::class);
357
358
        $this->em->find(CmsUser::class, $userId, LockMode::OPTIMISTIC);
0 ignored issues
show
Unused Code introduced by
The call to EntityManagerInterface::find() has too many arguments starting with \Doctrine\DBAL\LockMode::OPTIMISTIC.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
359
    }
360
361
    /**
362
     * @group DDC-819
363
     */
364
    public function testFindMagicCallByNullValue()
365
    {
366
        $this->loadFixture();
367
368
        $repos = $this->em->getRepository(CmsUser::class);
369
370
        $users = $repos->findByStatus(null);
0 ignored issues
show
Bug introduced by
The method findByStatus() does not exist on Doctrine\Common\Persistence\ObjectRepository. Did you maybe mean findBy()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
371
        self::assertCount(1, $users);
372
    }
373
374
    /**
375
     * @group DDC-819
376
     */
377
    public function testInvalidMagicCall()
378
    {
379
        $this->expectException(\BadMethodCallException::class);
380
381
        $repos = $this->em->getRepository(CmsUser::class);
382
        $repos->foo();
383
    }
384
385
    /**
386
     * @group DDC-817
387
     */
388
    public function testFindByAssociationKey_ExceptionOnInverseSide()
389
    {
390
        list($userId, $addressId) = $this->loadAssociatedFixture();
0 ignored issues
show
Unused Code introduced by
The assignment to $userId is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
391
        $repos = $this->em->getRepository(CmsUser::class);
392
393
        $this->expectException(ORMException::class);
394
        $this->expectExceptionMessage("You cannot search for the association field 'Doctrine\Tests\Models\CMS\CmsUser#address', because it is the inverse side of an association. Find methods only work on owning side associations.");
395
396
        $user = $repos->findBy(['address' => $addressId]);
0 ignored issues
show
Unused Code introduced by
$user is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
397
    }
398
399
    /**
400
     * @group DDC-817
401
     */
402 View Code Duplication
    public function testFindOneByAssociationKey()
403
    {
404
        list($userId, $addressId) = $this->loadAssociatedFixture();
405
        $repos = $this->em->getRepository(CmsAddress::class);
406
        $address = $repos->findOneBy(['user' => $userId]);
407
408
        self::assertInstanceOf(CmsAddress::class, $address);
409
        self::assertEquals($addressId, $address->id);
410
    }
411
412
    /**
413
     * @group DDC-1241
414
     */
415
    public function testFindOneByOrderBy()
416
    {
417
    	$this->loadFixture();
418
419
    	$repos = $this->em->getRepository(CmsUser::class);
420
    	$userAsc = $repos->findOneBy([], ["username" => "ASC"]);
0 ignored issues
show
Unused Code introduced by
The call to ObjectRepository::findOneBy() has too many arguments starting with array('username' => 'ASC').

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
421
    	$userDesc = $repos->findOneBy([], ["username" => "DESC"]);
0 ignored issues
show
Unused Code introduced by
The call to ObjectRepository::findOneBy() has too many arguments starting with array('username' => 'DESC').

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
422
423
    	self::assertNotSame($userAsc, $userDesc);
424
    }
425
426
    /**
427
     * @group DDC-817
428
     */
429 View Code Duplication
    public function testFindByAssociationKey()
430
    {
431
        list($userId, $addressId) = $this->loadAssociatedFixture();
432
        $repos = $this->em->getRepository(CmsAddress::class);
433
        $addresses = $repos->findBy(['user' => $userId]);
434
435
        self::assertContainsOnly(CmsAddress::class, $addresses);
436
        self::assertCount(1, $addresses);
437
        self::assertEquals($addressId, $addresses[0]->id);
438
    }
439
440
    /**
441
     * @group DDC-817
442
     */
443
    public function testFindAssociationByMagicCall()
444
    {
445
        list($userId, $addressId) = $this->loadAssociatedFixture();
446
        $repos = $this->em->getRepository(CmsAddress::class);
447
        $addresses = $repos->findByUser($userId);
0 ignored issues
show
Bug introduced by
The method findByUser() does not exist on Doctrine\Common\Persistence\ObjectRepository. Did you maybe mean findBy()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
448
449
        self::assertContainsOnly(CmsAddress::class, $addresses);
450
        self::assertCount(1, $addresses);
451
        self::assertEquals($addressId, $addresses[0]->id);
452
    }
453
454
    /**
455
     * @group DDC-817
456
     */
457
    public function testFindOneAssociationByMagicCall()
458
    {
459
        list($userId, $addressId) = $this->loadAssociatedFixture();
460
        $repos = $this->em->getRepository(CmsAddress::class);
461
        $address = $repos->findOneByUser($userId);
0 ignored issues
show
Bug introduced by
The method findOneByUser() does not exist on Doctrine\Common\Persistence\ObjectRepository. Did you maybe mean findOneBy()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
462
463
        self::assertInstanceOf(CmsAddress::class, $address);
464
        self::assertEquals($addressId, $address->id);
465
    }
466
467
    public function testValidNamedQueryRetrieval()
468
    {
469
        $repos = $this->em->getRepository(CmsUser::class);
470
471
        $query = $repos->createNamedQuery('all');
472
473
        self::assertInstanceOf(Query::class, $query);
474
        self::assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u', $query->getDQL());
475
    }
476
477
    public function testInvalidNamedQueryRetrieval()
478
    {
479
        $repos = $this->em->getRepository(CmsUser::class);
480
481
        $this->expectException(\Doctrine\ORM\Mapping\MappingException::class);
482
483
        $repos->createNamedQuery('invalidNamedQuery');
484
    }
485
486
    /**
487
     * @group DDC-1087
488
     */
489
    public function testIsNullCriteriaDoesNotGenerateAParameter()
490
    {
491
        $repos = $this->em->getRepository(CmsUser::class);
492
        $users = $repos->findBy(['status' => null, 'username' => 'romanb']);
0 ignored issues
show
Unused Code introduced by
$users is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
493
494
        $params = $this->sqlLoggerStack->queries[$this->sqlLoggerStack->currentQuery]['params'];
495
        self::assertCount(1, $params, "Should only execute with one parameter.");
496
        self::assertEquals(['romanb'], $params);
497
    }
498
499
    public function testIsNullCriteria()
500
    {
501
        $this->loadFixture();
502
503
        $repos = $this->em->getRepository(CmsUser::class);
504
505
        $users = $repos->findBy(['status' => null]);
506
        self::assertCount(1, $users);
507
    }
508
509
    /**
510
     * @group DDC-1094
511
     */
512
    public function testFindByLimitOffset()
513
    {
514
        $this->loadFixture();
515
516
        $repos = $this->em->getRepository(CmsUser::class);
517
518
        $users1 = $repos->findBy([], null, 1, 0);
519
        $users2 = $repos->findBy([], null, 1, 1);
520
521
        self::assertCount(4, $repos->findBy([]));
522
        self::assertCount(1, $users1);
523
        self::assertCount(1, $users2);
524
        self::assertNotSame($users1[0], $users2[0]);
525
    }
526
527
    /**
528
     * @group DDC-1094
529
     */
530
    public function testFindByOrderBy()
531
    {
532
        $this->loadFixture();
533
534
        $repos = $this->em->getRepository(CmsUser::class);
535
        $usersAsc = $repos->findBy([], ["username" => "ASC"]);
536
        $usersDesc = $repos->findBy([], ["username" => "DESC"]);
537
538
        self::assertCount(4, $usersAsc, "Pre-condition: only four users in fixture");
539
        self::assertCount(4, $usersDesc, "Pre-condition: only four users in fixture");
540
        self::assertSame($usersAsc[0], $usersDesc[3]);
541
        self::assertSame($usersAsc[3], $usersDesc[0]);
542
    }
543
544
    /**
545
     * @group DDC-1376
546
     */
547
    public function testFindByOrderByAssociation()
548
    {
549
        $this->loadFixtureUserEmail();
550
551
        $repository = $this->em->getRepository(CmsUser::class);
552
        $resultAsc  = $repository->findBy([], ['email' => 'ASC']);
553
        $resultDesc = $repository->findBy([], ['email' => 'DESC']);
554
555
        self::assertCount(3, $resultAsc);
556
        self::assertCount(3, $resultDesc);
557
558
        self::assertEquals($resultAsc[0]->getEmail()->getId(), $resultDesc[2]->getEmail()->getId());
559
        self::assertEquals($resultAsc[2]->getEmail()->getId(), $resultDesc[0]->getEmail()->getId());
560
    }
561
562
    /**
563
     * @group DDC-1426
564
     */
565
    public function testFindFieldByMagicCallOrderBy()
566
    {
567
        $this->loadFixture();
568
        $repos = $this->em->getRepository(CmsUser::class);
569
570
        $usersAsc = $repos->findByStatus('dev', ['username' => "ASC"]);
0 ignored issues
show
Bug introduced by
The method findByStatus() does not exist on Doctrine\Common\Persistence\ObjectRepository. Did you maybe mean findBy()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
571
        $usersDesc = $repos->findByStatus('dev', ['username' => "DESC"]);
0 ignored issues
show
Bug introduced by
The method findByStatus() does not exist on Doctrine\Common\Persistence\ObjectRepository. Did you maybe mean findBy()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
572
573
        self::assertCount(2, $usersAsc);
574
        self::assertCount(2, $usersDesc);
575
576
        self::assertInstanceOf(CmsUser::class,$usersAsc[0]);
577
        self::assertEquals('Alexander', $usersAsc[0]->name);
578
        self::assertEquals('dev', $usersAsc[0]->status);
579
580
        self::assertSame($usersAsc[0], $usersDesc[1]);
581
        self::assertSame($usersAsc[1], $usersDesc[0]);
582
    }
583
584
    /**
585
     * @group DDC-1426
586
     */
587
    public function testFindFieldByMagicCallLimitOffset()
588
    {
589
        $this->loadFixture();
590
        $repos = $this->em->getRepository(CmsUser::class);
591
592
        $users1 = $repos->findByStatus('dev', [], 1, 0);
0 ignored issues
show
Bug introduced by
The method findByStatus() does not exist on Doctrine\Common\Persistence\ObjectRepository. Did you maybe mean findBy()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
593
        $users2 = $repos->findByStatus('dev', [], 1, 1);
0 ignored issues
show
Bug introduced by
The method findByStatus() does not exist on Doctrine\Common\Persistence\ObjectRepository. Did you maybe mean findBy()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
594
595
        self::assertCount(1, $users1);
596
        self::assertCount(1, $users2);
597
        self::assertNotSame($users1[0], $users2[0]);
598
    }
599
600
    /**
601
     * @group DDC-753
602
     */
603
    public function testDefaultRepositoryClassName()
604
    {
605
        self::assertEquals($this->em->getConfiguration()->getDefaultRepositoryClassName(), EntityRepository::class);
606
        $this->em->getConfiguration()->setDefaultRepositoryClassName(DDC753DefaultRepository::class);
607
        self::assertEquals($this->em->getConfiguration()->getDefaultRepositoryClassName(), DDC753DefaultRepository::class);
608
609
        $repos = $this->em->getRepository(DDC753EntityWithDefaultCustomRepository::class);
610
        self::assertInstanceOf(DDC753DefaultRepository::class, $repos);
611
        self::assertTrue($repos->isDefaultRepository());
612
613
614
        $repos = $this->em->getRepository(DDC753EntityWithCustomRepository::class);
615
        self::assertInstanceOf(DDC753CustomRepository::class, $repos);
616
        self::assertTrue($repos->isCustomRepository());
617
618
        self::assertEquals($this->em->getConfiguration()->getDefaultRepositoryClassName(), DDC753DefaultRepository::class);
619
        $this->em->getConfiguration()->setDefaultRepositoryClassName(EntityRepository::class);
620
        self::assertEquals($this->em->getConfiguration()->getDefaultRepositoryClassName(), EntityRepository::class);
621
622
    }
623
624
    /**
625
     * @group DDC-753
626
     * @expectedException Doctrine\ORM\ORMException
627
     * @expectedExceptionMessage Invalid repository class 'Doctrine\Tests\Models\DDC753\DDC753InvalidRepository'. It must be a Doctrine\Common\Persistence\ObjectRepository.
628
     */
629
    public function testSetDefaultRepositoryInvalidClassError()
630
    {
631
        self::assertEquals($this->em->getConfiguration()->getDefaultRepositoryClassName(), EntityRepository::class);
632
        $this->em->getConfiguration()->setDefaultRepositoryClassName(DDC753InvalidRepository::class);
633
    }
634
635
    /**
636
     * @group DDC-3257
637
     */
638
    public function testCanRetrieveRepositoryFromClassNameWithLeadingBackslash()
639
    {
640
        self::assertSame(
641
            $this->em->getRepository('\\' . CmsUser::class),
642
            $this->em->getRepository(CmsUser::class)
643
        );
644
    }
645
646
    /**
647
     * @group DDC-1376
648
     *
649
     * @expectedException Doctrine\ORM\ORMException
650
     * @expectedExceptionMessage You cannot search for the association field 'Doctrine\Tests\Models\CMS\CmsUser#address', because it is the inverse side of an association.
651
     */
652
    public function testInvalidOrderByAssociation()
653
    {
654
        $this->em->getRepository(CmsUser::class)
655
            ->findBy(['status' => 'test'], ['address' => 'ASC']);
656
    }
657
658
    /**
659
     * @group DDC-1500
660
     */
661 View Code Duplication
    public function testInvalidOrientation()
662
    {
663
        $this->expectException(ORMException::class);
664
        $this->expectExceptionMessage('Invalid order by orientation specified for Doctrine\Tests\Models\CMS\CmsUser#username');
665
666
        $repo = $this->em->getRepository(CmsUser::class);
667
        $repo->findBy(['status' => 'test'], ['username' => 'INVALID']);
668
    }
669
670
    /**
671
     * @group DDC-1713
672
     */
673
    public function testFindByAssociationArray()
674
    {
675
        $repo = $this->em->getRepository(CmsAddress::class);
676
        $data = $repo->findBy(['user' => [1, 2, 3]]);
0 ignored issues
show
Unused Code introduced by
$data is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
677
678
        $query = array_pop($this->sqlLoggerStack->queries);
679
        self::assertEquals([1,2,3], $query['params'][0]);
680
        self::assertEquals(Connection::PARAM_INT_ARRAY, $query['types'][0]);
681
    }
682
683
    /**
684
     * @group DDC-1637
685
     */
686 View Code Duplication
    public function testMatchingEmptyCriteria()
687
    {
688
        $this->loadFixture();
689
690
        $repository = $this->em->getRepository(CmsUser::class);
691
        $users = $repository->matching(new Criteria());
692
693
        self::assertCount(4, $users);
694
    }
695
696
    /**
697
     * @group DDC-1637
698
     */
699 View Code Duplication
    public function testMatchingCriteriaEqComparison()
700
    {
701
        $this->loadFixture();
702
703
        $repository = $this->em->getRepository(CmsUser::class);
704
        $users = $repository->matching(new Criteria(
705
            Criteria::expr()->eq('username', 'beberlei')
706
        ));
707
708
        self::assertCount(1, $users);
709
    }
710
711
    /**
712
     * @group DDC-1637
713
     */
714 View Code Duplication
    public function testMatchingCriteriaNeqComparison()
715
    {
716
        $this->loadFixture();
717
718
        $repository = $this->em->getRepository(CmsUser::class);
719
        $users = $repository->matching(new Criteria(
720
            Criteria::expr()->neq('username', 'beberlei')
721
        ));
722
723
        self::assertCount(3, $users);
724
    }
725
726
    /**
727
     * @group DDC-1637
728
     */
729 View Code Duplication
    public function testMatchingCriteriaInComparison()
730
    {
731
        $this->loadFixture();
732
733
        $repository = $this->em->getRepository(CmsUser::class);
734
        $users = $repository->matching(new Criteria(
735
            Criteria::expr()->in('username', ['beberlei', 'gblanco'])
736
        ));
737
738
        self::assertCount(2, $users);
739
    }
740
741
    /**
742
     * @group DDC-1637
743
     */
744 View Code Duplication
    public function testMatchingCriteriaNotInComparison()
745
    {
746
        $this->loadFixture();
747
748
        $repository = $this->em->getRepository(CmsUser::class);
749
        $users = $repository->matching(new Criteria(
750
            Criteria::expr()->notIn('username', ['beberlei', 'gblanco', 'asm89'])
751
        ));
752
753
        self::assertCount(1, $users);
754
    }
755
756
    /**
757
     * @group DDC-1637
758
     */
759
    public function testMatchingCriteriaLtComparison()
760
    {
761
        $firstUserId = $this->loadFixture();
762
763
        $repository = $this->em->getRepository(CmsUser::class);
764
        $users = $repository->matching(new Criteria(
765
            Criteria::expr()->lt('id', $firstUserId + 1)
766
        ));
767
768
        self::assertCount(1, $users);
769
    }
770
771
    /**
772
     * @group DDC-1637
773
     */
774
    public function testMatchingCriteriaLeComparison()
775
    {
776
        $firstUserId = $this->loadFixture();
777
778
        $repository = $this->em->getRepository(CmsUser::class);
779
        $users = $repository->matching(new Criteria(
780
            Criteria::expr()->lte('id', $firstUserId + 1)
781
        ));
782
783
        self::assertCount(2, $users);
784
    }
785
786
    /**
787
     * @group DDC-1637
788
     */
789 View Code Duplication
    public function testMatchingCriteriaGtComparison()
790
    {
791
        $firstUserId = $this->loadFixture();
792
793
        $repository = $this->em->getRepository(CmsUser::class);
794
        $users = $repository->matching(new Criteria(
795
            Criteria::expr()->gt('id', $firstUserId)
796
        ));
797
798
        self::assertCount(3, $users);
799
    }
800
801
    /**
802
     * @group DDC-1637
803
     */
804 View Code Duplication
    public function testMatchingCriteriaGteComparison()
805
    {
806
        $firstUserId = $this->loadFixture();
807
808
        $repository = $this->em->getRepository(CmsUser::class);
809
        $users = $repository->matching(new Criteria(
810
            Criteria::expr()->gte('id', $firstUserId)
811
        ));
812
813
        self::assertCount(4, $users);
814
    }
815
816
    /**
817
     * @group DDC-2430
818
     */
819 View Code Duplication
    public function testMatchingCriteriaAssocationByObjectInMemory()
820
    {
821
        list($userId, $addressId) = $this->loadAssociatedFixture();
0 ignored issues
show
Unused Code introduced by
The assignment to $addressId is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
822
823
        $user = $this->em->find(CmsUser::class, $userId);
824
825
        $criteria = new Criteria(
826
            Criteria::expr()->eq('user', $user)
827
        );
828
829
        $repository = $this->em->getRepository(CmsAddress::class);
830
        $addresses = $repository->matching($criteria);
831
832
        self::assertCount(1, $addresses);
833
834
        $addresses = new ArrayCollection($repository->findAll());
835
836
        self::assertCount(1, $addresses->matching($criteria));
837
    }
838
839
    /**
840
     * @group DDC-2430
841
     */
842 View Code Duplication
    public function testMatchingCriteriaAssocationInWithArray()
843
    {
844
        list($userId, $addressId) = $this->loadAssociatedFixture();
0 ignored issues
show
Unused Code introduced by
The assignment to $addressId is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
845
846
        $user = $this->em->find(CmsUser::class, $userId);
847
848
        $criteria = new Criteria(
849
            Criteria::expr()->in('user', [$user])
850
        );
851
852
        $repository = $this->em->getRepository(CmsAddress::class);
853
        $addresses = $repository->matching($criteria);
854
855
        self::assertCount(1, $addresses);
856
857
        $addresses = new ArrayCollection($repository->findAll());
858
859
        self::assertCount(1, $addresses->matching($criteria));
860
    }
861
862 View Code Duplication
    public function testMatchingCriteriaContainsComparison()
863
    {
864
        $this->loadFixture();
865
866
        $repository = $this->em->getRepository(CmsUser::class);
867
868
        $users = $repository->matching(new Criteria(Criteria::expr()->contains('name', 'Foobar')));
869
        self::assertCount(0, $users);
870
871
        $users = $repository->matching(new Criteria(Criteria::expr()->contains('name', 'Rom')));
872
        self::assertCount(1, $users);
873
874
        $users = $repository->matching(new Criteria(Criteria::expr()->contains('status', 'dev')));
875
        self::assertCount(2, $users);
876
    }
877
878 View Code Duplication
    public function testMatchingCriteriaStartsWithComparison()
879
    {
880
        $this->loadFixture();
881
882
        $repository = $this->em->getRepository(CmsUser::class);
883
884
        $users = $repository->matching(new Criteria(Criteria::expr()->startsWith('name', 'Foo')));
885
        self::assertCount(0, $users);
886
887
        $users = $repository->matching(new Criteria(Criteria::expr()->startsWith('name', 'R')));
888
        self::assertCount(1, $users);
889
890
        $users = $repository->matching(new Criteria(Criteria::expr()->startsWith('status', 'de')));
891
        self::assertCount(2, $users);
892
    }
893
894 View Code Duplication
    public function testMatchingCriteriaEndsWithComparison()
895
    {
896
        $this->loadFixture();
897
898
        $repository = $this->em->getRepository(CmsUser::class);
899
900
        $users = $repository->matching(new Criteria(Criteria::expr()->endsWith('name', 'foo')));
901
        self::assertCount(0, $users);
902
903
        $users = $repository->matching(new Criteria(Criteria::expr()->endsWith('name', 'oman')));
904
        self::assertCount(1, $users);
905
906
        $users = $repository->matching(new Criteria(Criteria::expr()->endsWith('status', 'ev')));
907
        self::assertCount(2, $users);
908
    }
909
910
    /**
911
     * @group DDC-2478
912
     */
913
    public function testMatchingCriteriaNullAssocComparison()
914
    {
915
        $fixtures       = $this->loadFixtureUserEmail();
916
        $user           = $this->em->find(get_class($fixtures[0]), $fixtures[0]->id);
917
        $repository     = $this->em->getRepository(CmsUser::class);
918
        $criteriaIsNull = Criteria::create()->where(Criteria::expr()->isNull('email'));
919
        $criteriaEqNull = Criteria::create()->where(Criteria::expr()->eq('email', null));
920
921
        $user->setEmail(null);
922
        $this->em->flush();
923
        $this->em->clear();
924
925
        $usersIsNull = $repository->matching($criteriaIsNull);
926
        $usersEqNull = $repository->matching($criteriaEqNull);
927
928
        self::assertCount(1, $usersIsNull);
929
        self::assertCount(1, $usersEqNull);
930
931
        self::assertInstanceOf(CmsUser::class, $usersIsNull[0]);
932
        self::assertInstanceOf(CmsUser::class, $usersEqNull[0]);
933
934
        self::assertNull($usersIsNull[0]->getEmail());
935
        self::assertNull($usersEqNull[0]->getEmail());
936
    }
937
938
    /**
939
     * @group DDC-2055
940
     */
941
    public function testCreateResultSetMappingBuilder()
942
    {
943
        $repository = $this->em->getRepository(CmsUser::class);
944
        $rsm = $repository->createResultSetMappingBuilder('u');
945
946
        self::assertInstanceOf(Query\ResultSetMappingBuilder::class, $rsm);
947
        self::assertEquals(['u' => CmsUser::class], $rsm->aliasMap);
948
    }
949
950
    /**
951
     * @group DDC-3045
952
     */
953 View Code Duplication
    public function testFindByFieldInjectionPrevented()
954
    {
955
        $this->expectException(ORMException::class);
956
        $this->expectExceptionMessage('Unrecognized field: ');
957
958
        $repository = $this->em->getRepository(CmsUser::class);
959
        $repository->findBy(['username = ?; DELETE FROM cms_users; SELECT 1 WHERE 1' => 'test']);
960
    }
961
962
    /**
963
     * @group DDC-3045
964
     */
965 View Code Duplication
    public function testFindOneByFieldInjectionPrevented()
966
    {
967
        $this->expectException(ORMException::class);
968
        $this->expectExceptionMessage('Unrecognized field: ');
969
970
        $repository = $this->em->getRepository(CmsUser::class);
971
        $repository->findOneBy(['username = ?; DELETE FROM cms_users; SELECT 1 WHERE 1' => 'test']);
972
    }
973
974
    /**
975
     * @group DDC-3045
976
     */
977
    public function testMatchingInjectionPrevented()
978
    {
979
        $this->expectException(ORMException::class);
980
        $this->expectExceptionMessage('Unrecognized field: ');
981
982
        $repository = $this->em->getRepository(CmsUser::class);
983
        $result     = $repository->matching(new Criteria(
984
            Criteria::expr()->eq('username = ?; DELETE FROM cms_users; SELECT 1 WHERE 1', 'beberlei')
985
        ));
986
987
        // Because repository returns a lazy collection, we call toArray to force initialization
988
        $result->toArray();
989
    }
990
991
    /**
992
     * @group DDC-3045
993
     */
994 View Code Duplication
    public function testFindInjectionPrevented()
995
    {
996
        $this->expectException(ORMException::class);
997
        $this->expectExceptionMessage('Unrecognized identifier fields: ');
998
999
        $repository = $this->em->getRepository(CmsUser::class);
1000
        $repository->find(['username = ?; DELETE FROM cms_users; SELECT 1 WHERE 1' => 'test', 'id' => 1]);
1001
    }
1002
1003
    /**
1004
     * @group DDC-3056
1005
     */
1006 View Code Duplication
    public function testFindByNullValueInInCondition()
1007
    {
1008
        $user1 = new CmsUser();
1009
        $user2 = new CmsUser();
1010
1011
        $user1->username = 'ocramius';
1012
        $user1->name = 'Marco';
1013
        $user2->status = null;
1014
        $user2->username = 'deeky666';
1015
        $user2->name = 'Steve';
1016
        $user2->status = 'dbal maintainer';
1017
1018
        $this->em->persist($user1);
1019
        $this->em->persist($user2);
1020
        $this->em->flush();
1021
1022
        $users = $this->em->getRepository(CmsUser::class)->findBy(['status' => [null]]);
1023
1024
        self::assertCount(1, $users);
1025
        self::assertSame($user1, reset($users));
1026
    }
1027
1028
    /**
1029
     * @group DDC-3056
1030
     */
1031 View Code Duplication
    public function testFindByNullValueInMultipleInCriteriaValues()
1032
    {
1033
        $user1 = new CmsUser();
1034
        $user2 = new CmsUser();
1035
1036
        $user1->username = 'ocramius';
1037
        $user1->name = 'Marco';
1038
        $user2->status = null;
1039
        $user2->username = 'deeky666';
1040
        $user2->name = 'Steve';
1041
        $user2->status = 'dbal maintainer';
1042
1043
        $this->em->persist($user1);
1044
        $this->em->persist($user2);
1045
        $this->em->flush();
1046
1047
        $users = $this
1048
            ->em
1049
            ->getRepository(CmsUser::class)
1050
            ->findBy(['status' => ['foo', null]]);
1051
1052
        self::assertCount(1, $users);
1053
        self::assertSame($user1, reset($users));
1054
    }
1055
1056
    /**
1057
     * @group DDC-3056
1058
     */
1059
    public function testFindMultipleByNullValueInMultipleInCriteriaValues()
1060
    {
1061
        $user1 = new CmsUser();
1062
        $user2 = new CmsUser();
1063
1064
        $user1->username = 'ocramius';
1065
        $user1->name = 'Marco';
1066
        $user2->status = null;
1067
        $user2->username = 'deeky666';
1068
        $user2->name = 'Steve';
1069
        $user2->status = 'dbal maintainer';
1070
1071
        $this->em->persist($user1);
1072
        $this->em->persist($user2);
1073
        $this->em->flush();
1074
1075
        $users = $this
1076
            ->em
1077
            ->getRepository(CmsUser::class)
1078
            ->findBy(['status' => ['dbal maintainer', null]]);
1079
1080
        self::assertCount(2, $users);
1081
1082
        foreach ($users as $user) {
1083
            self::assertContains($user, [$user1, $user2]);
1084
        }
1085
    }
1086
}
1087