Passed
Push — master ( b28c40...f61e74 )
by Petr
08:06
created

BasicTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
eloc 18
c 3
b 0
f 1
dl 0
loc 39
rs 10
wmc 3
1
<?php
2
3
namespace MethodsTests;
4
5
6
use CommonTestClass;
7
use kalanis\kw_auth\AuthException;
8
use kalanis\kw_auth\Methods;
9
use kalanis\kw_locks\LockException;
10
11
12
class BasicTest extends CommonTestClass
13
{
14
    /**
15
     * @throws AuthException
16
     * @throws LockException
17
     */
18
    public function testUser(): void
19
    {
20
        $method = new MockMethod(new \MockAuth(), null);
21
        $this->assertFalse($method->isAuthorized());
22
        $this->assertEmpty($method->getLoggedUser());
23
        $this->assertEmpty($method->getNextMethod());
24
        $method->process(new \MockCredentials());
25
        $this->assertTrue($method->isAuthorized());
26
        $this->assertNotEmpty($method->getLoggedUser());
27
        $this->assertEquals('Testing', $method->getLoggedUser()->getAuthName());
28
        $this->assertEmpty($method->getNextMethod());
29
    }
30
31
    /**
32
     * @param int $when
33
     * @param int $length
34
     * @param bool $pass
35
     * @dataProvider stampsProvider
36
     */
37
    public function testStamps(int $when, int $length, bool $pass): void
38
    {
39
        $lib = new MockStamp();
40
        $lib->setDiff($length);
41
        $this->assertEquals($pass, $lib->checkTime($when));
42
    }
43
44
    public function stampsProvider(): array
45
    {
46
        return [
47
            [ time() + 10, 20, true],
48
            [ time() - 10, 20, true],
49
            [ time() + 50, 20, false],
50
            [ time() - 50, 20, false],
51
        ];
52
    }
53
}
54
55
56
class MockMethod extends Methods\AMethods
57
{
58
    public function process(\ArrayAccess $credentials): void
59
    {
60
        $this->loggedUser = new \MockUserToFill(
61
            0,
62
            'Testing',
63
            0,
64
            9999,
65
            null,
66
            'Testing',
67
            'not_available\\:///'
68
        );
69
    }
70
71
    public function remove(): void
72
    {
73
    }
74
}
75
76
77
class MockStamp
78
{
79
    use Methods\TStamp;
80
81
    public function setDiff(int $timeDiff): void
82
    {
83
        $this->initStamp($timeDiff);
84
    }
85
86
    public function checkTime(int $time): bool
87
    {
88
        return $this->checkStamp($time);
89
    }
90
}
91