CSessionTest::testGetSetHas()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 11
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 17
rs 9.4285
1
<?php
2
3
namespace Anax\Request;
4
5
/**
6
 * Testing framework session class.
7
 *
8
 */
9
class CSessionTest extends \PHPUnit_Framework_TestCase
10
{
11
    /**
12
     * Test 
13
     *
14
     * @return void
15
     *
16
     */
17
    public function testLoadConfig()
18
    {
19
        $session = new \Anax\Session\CSession();
20
        $session->configure(ANAX_APP_PATH . 'config/session.php');
21
    }
22
23
24
25
    /**
26
     * Test 
27
     *
28
     * @return void
29
     *
30
     */
31
    public function testSetName()
32
    {
33
        $session = new \Anax\Session\CSession();
34
        $name = "someName";
35
36
        $session->name($name);
0 ignored issues
show
Documentation introduced by
$name is of type string, but the function expects a array|null.

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...
37
38
        $this->assertEquals($name, session_name(), "Session name does not match.");
39
    }
40
41
42
43
    /**
44
     * Test 
45
     *
46
     * @return void
47
     *
48
     */
49
    public function testGetSetHas()
50
    {
51
        $session = new \Anax\Session\CSession();
52
53
        $ret = $session->has('key');
54
        $this->assertFalse($ret, "Session should not have this entry.");
55
56
        $ret = $session->get('key');
57
        $this->assertNull($ret, "Session should return null for this entry.");
58
59
        $ret = $session->set('key', 'value');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $ret is correct as $session->set('key', 'value') (which targets Anax\Session\CSession::set()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$ret is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
60
        $ret = $session->has('key');
61
        $this->assertTrue($ret, "Session should have this entry.");
62
63
        $ret = $session->get('key');
64
        $this->assertEquals($ret, 'value', "Session should have a value for this entry.");
65
    }
66
}
67