InstanceManagerTest   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 125
Duplicated Lines 27.2 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 34
loc 125
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 3

11 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A createInstanceManager() 0 4 1
A testConstruction() 0 5 1
A testConstructionOnStandardType() 0 5 1
A testConstructionOnInvalidType() 0 5 1
A testSaveWithEmptyArray() 0 5 1
A testSaveWithOverwriteStandardType() 10 10 1
B testLoadAfterOverwriteStandardType() 0 26 1
A testSaveNewType() 10 10 1
B testLoadAfterSaveNewType() 0 24 1
A testGetList() 13 13 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
require_once 'Intraface/Standard.php';
3
require_once 'Intraface/Error.php';
4
require_once 'Intraface/modules/filemanager/FileHandler.php';
5
require_once 'Intraface/modules/filemanager/InstanceManager.php';
6
require_once 'file_functions.php';
7
8
class InstanceManagerTest extends PHPUnit_Framework_TestCase
9
{
10
    function setUp()
11
    {
12
        $db = MDB2::singleton(DB_DSN);
13
        $db->query('TRUNCATE file_handler_instance_type');
14
    }
15
16
    function createInstanceManager($id = 0)
17
    {
18
        return new InstanceManager(new Stub_Kernel, $id);
19
    }
20
21
    function testConstruction()
22
    {
23
        $im = $this->createInstanceManager();
24
        $this->assertTrue(is_object($im));
25
    }
26
27
    function testConstructionOnStandardType()
28
    {
29
        $im = $this->createInstanceManager(1);
30
        $this->assertEquals('square', $im->get('name'));
31
    }
32
33
    function testConstructionOnInvalidType()
34
    {
35
        $im = $this->createInstanceManager(999999);
36
        $this->assertEquals(0, $im->get('type_key'));
37
    }
38
39
    function testSaveWithEmptyArray()
40
    {
41
        $im = $this->createInstanceManager();
42
        $this->assertFalse($im->save(array()));
43
    }
44
45 View Code Duplication
    function testSaveWithOverwriteStandardType()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
    {
47
        $im = $this->createInstanceManager(2);
48
        $input = array('name' => 'some-new-name-which-will-not-be-used',
49
            'max_width' => 100,
50
            'max_height' => 100,
51
            'resize_type' => 'strict');
52
53
        $this->assertEquals(2, $im->save($input));
54
    }
55
56
    function testLoadAfterOverwriteStandardType()
57
    {
58
        $im = $this->createInstanceManager(2);
59
60
        $input = array('name' => 'some-new-name-which-will-not-be-used',
61
            'max_width' => 101,
62
            'max_height' => 101,
63
            'resize_type' => 'strict');
64
65
        $im->save($input);
66
67
        $im = $this->createInstanceManager(2);
68
        $output = array(
69
            'type_key' => 2,
70
            'name' => 'thumbnail',
71
            'fixed' => false,
72
            'hidden' => false,
73
            'max_width' => 101,
74
            'max_height' => 101,
75
            'resize_type' => 'strict',
76
            'resize_type_key' => 1,
77
            'origin' => 'overwritten'
78
        );
79
80
        $this->assertEquals($output, $im->get());
81
    }
82
83 View Code Duplication
    function testSaveNewType()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
84
    {
85
        $im = $this->createInstanceManager();
86
        $input = array('name' => 'new-type',
87
            'max_width' => 240,
88
            'max_height' => 130,
89
            'resize_type' => 'relative');
90
91
        $this->assertEquals(1000, $im->save($input));
92
    }
93
94
    function testLoadAfterSaveNewType()
95
    {
96
        $im = $this->createInstanceManager();
97
98
        $input = array('name' => 'new-type',
99
            'max_width' => 240,
100
            'max_height' => 130,
101
            'resize_type' => 'relative');
102
103
        $im->save($input);
104
105
        $im = $this->createInstanceManager(1000);
106
        $output = array(
107
            'name' => 'new-type',
108
            'type_key' => 1000,
109
            'max_width' => 240,
110
            'max_height' => 130,
111
            'resize_type_key' => 0,
112
            'resize_type' => 'relative',
113
            'origin' => 'custom'
114
        );
115
116
        $this->assertEquals($output, $im->get());
117
    }
118
119 View Code Duplication
    function testGetList()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
120
    {
121
        $im = $this->createInstanceManager();
122
123
        $input = array('name' => 'new-type',
124
            'max_width' => 240,
125
            'max_height' => 130,
126
            'resize_type' => 'relative');
127
128
        $im->save($input);
129
130
        $this->assertEquals(7, count($im->getList()));
131
    }
132
}
133