Completed
Push — master ( 737862...3fd823 )
by Wim
9s
created

DeprecatedFunctionsSniffTest::testMcryptCfb()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 9.4285
1
<?php
2
/**
3
 * Deprecated functions sniff test file
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * Deprecated functions sniff tests
11
 *
12
 * @uses BaseSniffTest
13
 * @package PHPCompatibility
14
 * @author Jansen Price <[email protected]>
15
 */
16
class DeprecatedFunctionsSniffTest extends BaseSniffTest
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
    const TEST_FILE = 'sniff-examples/deprecated_functions.php';
20
21
22
    /**
23
     * testDeprecatedFunction
24
     *
25
     * @dataProvider dataDeprecatedFunction
26
     *
27
     * @param string $functionName      Name of the function.
28
     * @param string $deprecatedIn      The PHP version in which the function was deprecated.
29
     * @param array  $lines             The line numbers in the test file which apply to this function.
30
     * @param string $okVersion         A PHP version in which the function was still valid.
31
     * @param string $deprecatedVersion Optional PHP version to test deprecation message with -
32
     *                                  if different from the $deprecatedIn version.
33
     *
34
     * return void
35
     */
36 View Code Duplication
    public function testDeprecatedFunction($functionName, $deprecatedIn, $lines, $okVersion, $deprecatedVersion = null)
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...
37
    {
38
        $file = $this->sniffFile(self::TEST_FILE, $okVersion);
39
        foreach($lines as $line) {
40
            $this->assertNoViolation($file, $line);
41
        }
42
43
        if (isset($deprecatedVersion)){
44
            $file = $this->sniffFile(self::TEST_FILE, $deprecatedVersion);
45
        }
46
        else {
47
            $file = $this->sniffFile(self::TEST_FILE, $deprecatedIn);
48
        }
49
        foreach($lines as $line) {
50
            $this->assertWarning($file, $line, "The use of function {$functionName} is discouraged from PHP version {$deprecatedIn}");
51
        }
52
    }
53
54
    /**
55
     * Data provider.
56
     *
57
     * @see testDeprecatedFunction()
58
     *
59
     * @return array
60
     */
61
    public function dataDeprecatedFunction()
62
    {
63
        return array(
64
            array('dl', '5.3', array(6), '5.2'),
65
            array('ocifetchinto', '5.4', array(63), '5.3'),
66
            array('ldap_sort', '7.0', array(97), '5.6'),
67
        );
68
    }
69
70
71
    /**
72
     * testDeprecatedFunctionWithAlternative
73
     *
74
     * @dataProvider dataDeprecatedFunctionWithAlternative
75
     *
76
     * @param string $functionName      Name of the function.
77
     * @param string $deprecatedIn      The PHP version in which the function was deprecated.
78
     * @param string $alternative       An alternative function.
79
     * @param array  $lines             The line numbers in the test file which apply to this function.
80
     * @param string $okVersion         A PHP version in which the function was still valid.
81
     * @param string $deprecatedVersion Optional PHP version to test deprecation message with -
82
     *                                  if different from the $deprecatedIn version.
83
     *
84
     * return void
85
     */
86 View Code Duplication
    public function testDeprecatedFunctionWithAlternative($functionName, $deprecatedIn, $alternative, $lines, $okVersion, $deprecatedVersion = null)
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...
87
    {
88
        $file = $this->sniffFile(self::TEST_FILE, $okVersion);
89
        foreach($lines as $line) {
90
            $this->assertNoViolation($file, $line);
91
        }
92
93
        if (isset($deprecatedVersion)){
94
            $file = $this->sniffFile(self::TEST_FILE, $deprecatedVersion);
95
        }
96
        else {
97
            $file = $this->sniffFile(self::TEST_FILE, $deprecatedIn);
98
        }
99
        foreach($lines as $line) {
100
            $this->assertWarning($file, $line, "The use of function {$functionName} is discouraged from PHP version {$deprecatedIn}; use {$alternative} instead");
101
        }
102
    }
