ModuleHandlerTest::setUp()   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
class ModuleHandlerIntranet
3
{
4
    function hasModuleAccess()
5
    {
6
        return true;
7
    }
8
}
9
10
class ModuleHandlerTest extends PHPUnit_Framework_TestCase
11
{
12
    private $handler;
13
14
    function setUp()
15
    {
16
        $this->handler = new Intraface_ModuleHandler(new ModuleHandlerIntranet);
0 ignored issues
show
Documentation introduced by
new \ModuleHandlerIntranet() is of type object<ModuleHandlerIntranet>, 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...
17
    }
18
19
    function testUseModuleThrowsAnExceptionIfTheModuleIsNotValid()
20
    {
21
        try {
22
            $this->handler->useModule('invalid module name');
23
            $this->assertTrue(false, 'Exception should have been thrown');
24
        } catch (Exception $e) {
25
            $this->assertTrue(true);
26
        }
27
    }
28
29
    function testSetPrimaryModuleThrowsAnExceptionWhenNoIntranetIsset()
30
    {
31
        try {
32
            $this->handler->setPrimaryModule('intranetmaintenance');
33
            $this->assertFalse(true, 'Should have thrown an exception');
34
        } catch (Exception $e) {
35
            $this->assertTrue(true);
36
        }
37
    }
38
39
    function testUseModuleReturnsTheModuleAsAnObjectTrueWhenModuleIsAvailable()
40
    {
41
        $this->assertTrue(is_object($module = $this->handler->useModule('intranetmaintenance')));
42
        $this->assertEquals('intranetmaintenance', $module->getName());
43
    }
44
45
    function testGetModule()
46
    {
47
        $this->assertTrue(is_object($this->handler->useModule('intranetmaintenance')));
48
        $this->assertTrue(is_object($module = $this->handler->getModule('intranetmaintenance')));
49
        $this->assertEquals('intranetmaintenance', $module->getName());
50
    }
51
52
    function testGetModules()
53
    {
54
        $db = MDB2::singleton(DB_DSN);
55
        $result = $db->query('SELECT * FROM module');
56
        if (PEAR::isError($result)) {
57
            die($result->getMessage() . $result->getUserInfo());
0 ignored issues
show
Coding Style Compatibility introduced by
The method testGetModules() 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...
58
        }
59
60
        $this->assertTrue(is_array($this->handler->getModules(MDB2::singleton(DB_DSN))));
61
        $this->assertEquals($result->numRows(), count($this->handler->getModules(MDB2::singleton(DB_DSN))));
62
    }
63
}
64