ParameterTest::tearDown()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
require_once 'CMSStubs.php';
3
require_once 'Intraface/Kernel.php';
4
require_once 'Intraface/modules/cms/Parameter.php';
5
6
class FakeObjectToPutIntoParameter
7
{
8
    public $kernel;
9
10
    function __construct()
11
    {
12
        $this->kernel = new Stub_Kernel;
13
    }
14
15
    function get($type)
16
    {
17
        switch ($type) {
18
            case 'identify_as':
19
                return 'cms_element';
20
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
21
            default:
22
                return 1;
23
                exit;
0 ignored issues
show
Unused Code introduced by
die; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
Coding Style Compatibility introduced by
The method get() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
24
        }
25
    }
26
}
27
28
class ParameterTest extends PHPUnit_Framework_TestCase
29
{
30
    protected $db;
31
32
    function setUp()
33
    {
34
        $this->db = MDB2::singleton(DB_DSN);
35
        $this->parameter = $this->createParameter();
0 ignored issues
show
Bug introduced by
The property parameter does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
36
    }
37
38
    function tearDown()
39
    {
40
        $this->db->exec('TRUNCATE cms_parameter');
41
    }
42
43
    function createParameter()
44
    {
45
        return new CMS_Parameter(new FakeObjectToPutIntoParameter);
46
    }
47
48
    function testConstruction()
49
    {
50
        $this->assertTrue(is_object($this->parameter));
51
    }
52
53
    function testSaveSavesValuesAndTheyCanBeGottenRightAway()
54
    {
55
        $parameter = 'parameter';
56
        $value = 'value';
57
        $this->assertTrue($this->parameter->save($parameter, $value));
58
        $this->assertEquals($value, $this->parameter->get($parameter));
59
    }
60
61
    function testSaveActuallyPersistsValuesForLaterUsage()
62
    {
63
        $parameter = 'parameter';
64
        $value = 'value';
65
        $this->assertTrue($this->parameter->save($parameter, $value));
66
        $this->assertEquals($value, $this->parameter->get($parameter));
67
68
        $p = $this->createParameter();
69
        $this->assertEquals($value, $p->get($parameter));
70
    }
71
}
72