103
104
    /**
105
     * Data provider.
106
     *
107
     * @see testDeprecatedFunctionWithAlternative()
108
     *
109
     * @return array
110
     */
111
    public function dataDeprecatedFunctionWithAlternative()
112
    {
113
        return array(
114
            array('ocibindbyname', '5.4', 'oci_bind_by_name', array(41), '5.3'),
115
            array('ocicancel', '5.4', 'oci_cancel', array(42), '5.3'),
116
            array('ocicloselob', '5.4', 'OCI-Lob::close', array(43), '5.3'),
117
            array('ocicollappend', '5.4', 'OCI-Collection::append', array(44), '5.3'),
118
            array('ocicollassign', '5.4', 'OCI-Collection::assign', array(45), '5.3'),
119
            array('ocicollassignelem', '5.4', 'OCI-Collection::assignElem', array(46), '5.3'),
120
            array('ocicollgetelem', '5.4', 'OCI-Collection::getElem', array(47), '5.3'),
121
            array('ocicollmax', '5.4', 'OCI-Collection::max', array(48), '5.3'),
122
            array('ocicollsize', '5.4', 'OCI-Collection::size', array(49), '5.3'),
123
            array('ocicolltrim', '5.4', 'OCI-Collection::trim', array(50), '5.3'),
124
            array('ocicolumnisnull', '5.4', 'oci_field_is_null', array(51), '5.3'),
125
            array('ocicolumnname', '5.4', 'oci_field_name', array(52), '5.3'),
126
            array('ocicolumnprecision', '5.4', 'oci_field_precision', array(53), '5.3'),
127
            array('ocicolumnscale', '5.4', 'oci_field_scale', array(54), '5.3'),
128
            array('ocicolumnsize', '5.4', 'oci_field_size', array(55), '5.3'),
129
            array('ocicolumntype', '5.4', 'oci_field_type', array(56), '5.3'),
130
            array('ocicolumntyperaw', '5.4', 'oci_field_type_raw', array(57), '5.3'),
131
            array('ocicommit', '5.4', 'oci_commit', array(58), '5.3'),
132
            array('ocidefinebyname', '5.4', 'oci_define_by_name', array(59), '5.3'),
133
            array('ocierror', '5.4', 'oci_error', array(60), '5.3'),
134
            array('ociexecute', '5.4', 'oci_execute', array(61), '5.3'),
135
            array('ocifetch', '5.4', 'oci_fetch', array(62), '5.3'),
136
            array('ocifetchstatement', '5.4', 'oci_fetch_all', array(64), '5.3'),
137
            array('ocifreecollection', '5.4', 'OCI-Collection::free', array(65), '5.3'),
138
            array('ocifreecursor', '5.4', 'oci_free_statement', array(66), '5.3'),
139
            array('ocifreedesc', '5.4', 'OCI-Lob::free', array(67), '5.3'),
140
            array('ocifreestatement', '5.4', 'oci_free_statement', array(68), '5.3'),
141
            array('ociinternaldebug', '5.4', 'oci_internal_debug', array(69), '5.3'),
142
            array('ociloadlob', '5.4', 'OCI-Lob::load', array(70), '5.3'),
143
            array('ocilogoff', '5.4', 'oci_close', array(71), '5.3'),
144
            array('ocilogon', '5.4', 'oci_connect', array(72), '5.3'),
145
            array('ocinewcollection', '5.4', 'oci_new_collection', array(73), '5.3'),
146
            array('ocinewcursor', '5.4', 'oci_new_cursor', array(74), '5.3'),
147
            array('ocinewdescriptor', '5.4', 'oci_new_descriptor', array(75), '5.3'),
148
            array('ocinlogon', '5.4', 'oci_new_connect', array(76), '5.3'),
149
            array('ocinumcols', '5.4', 'oci_num_fields', array(77), '5.3'),
150
            array('ociparse', '5.4', 'oci_parse', array(78), '5.3'),
151
            array('ociplogon', '5.4', 'oci_pconnect', array(79), '5.3'),
152
            array('ociresult', '5.4', 'oci_result', array(80), '5.3'),
153
            array('ocirollback', '5.4', 'oci_rollback', array(81), '5.3'),
154
            array('ocirowcount', '5.4', 'oci_num_rows', array(82), '5.3'),
155
            array('ocisavelob', '5.4', 'OCI-Lob::save', array(83), '5.3'),
156
            array('ocisavelobfile', '5.4', 'OCI-Lob::import', array(84), '5.3'),
157
            array('ociserverversion', '5.4', 'oci_server_version', array(85), '5.3'),
158
            array('ocisetprefetch', '5.4', 'oci_set_prefetch', array(86), '5.3'),
159
            array('ocistatementtype', '5.4', 'oci_statement_type', array(87), '5.3'),
160
            array('ociwritelobtofile', '5.4', 'OCI-Lob::export', array(88), '5.3'),
161
            array('ociwritetemporarylob', '5.4', 'OCI-Lob::writeTemporary', array(89), '5.3'),
162
163
        );
164
    }
