Completed
Pull Request — master (#215)
by Juliette
03:11
created

BaseClass_GetFunctionParametersTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 273
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 273
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetFunctionCallParameters() 0 5 1
B dataGetFunctionCallParameters() 0 104 1
A testGetFunctionCallParameter() 0 5 1
B dataGetFunctionCallParameter() 0 29 1
A testGetFunctionCallParameterCount() 0 5 1
A dataGetFunctionCallParameterCount() 0 54 1
1
<?php
2
/**
3
 * Function parameter count test file
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * Function parameters count function tests
11
 *
12
 * @uses    BaseClass_MethodTestFrame
13
 * @package PHPCompatibility
14
 * @author  Juliette Reinders Folmer <[email protected]>
15
 */
16
class BaseClass_GetFunctionParametersTest extends BaseClass_MethodTestFrame
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
17
{
18
19
    public $filename = '../sniff-examples/utility-functions/get_function_parameters.php';
20
21
    /**
22
     * testGetFunctionCallParameters
23
     *
24
     * @group utilityFunctions
25
     *
26
     * @dataProvider dataGetFunctionCallParameters
27
     *
28
     * @covers PHPCompatibility_Sniff::getFunctionCallParameters
29
     *
30
     * @param int    $stackPtr Stack pointer for a T_CLASS token in the test file.
31
     * @param string $expected The expected fully qualified class name.
32
     */
33
    public function testGetFunctionCallParameters($stackPtr, $expected)
34
    {
35
        $result = $this->helperClass->getFunctionCallParameters($this->_phpcsFile, $stackPtr);
36
        $this->assertSame($expected, $result);
37
    }
38
39
    /**
40
     * dataGetFunctionCallParameters
41
     *
42
     * @see testGetFunctionCallParameters()
43
     *
44
     * @return array
45
     */
46
    public function dataGetFunctionCallParameters()
47
    {
48
        return array(
49
            array(88, array(
50
                       1 => array(
51
                             'start' => 90,
52
                             'end'   => 91,
53
                             'raw'   => '1',
54
                            ),
55
                       2 => array(
56
                             'start' => 93,
57
                             'end'   => 94,
58
                             'raw'   => '2',
59
                            ),
60
                       3 => array(
61
                             'start' => 96,
62
                             'end'   => 97,
63
                             'raw'   => '3',
64
                            ),
65
                       4 => array(
66
                             'start' => 99,
67
                             'end'   => 100,
68
                             'raw'   => '4',
69
                            ),
70
                       5 => array(
71
                             'start' => 102,
72
                             'end'   => 103,
73
                             'raw'   => '5',
74
                            ),
75
                       6 => array(
76
                             'start' => 105,
77
                             'end'   => 106,
78
                             'raw'   => '6',
79
                            ),
80
                       7 => array(
81
                             'start' => 108,
82
                             'end'   => 110,
83
                             'raw'   => 'true',
84
                            ),
85
                      ),
86
87
            ),
88
            array(120, array(
89
                        1 => array(
90
                              'start' => 122,
91
                              'end'   => 129,
92
                              'raw'   => 'dirname( __FILE__ )',
93
                             ),
94
                       ),
95
            ),
96
            array(250, array(
97
                        1 => array(
98
                              'start' => 252,
99
                              'end'   => 252,
100
                              'raw'   => '$stHour',
101
                             ),
102
                        2 => array(
103
                              'start' => 254,
104
                              'end'   => 255,
105
                              'raw'   => '0',
106
                             ),
107
                        3 => array(
108
                              'start' => 257,
109
                              'end'   => 258,
110
                              'raw'   => '0',
111
                             ),
112
                        4 => array(
113
                              'start' => 260,
114
                              'end'   => 264,
115
                              'raw'   => '$arrStDt[0]',
116
                             ),
117
                        5 => array(
118
                              'start' => 266,
119
                              'end'   => 270,
120
                              'raw'   => '$arrStDt[1]',
121
                             ),
122
                        6 => array(
123
                              'start' => 272,
124
                              'end'   => 276,
125
                              'raw'   => '$arrStDt[2]',
126
                             ),
127
                       ),
128
129
            ),
130
            array(535, array(
131
                        1 => array(
132
                              'start' => 537,
133
                              'end'   => 540,
134
                              'raw'   => 'array()',
135
                             ),
136
                       ),
137
138
            ),
139
            array(577, array(
140
                        1 => array(
141
                              'start' => 579,
142
                              'end'   => 611,
143
                              'raw'   => '[\'a\' => $a,] + (isset($b) ? [\'b\' => $b,] : [])',
144
                             ),
145
                       ),
146
147
            ),
148
        );
149
    }
150
151
152
    /**
153
     * testGetFunctionCallParameter
154
     *
155
     * @group utilityFunctions
156
     *
157
     * @dataProvider dataGetFunctionCallParameter
158
     *
159
     * @covers PHPCompatibility_Sniff::getFunctionCallParameter
160
     *
161
     * @param int    $stackPtr Stack pointer for a T_CLASS token in the test file.
162
     * @param string $expected The expected fully qualified class name.
163
     */
164
    public function testGetFunctionCallParameter($stackPtr, $paramPosition, $expected)
165
    {
166
        $result = $this->helperClass->getFunctionCallParameter($this->_phpcsFile, $stackPtr, $paramPosition);
167
        $this->assertSame($expected, $result);
168
    }
169
170
    /**
171
     * dataGetFunctionCallParameter
172
     *
173
     * @see testGetFunctionCallParameter()
174
     *
175
     * @return array
176
     */
177
    public function dataGetFunctionCallParameter()
178
    {
179
        return array(
180
            array(88, 4, array(
181
                          'start' => 99,
182
                          'end'   => 100,
183
                          'raw'   => '4',
184
                         ),
185
            ),
186
            array(120, 1, array(
187
                           'start' => 122,
188
                           'end'   => 129,
189
                           'raw'   => 'dirname( __FILE__ )',
190
                          ),
191
            ),
192
            array(250, 1, array(
193
                           'start' => 252,
194
                           'end'   => 252,
195
                           'raw'   => '$stHour',
196
                          ),
197
            ),
198
            array(250, 6, array(
199
                           'start' => 272,
200
                           'end'   => 276,
201
                           'raw'   => '$arrStDt[2]',
202
                          ),
203
            ),
204
        );
205
    }
206
207
208
    /**
209
     * testGetFunctionCallParameterCount
210
     *
211
     * @group utilityFunctions
212
     *
213
     * @dataProvider dataGetFunctionCallParameterCount
214
     *
215
     * @covers PHPCompatibility_Sniff::getFunctionCallParameterCount
216
     *
217
     * @param int    $stackPtr Stack pointer for a T_CLASS token in the test file.
218
     * @param string $expected The expected fully qualified class name.
219
     */
220
    public function testGetFunctionCallParameterCount($stackPtr, $expected)
221
    {
222
        $result = $this->helperClass->getFunctionCallParameterCount($this->_phpcsFile, $stackPtr);
223
        $this->assertSame($expected, $result);
224
    }
225
226
    /**
227
     * dataGetFunctionCallParameterCount
228
     *
229
     * @see testGetFunctionCallParameterCount()
230
     *
231
     * @return array
232
     */
233
    public function dataGetFunctionCallParameterCount()
234
    {
235
        return array(
236
            array(5, 1),
237
            array(11, 2),
238
            array(22, 3),
239
            array(34, 4),
240
            array(49, 5),
241
            array(67, 6),
242
            array(88, 7),
243
            array(120, 1),
244
            array(135, 1),
245
            array(150, 1),
246
            array(164, 2),
247
            array(181, 1),
248
            array(194, 1),
249
            array(209, 1),
250
            array(228, 2),
251
            array(250, 6),
252
            array(281, 6),
253
            array(312, 6),
254
            array(351, 6),
255
            array(386, 6),
256
            array(420, 6),
257
            array(454, 6),
258
            array(499, 3),
259
            array(518, 1),
260
            array(535, 1),
261
262
            // Issue #211.
263
            array(551, 1),
264
            array(564, 1),
265
            array(577, 1),
266
            array(615, 1),
267
            array(660, 1),
268
            array(710, 1),
269
            array(761, 1),
270
            array(818, 1),
271
            array(874, 1),
272
            array(894, 1),
273
            array(910, 1),
274
            array(930, 1),
275
            array(964, 1),
276
            array(984, 1),
277
            array(1008, 1),
278
            array(1038, 1),
279
            array(1074, 1),
280
            array(1111, 1),
281
            array(1154, 1),
282
            array(1184, 1),
283
            array(1215, 1),
284
            array(1241, 1),
285
        );
286
    }
287
288
}
289