LogRepositoryTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 24
dl 0
loc 48
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testLoginFailedOften() 0 14 2
A testUpdatePasswordFailedOften() 0 14 2
A testDeleteOldLogs() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApplicationTest\Repository;
6
7
use Application\Model\Log;
8
use Application\Repository\LogRepository;
9
10
class LogRepositoryTest extends AbstractRepositoryTest
11
{
12
    private LogRepository $repository;
13
14
    protected function setUp(): void
15
    {
16
        parent::setUp();
17
        $this->repository = _em()->getRepository(Log::class);
18
    }
19
20
    public function testLoginFailedOften(): void
21
    {
22
        $this->getEntityManager()->getConnection()->executeStatement('DELETE FROM log');
23
        _log()->info(LogRepository::LOGIN_FAILED);
24
25
        $result = $this->repository->loginFailedOften();
26
        self::assertFalse($result);
27
28
        foreach (range(1, 20) as $i) {
29
            _log()->info(LogRepository::LOGIN_FAILED);
30
        }
31
32
        $result = $this->repository->loginFailedOften();
33
        self::assertTrue($result, 'is your PHP date.timezone setting correct ?');
34
    }
35
36
    public function testUpdatePasswordFailedOften(): void
37
    {
38
        $this->getEntityManager()->getConnection()->executeStatement('DELETE FROM log');
39
        _log()->info(LogRepository::UPDATE_PASSWORD_FAILED);
40
41
        $result = $this->repository->updatePasswordFailedOften();
42
        self::assertFalse($result);
43
44
        foreach (range(1, 20) as $i) {
45
            _log()->info(LogRepository::UPDATE_PASSWORD_FAILED);
46
        }
47
48
        $result = $this->repository->updatePasswordFailedOften();
49
        self::assertTrue($result, 'is your PHP date.timezone setting correct ?');
50
    }
51
52
    public function testDeleteOldLogs(): void
53
    {
54
        _em()->rollBack();
55
        $result = $this->repository->deleteOldLogs();
56
        _em()->beginTransaction();
57
        self::assertSame(0, $result);
58
    }
59
}
60