165
166
167
    /**
168
     * testForbiddenFunction
169
     *
170
     * @dataProvider dataForbiddenFunction
171
     *
172
     * @param string $functionName      Name of the function.
173
     * @param string $forbiddenIn       The PHP version in which the function was forbidden.
174
     * @param array  $lines             The line numbers in the test file which apply to this function.
175
     * @param string $okVersion         A PHP version in which the function was still valid.
176
     * @param string $forbiddenVersion  Optional PHP version to test forbidden message with -
177
     *                                  if different from the $forbiddenIn version.
178
     *
179
     * return void
180
     */
181 View Code Duplication
    public function testForbiddenFunction($functionName, $forbiddenIn, $lines, $okVersion, $forbiddenVersion = null)
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...
182
    {
183
        $file = $this->sniffFile(self::TEST_FILE, $okVersion);
184
        foreach($lines as $line) {
185
            $this->assertNoViolation($file, $line);
186
        }
187
188
        if (isset($forbiddenVersion)){
189
            $file = $this->sniffFile(self::TEST_FILE, $forbiddenVersion);
190
        }
191
        else {
192
            $file = $this->sniffFile(self::TEST_FILE, $forbiddenIn);
193
        }
194
        foreach($lines as $line) {
195
            $this->assertError($file, $line, "The use of function {$functionName} is forbidden from PHP version {$forbiddenIn}");
196
        }
197
    }
198
199
    /**
200
     * Data provider.
201
     *
202
     * @see testForbiddenFunction()
203
     *
204
     * @return array
205
     */
206
    public function dataForbiddenFunction()
207
    {
208
        return array(
209
            array('php_logo_guid', '5.5', array(32), '5.4'),
210
            array('php_egg_logo_guid', '5.5', array(33), '5.4'),
211
            array('php_real_logo_guid', '5.5', array(34), '5.4'),
212
            array('zend_logo_guid', '5.5', array(35), '5.4'),
213
            array('imagepsbbox', '7.0', array(90), '5.6'),
214
            array('imagepsencodefont', '7.0', array(91), '5.6'),
215
            array('imagepsextendfont', '7.0', array(92), '5.6'),
216
            array('imagepsfreefont', '7.0', array(93), '5.6'),
217
            array('imagepsloadfont', '7.0', array(94), '5.6'),
218
            array('imagepsslantfont', '7.0', array(95), '5.6'),
219
            array('imagepstext', '7.0', array(96), '5.6'),
220
221
        );
222
    }
223
224
225
    /**
226
     * testDeprecatedForbiddenFunction
227
     *
228
     * @dataProvider dataDeprecatedForbiddenFunction
229
     *
230
     * @param string $functionName      Name of the function.
231
     * @param string $deprecatedIn      The PHP version in which the function was deprecated.
232
     * @param string $forbiddenIn       The PHP version in which the function was forbidden.
233
     * @param array  $lines             The line numbers in the test file which apply to this function.
234
     * @param string $okVersion         A PHP version in which the function was still valid.
235
     * @param string $deprecatedVersion Optional PHP version to test deprecation message with -
236
     *                                  if different from the $deprecatedIn version.
237
     * @param string $forbiddenVersion  Optional PHP version to test forbidden message with -
238
     *                                  if different from the $forbiddenIn version.
239
     *
240
     * return void
241
     */
