SessionTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 2
dl 0
loc 78
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testCorrectInterfaceKeyValuePair() 0 6 1
A testCorrectInterfaceRegeneratable() 0 6 1
A testSet() 0 6 1
A testGetValid() 0 7 1
A testIsKeyValidFail() 0 6 1
A testIsKeyValidSuccess() 0 7 1
A testGetInvalid() 0 7 1
1
<?php
2
3
namespace OpCacheGUITest\Unit\Storage;
4
5
use OpCacheGUI\Storage\InvalidKeyException;
6
use OpCacheGUI\Storage\KeyValuePair;
7
use OpCacheGUI\Storage\Regeneratable;
8
use OpCacheGUI\Storage\Session;
9
use PHPUnit\Framework\TestCase;
10
11
class SessionTest extends TestCase
12
{
13
    /**
14
     */
15
    public function testCorrectInterfaceKeyValuePair()
16
    {
17
        $session = new Session();
18
19
        $this->assertInstanceOf(KeyValuePair::class, $session);
20
    }
21
22
    /**
23
     */
24
    public function testCorrectInterfaceRegeneratable()
25
    {
26
        $session = new Session();
27
28
        $this->assertInstanceOf(Regeneratable::class, $session);
29
    }
30
31
    /**
32
     * @covers OpCacheGUI\Storage\Session::set
33
     */
34
    public function testSet()
35
    {
36
        $session = new Session();
37
38
        $this->assertNull($session->set('key', 'value'));
39
    }
40
41
    /**
42
     * @covers OpCacheGUI\Storage\Session::set
43
     * @covers OpCacheGUI\Storage\Session::isKeyValid
44
     * @covers OpCacheGUI\Storage\Session::get
45
     */
46
    public function testGetValid()
47
    {
48
        $session = new Session();
49
        $session->set('key', 'value');
50
51
        $this->assertSame('value', $session->get('key'));
52
    }
53
54
    /**
55
     * @covers OpCacheGUI\Storage\Session::set
56
     * @covers OpCacheGUI\Storage\Session::isKeyValid
57
     * @covers OpCacheGUI\Storage\Session::get
58
     */
59
    public function testGetInvalid()
60
    {
61
        $session = new Session();
62
        $this->expectException(InvalidKeyException::class);
63
64
        $session->get('key');
65
    }
66
67
    /**
68
     * @covers OpCacheGUI\Storage\Session::isKeyValid
69
     */
70
    public function testIsKeyValidFail()
71
    {
72
        $session = new Session();
73
74
        $this->assertFalse(false, $session->isKeyValid('unknownkey'));
0 ignored issues
show
Documentation introduced by
$session->isKeyValid('unknownkey') is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
75
    }
76
77
    /**
78
     * @covers OpCacheGUI\Storage\Session::set
79
     * @covers OpCacheGUI\Storage\Session::isKeyValid
80
     */
81
    public function testIsKeyValidSuccess()
82
    {
83
        $session = new Session();
84
        $session->set('key', 'value');
85
86
        $this->assertTrue($session->isKeyValid('key'));
87
    }
88
}
89