ListTableTest::testFitDataWithTitle()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 116

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 116
rs 8
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace FwlibTest\Html;
3
4
use Fwlib\Bridge\Smarty;
5
use Fwlib\Html\ListTable;
6
use Fwolf\Wrapper\PHPUnit\PHPUnitTestCase;
7
8
/**
9
 * @copyright   Copyright 2013-2015 Fwolf
10
 * @license     http://www.gnu.org/licenses/lgpl.html LGPL-3.0+
11
 */
12
class ListTableTest extends PHPUnitTestCase
13
{
14
    /**
15
     * @return ListTable
16
     */
17
    protected function buildMock()
18
    {
19
        $smarty = new Smarty;
20
21
        $listTable = new ListTable($smarty);
0 ignored issues
show
Deprecated Code introduced by
The class Fwlib\Html\ListTable has been deprecated with message: Use ListView instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
22
23
        return $listTable;
24
    }
25
26
27
    public function testFitDataWithTitle()
28
    {
29
        $listTable = $this->buildMock();
30
31
        $listTable->setConfig('fitEmpty', '&nbsp;');
32
        $data = [
33
            [
34
                'uuid'  => '1',
35
                'title' => 'tom',
36
                'age'   => 20,
37
            ],
38
            [
39
                'uuid'  => '2',
40
                'title' => 'jack',
41
                'age'   => 30,
42
            ],
43
            [
44
                'uuid'  => '3',
45
                'title' => 'smith',
46
                'age'   => 40,
47
            ],
48
        ];
49
        $title = [
50
            'title' => 'Name',
51
            'age'   => 'Current Age',
52
            'credit'    => 'Money',
53
        ];
54
55
56
        $listTable->setConfig('fitMode', ListTable::FIT_TO_TITLE);
57
        $listTable->setData($data, $title);
58
        $x = [
59
            [
60
                'title' => 'tom',
61
                'age'   => 20,
62
                'credit'    => '&nbsp;',
63
            ],
64
            [
65
                'title' => 'jack',
66
                'age'   => 30,
67
                'credit'    => '&nbsp;',
68
            ],
69
            [
70
                'title' => 'smith',
71
                'age'   => 40,
72
                'credit'    => '&nbsp;',
73
            ],
74
        ];
75
        $this->assertEqualArray($x, $this->reflectionGet($listTable, 'listData'));
76
77
78
        $listTable->setConfig('fitMode', ListTable::FIT_TO_DATA);
79
        $listTable->setData($data, $title);
80
        $x = [
81
            'title' => 'Name',
82
            'age'   => 'Current Age',
83
            'uuid'  => 'uuid',  // Add later, so on last position
84
        ];
85
        $this->assertEqualArray($x, $this->reflectionGet($listTable, 'listTitle'));
86
87
88
        $listTable->setConfig('fitMode', ListTable::FIT_INTERSECTION);
89
        $listTable->setData($data, $title);
90
        $x = [
91
            [
92
                'title' => 'tom',
93
                'age'   => 20,
94
            ],
95
            [
96
                'title' => 'jack',
97
                'age'   => 30,
98
            ],
99
            [
100
                'title' => 'smith',
101
                'age'   => 40,
102
            ],
103
        ];
104
        $y = [
105
            'title' => 'Name',
106
            'age'   => 'Current Age',
107
        ];
108
        $this->assertEqualArray($x, $this->reflectionGet($listTable, 'listData'));
109
        $this->assertEqualArray($y, $this->reflectionGet($listTable, 'listTitle'));
110
111
112
        $listTable->setConfig('fitMode', ListTable::FIT_UNION);
113
        $listTable->setData($data, $title);
114
        $x = [
115
            [
116
                'uuid'  => '1',
117
                'title' => 'tom',
118
                'age'   => 20,
119
                'credit'    => '&nbsp;',
120
            ],
121
            [
122
                'uuid'  => '2',
123
                'title' => 'jack',
124
                'age'   => 30,
125
                'credit'    => '&nbsp;',
126
            ],
127
            [
128
                'uuid'  => '3',
129
                'title' => 'smith',
130
                'age'   => 40,
131
                'credit'    => '&nbsp;',
132
            ],
133
        ];
134
        $y = [
135
            'title' => 'Name',
136
            'age'   => 'Current Age',
137
            'credit'    => 'Money',
138
            'uuid'  => 'uuid',
139
        ];
140
        $this->assertEqualArray($x, $this->reflectionGet($listTable, 'listData'));
141
        $this->assertEqualArray($y, $this->reflectionGet($listTable, 'listTitle'));
142
    }
143
}
144