242 View Code Duplication
    public function testDeprecatedForbiddenFunction($functionName, $deprecatedIn, $forbiddenIn, $lines, $okVersion, $deprecatedVersion = null, $forbiddenVersion = null)
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...
243
    {
244
        $file = $this->sniffFile(self::TEST_FILE, $okVersion);
245
        foreach($lines as $line) {
246
            $this->assertNoViolation($file, $line);
247
        }
248
249
        if (isset($deprecatedVersion)){
250
            $file = $this->sniffFile(self::TEST_FILE, $deprecatedVersion);
251
        }
252
        else {
253
            $file = $this->sniffFile(self::TEST_FILE, $deprecatedIn);
254
        }
255
        foreach($lines as $line) {
256
            $this->assertWarning($file, $line, "The use of function {$functionName} is discouraged from PHP version {$deprecatedIn}");
257
        }
258
259
        if (isset($forbiddenVersion)){
260
            $file = $this->sniffFile(self::TEST_FILE, $forbiddenVersion);
261
        }
262
        else {
263
            $file = $this->sniffFile(self::TEST_FILE, $forbiddenIn);
264
        }
265
        foreach($lines as $line) {
266
            $this->assertError($file, $line, "The use of function {$functionName} is discouraged from PHP version {$deprecatedIn} and forbidden from PHP version {$forbiddenIn}");
267
        }
268
    }
269
270
    /**
271
     * Data provider.
272
     *
273
     * @see testDeprecatedForbiddenFunction()
274
     *
275
     * @return array
276
     */
277
    public function dataDeprecatedForbiddenFunction()
278
    {
279
        return array(
280
            array('define_syslog_variables', '5.3', '5.4', array(5), '5.2'),
281
            array('import_request_variables', '5.3', '5.4', array(11), '5.2'),
282
            array('mysql_list_dbs', '5.4', '7.0', array(15), '5.3'),
283
            array('magic_quotes_runtime', '5.3', '7.0', array(23), '5.2'),
284
            array('set_magic_quotes_runtime', '5.3', '7.0', array(27), '5.2'),
285
            array('sql_regcase', '5.3', '7.0', array(31), '5.2'),
286
            array('mcrypt_ecb', '5.5', '7.0', array(37), '5.4'),
287
            array('mcrypt_cbc', '5.5', '7.0', array(38), '5.4'),
288
            array('mcrypt_cfb', '5.5', '7.0', array(39), '5.4'),
289
            array('mcrypt_ofb', '5.5', '7.0', array(40), '5.4'),
290
291
        );
292
    }
293
294
295
    /**
296
     * testDeprecatedForbiddenFunctionWithAlternative
297
     *
298
     * @dataProvider dataDeprecatedForbiddenFunctionWithAlternative
299
     *
300
     * @param string $functionName      Name of the function.
301
     * @param string $deprecatedIn      The PHP version in which the function was deprecated.
302
     * @param string $forbiddenIn       The PHP version in which the function was forbidden.
303
     * @param string $alternative       An alternative function.
304
     * @param array  $lines             The line numbers in the test file which apply to this function.
305
     * @param string $okVersion         A PHP version in which the function was still valid.
306
     * @param string $deprecatedVersion Optional PHP version to test deprecation message with -
307
     *                                  if different from the $deprecatedIn version.
308
     * @param string $forbiddenVersion  Optional PHP version to test forbidden message with -
309
     *                                  if different from the $forbiddenIn version.
310
     *
311
     * return void
312
     */
