AppendFileTest   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 85
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 4

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A createAppendFile() 0 5 1
A testConstruction() 0 5 1
A testAddFileAsInteger() 0 5 1
A testAddFilesAsArray() 0 5 1
A testDeleteReturnsTrue() 0 6 1
A testUnDeleteReturnsTrue() 0 7 1
A testCreateDBQuery() 0 7 1
B testGetList() 0 27 1
1
<?php
2
require_once 'Intraface/Standard.php';
3
require_once 'Intraface/Kernel.php';
4
require_once 'Intraface/modules/filemanager/FileHandler.php';
5
require_once 'Intraface/modules/filemanager/AppendFile.php';
6
require_once 'file_functions.php';
7
8
class FakeFileHandler
9
{
10
    function get()
11
    {
12
        return 1;
13
    }
14
}
15
16
class FakeAppendFileFile
17
{
18
19
    public $id;
20
    function __construct($id = 1)
21
    {
22
        $this->id = $id;
23
    }
24
25
    function getId()
26
    {
27
        return $this->id;
28
    }
29
}
30
31
class AppendFileTest extends PHPUnit_Framework_TestCase
32
{
33
    function setUp()
34
    {
35
        $db = MDB2::singleton(DB_DSN);
36
        $db->query('TRUNCATE filehandler_append_file');
37
    }
38
39
    function createAppendFile($id = 0)
40
    {
41
        $kernel = new Stub_Kernel;
42
        return new AppendFile($kernel, 'product', 1, $id);
0 ignored issues
show
Unused Code introduced by
The call to AppendFile::__construct() has too many arguments starting with $id.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
43
    }
44
45
    /////////////////////////////////////////////////////////
46
47
    function testConstruction()
48
    {
49
        $append = $this->createAppendFile();
50
        $this->assertTrue(is_object($append));
51
    }
52
53
    function testAddFileAsInteger()
54
    {
55
        $append = $this->createAppendFile();
56
        $this->assertTrue($append->addFile(new FakeAppendFileFile) > 0);
57
    }
58
59
    function testAddFilesAsArray()
60
    {
61
        $append = $this->createAppendFile();
62
        $this->assertTrue($append->addFiles(array(new FakeAppendFileFile)));
63
    }
64
65
    function testDeleteReturnsTrue()
66
    {
67
        $append = $this->createAppendFile();
68
        $id = $append->addFile(new FakeAppendFileFile);
69
        $this->assertTrue($append->delete($id));
70
    }
71
72
    function testUnDeleteReturnsTrue()
73
    {
74
        $append = $this->createAppendFile();
75
        $id = $append->addFile(new FakeAppendFileFile);
76
        $append->delete($id);
77
        $this->assertTrue($append->undelete(1));
78
    }
79
80
    function testCreateDBQuery()
81
    {
82
        $append = $this->createAppendFile();
83
        $append->getDBQuery();
84
85
        $this->assertTrue(isset($append->dbquery));
86
    }
87
88
    function testGetList()
89
    {
90
        $append = $this->createAppendFile();
91
        $append->addFile(new FakeAppendFileFile(1));
92
        $append->addFile(new FakeAppendFileFile(2));
93
        $append->addFile(new FakeAppendFileFile(3));
94
95
        $append->getDBQuery();
96
97
        $expected = array(
98
            0 => array(
99
                'id' => 1,
100
                'file_handler_id' => 1,
101
                'description' => ''),
102
            1 => array(
103
                'id' => 2,
104
                'file_handler_id' => 2,
105
                'description' => ''),
106
            2 => array(
107
                'id' => 3,
108
                'file_handler_id' => 3,
109
                'description' => '')
110
        );
111
112
113
        $this->assertEquals($expected, $append->getList());
114
    }
115
}
116