UserRepositoryTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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