Passed
Push — master ( edb799...f409da )
by Petr
07:56
created

SequenceMock   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 5
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
wmc 1
1
<?php
2
3
namespace ProtocolsTests\Fsp;
4
5
6
use CommonTestClass;
7
use kalanis\RemoteRequest\Protocols\Fsp;
8
use kalanis\RemoteRequest\RequestException;
9
use kalanis\RemoteRequest\Translations;
10
11
12
class SequenceMock extends Fsp\Session\Sequence
13
{
14
    protected function getRandInitial(): int
15
    {
16
        return 75;
17
    }
18
}
19
20
21
class SessionMock extends Fsp\Session
22
{
23
    protected function getRandInitial(): int
24
    {
25
        return 64;
26
    }
27
28
    protected function sequencer($withInit = true): Fsp\Session\Sequence
29
    {
30
        $lib = new SequenceMock($this->lang);
31
        if ($withInit) {
32
            $lib->generateSequence();
33
        }
34
        return $lib;
35
    }
36
}
37
38
39
class SessionTest extends CommonTestClass
40
{
41
    /**
42
     * @throws RequestException
43
     */
44
    public function testSeqPass(): void
45
    {
46
        $mock = SequenceMock::newSequence(new Translations());
47
        $this->assertEquals(75, $mock->getKey());
48
        $mock->checkSequence(75);
49
        $mock->updateSequence();
50
    }
51
52
    /**
53
     * @throws RequestException
54
     */
55
    public function testSeqFail(): void
56
    {
57
        $mock = new SequenceMock(new Translations());
58
        $this->expectException(RequestException::class);
59
        $mock->checkSequence(75);
60
    }
61
62
    /**
63
     * @throws RequestException
64
     */
65
    public function testKeyNone(): void
66
    {
67
        $mock = new SessionMock(new Translations());
68
        $this->assertFalse($mock->hasKey());
69
    }
70
71
    /**
72
     * @throws RequestException
73
     */
74
    public function testKeyFail(): void
75
    {
76
        $mock = new SessionMock(new Translations());
77
        $this->expectException(RequestException::class);
78
        $mock->getKey();
79
    }
80
81
    /**
82
     * @throws RequestException
83
     */
84
    public function testSequenceFail(): void
85
    {
86
        $mock = new SessionMock(new Translations());
87
        $this->expectException(RequestException::class);
88
        $mock->getSequence();
89
    }
90
91
    /**
92
     * @throws RequestException
93
     */
94
    public function testKeyNotFound(): void
95
    {
96
        $mock = new SessionMock(new Translations());
97
        $mock->setHost('asdf');
98
        $this->assertFalse($mock->hasKey());
99
    }
100
101
    /**
102
     * @throws RequestException
103
     */
104
    public function testKeyFound(): void
105
    {
106
        $mock = new SessionMock(new Translations());
107
        $mock->setHost('asdf');
108
        $this->assertEquals(64, $mock->getKey());
109
        $mock->setKey(37);
110
        $this->assertEquals(37, $mock->getKey());
111
        $mock->clear();
112
        $mock->clear();
113
    }
114
115
    /**
116
     * @throws RequestException
117
     */
118
    public function testSequenceFound(): void
119
    {
120
        $mock = new SessionMock(new Translations());
121
        $mock->clear();
122
        $mock->setHost('asdf');
123
        $this->assertEquals(75, $mock->getSequence());
124
        $mock->updateSequence(75);
125
        $mock->clear();
126
127
    }
128
129
    /**
130
     * @throws RequestException
131
     */
132
    public function testSequenceNotSet(): void
133
    {
134
        $mock = new SessionMock(new Translations());
135
        $mock->clear();
136
        $mock->setHost('asdf');
137
        $this->expectException(RequestException::class);
138
        $mock->updateSequence(94);
139
    }
140
141
    /**
142
     * @throws RequestException
143
     */
144
    public function testSequences(): void
145
    {
146
        $mock = new SessionMock(new Translations());
147
        $mock->clear();
148
        $mock->setHost('asdf');
149
        $this->assertEquals(75, $mock->getSequence());
150
        $mock->setHost('poiu');
151
        $this->assertEquals(75, $mock->getSequence());
152
        $mock->setHost('asdf');
153
        $mock->clear();
154
        $mock->setHost('poiu');
155
        $this->assertEquals(64, $mock->getKey());
156
        $mock->clear();
157
        $mock->clear();
158
    }
159
}
160