UserRepositoryTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 12
c 0
b 0
f 0
dl 0
loc 22
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetLoginPassword() 0 12 1
A setUp() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApplicationTest\Repository;
6
7
use Application\Enum\Site;
8
use Application\Model\User;
9
use Application\Repository\UserRepository;
10
11
class UserRepositoryTest extends AbstractRepositoryTest
12
{
13
    private UserRepository $repository;
14
15
    protected function setUp(): void
16
    {
17
        parent::setUp();
18
        $this->repository = _em()->getRepository(User::class);
19
    }
20
21
    public function testGetLoginPassword(): void
22
    {
23
        self::assertNull($this->repository->getLoginPassword('foo', 'bar', Site::Dilps), 'wrong user');
24
        self::assertNull($this->repository->getLoginPassword('administrator', 'bar', Site::Dilps), 'wrong password');
25
26
        $user = $this->repository->getLoginPassword('administrator', 'administrator', Site::Dilps);
27
        self::assertNotNull($user);
28
        self::assertSame(1000, $user->getId());
29
30
        $hash = _em()->getConnection()->executeQuery('SELECT password FROM `user` WHERE id = 1000')->fetchOne();
31
        self::assertStringStartsWith('$', $hash, 'password should have been re-hashed automatically');
32
        self::assertNotSame(md5('administrator'), $hash, 'password should have been re-hashed automatically');
33
    }
34
}
35