313 View Code Duplication
    public function testDeprecatedForbiddenFunctionWithAlternative($functionName, $deprecatedIn, $forbiddenIn, $alternative, $lines, $okVersion, $deprecatedVersion = null, $forbiddenVersion = null)
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...
314
    {
315
        $file = $this->sniffFile(self::TEST_FILE, $okVersion);
316
        foreach($lines as $line) {
317
            $this->assertNoViolation($file, $line);
318
        }
319
320
        if (isset($deprecatedVersion)){
321
            $file = $this->sniffFile(self::TEST_FILE, $deprecatedVersion);
322
        }
323
        else {
324
            $file = $this->sniffFile(self::TEST_FILE, $deprecatedIn);
325
        }
326
        foreach($lines as $line) {
327
            $this->assertWarning($file, $line, "The use of function {$functionName} is discouraged from PHP version {$deprecatedIn}; use {$alternative} instead");
328
        }
329
330
        if (isset($forbiddenVersion)){
331
            $file = $this->sniffFile(self::TEST_FILE, $forbiddenVersion);
332
        }
333
        else {
334
            $file = $this->sniffFile(self::TEST_FILE, $forbiddenIn);
335
        }
336
        foreach($lines as $line) {
337
            $this->assertError($file, $line, "The use of function {$functionName} is discouraged from PHP version {$deprecatedIn} and forbidden from PHP version {$forbiddenIn}; use {$alternative} instead");
338
        }
339
    }
340
341
    /**
342
     * Data provider.
343
     *
344
     * @see testDeprecatedForbiddenFunctionWithAlternative()
345
     *
346
     * @return array
347
     */
348
    public function dataDeprecatedForbiddenFunctionWithAlternative()
349
    {
350
        return array(
351
            array('call_user_method', '5.3', '7.0', 'call_user_func', array(3), '5.2'),
352
            array('call_user_method_array', '5.3', '7.0', 'call_user_func_array', array(4), '5.2'),
353
            array('ereg', '5.3', '7.0', 'preg_match', array(7), '5.2'),
354
            array('ereg_replace', '5.3', '7.0', 'preg_replace', array(8), '5.2'),
355
            array('eregi', '5.3', '7.0', 'preg_match', array(9), '5.2'),
356
            array('eregi_replace', '5.3', '7.0', 'preg_replace', array(10), '5.2'),
357
            array('mcrypt_generic_end', '5.4', '7.0', 'mcrypt_generic_deinit', array(12), '5.3'),
358
            array('mysql_db_query', '5.3', '7.0', 'mysqli_select_db and mysqli_query', array(13), '5.2'),
359
            array('mysql_escape_string', '5.3', '7.0', 'mysqli_real_escape_string', array(14), '5.2'),
360
            array('mysqli_bind_param', '5.3', '5.4', 'mysqli_stmt_bind_param', array(16), '5.2'),
361
            array('mysqli_bind_result', '5.3', '5.4', 'mysqli_stmt_bind_result', array(17), '5.2'),
362
            array('mysqli_client_encoding', '5.3', '5.4', 'mysqli_character_set_name', array(18), '5.2'),
363
            array('mysqli_fetch', '5.3', '5.4', 'mysqli_stmt_fetch', array(19), '5.2'),
364
            array('mysqli_param_count', '5.3', '5.4', 'mysqli_stmt_param_count', array(20), '5.2'),
365
            array('mysqli_get_metadata', '5.3', '5.4', 'mysqli_stmt_result_metadata', array(21), '5.2'),
366
            array('mysqli_send_long_data', '5.3', '5.4', 'mysqli_stmt_send_long_data', array(22), '5.2'),
367
            array('session_register', '5.3', '5.4', '$_SESSION', array(24), '5.2'),
368
            array('session_unregister', '5.3', '5.4', '$_SESSION', array(25), '5.2'),
369
            array('session_is_registered', '5.3', '5.4', '$_SESSION', array(26), '5.2'),
370
            array('set_socket_blocking', '5.3', '7.0', 'stream_set_blocking', array(28), '5.2'),
371
            array('split', '5.3', '7.0', 'preg_split', array(29), '5.2'),
372
            array('spliti', '5.3', '7.0', 'preg_split', array(30), '5.2'),
373
            array('datefmt_set_timezone_id', '5.5', '7.0', 'datefmt_set_timezone', array(36), '5.4'),
374
375
        );
376
    }
377
378
}
379