1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ApplicationTest\Repository; |
6
|
|
|
|
7
|
|
|
use Application\Model\User; |
8
|
|
|
use Application\Repository\UserRepository; |
9
|
|
|
use ApplicationTest\Traits\LimitedAccessSubQuery; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @group Repository |
13
|
|
|
*/ |
14
|
|
|
class UserRepositoryTest extends AbstractRepositoryTest |
15
|
|
|
{ |
16
|
|
|
use LimitedAccessSubQuery; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var UserRepository |
20
|
|
|
*/ |
21
|
|
|
private $repository; |
22
|
|
|
|
23
|
|
|
protected function setUp(): void |
24
|
|
|
{ |
25
|
|
|
parent::setUp(); |
26
|
|
|
$this->repository = _em()->getRepository(User::class); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function providerGetAccessibleSubQuery(): array |
30
|
|
|
{ |
31
|
|
|
$all = [1000, 1001, 1002, 1003]; |
32
|
|
|
|
33
|
|
|
return [ |
34
|
|
|
['anonymous', [1001]], |
35
|
|
|
['member', $all], |
36
|
|
|
['facilitator', $all], |
37
|
|
|
['administrator', $all], |
38
|
|
|
]; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testGetOneByEmailPassword(): void |
42
|
|
|
{ |
43
|
|
|
self::assertNull($this->repository->getOneByEmailPassword('[email protected]', 'bar'), 'wrong user'); |
44
|
|
|
self::assertNull($this->repository->getOneByEmailPassword('[email protected]', 'bar'), 'wrong password'); |
45
|
|
|
|
46
|
|
|
$user = $this->repository->getOneByEmailPassword('[email protected]', 'administrator'); |
47
|
|
|
self::assertNotNull($user); |
48
|
|
|
self::assertSame(1000, $user->getId()); |
49
|
|
|
|
50
|
|
|
$hash = _em()->getConnection()->query('SELECT password FROM `user` WHERE id = 1000')->fetchColumn(); |
|
|
|
|
51
|
|
|
self::assertStringStartsWith('$', $hash, 'password should have been re-hashed automatically'); |
|
|
|
|
52
|
|
|
self::assertNotSame(md5('administrator'), $hash, 'password should have been re-hashed automatically'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testGetOneById(): void |
56
|
|
|
{ |
57
|
|
|
self::assertNull($this->repository->getOneById(1), 'wrong user'); |
58
|
|
|
|
59
|
|
|
$user = $this->repository->getOneById(1000); |
60
|
|
|
self::assertNotNull($user); |
61
|
|
|
self::assertSame(1000, $user->getId()); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.