Completed
Branch feature/scrutinizer-run-tests (072b5a)
by Juliette
10:12
created

DeprecatedIniDirectivesSniffTest::testDeprecatedForbiddenDirectives()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 26
rs 8.439
cc 5
eloc 16
nc 16
nop 7
1
<?php
2
/**
3
 * Deprecated ini directives sniff test file
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * Deprecated ini directives sniff tests
11
 *
12
 * @uses BaseSniffTest
13
 * @package PHPCompatibility
14
 * @author Jansen Price <[email protected]>
15
 */
16
class DeprecatedIniDirectivesSniffTest extends BaseSniffTest
17
{
18
19
    const TEST_FILE = 'sniff-examples/deprecated_ini_directives.php';
20
21
    /**
22
     * Test valid directive
23
     *
24
     * @return void
25
     */
26
    public function testValidDirective()
27
    {
28
        $file = $this->sniffFile(self::TEST_FILE);
29
        $this->assertNoViolation($file, 57);
30
        $this->assertNoViolation($file, 58);
31
    }
32
33
    /**
34
     * testDeprecatedForbiddenDirectives
35
     *
36
     * @dataProvider dataDeprecatedForbiddenDirectives
37
     *
38
     * @param string $iniName           Name of the ini directive.
39
     * @param string $deprecatedIn      The PHP version in which the ini directive was deprecated.
40
     * @param string $forbiddenIn       The PHP version in which the ini directive was forbidden.
41
     * @param array  $lines             The line numbers in the test file which apply to this ini directive.
42
     * @param string $okVersion         A PHP version in which the ini directive was still valid.
43
     * @param string $deprecatedVersion Optional PHP version to test deprecation message with -
44
     *                                  if different from the $deprecatedIn version.
45
     * @param string $forbiddenVersion  Optional PHP version to test forbidden message with -
46
     *                                  if different from the $forbiddenIn version.
47
     *
48
     * @return void
49
     */
50
    public function testDeprecatedForbiddenDirectives($iniName, $deprecatedIn, $forbiddenIn, $lines, $okVersion, $deprecatedVersion = null, $forbiddenVersion = null)
51
    {
52
        $file = $this->sniffFile(self::TEST_FILE, $okVersion);
53
        foreach($lines as $line) {
54
            $this->assertNoViolation($file, $line);
55
        }
56
57
        if (isset($deprecatedVersion)){
58
            $file = $this->sniffFile(self::TEST_FILE, $deprecatedVersion);
59
        }
60
        else {
61
            $file = $this->sniffFile(self::TEST_FILE, $deprecatedIn);
62
        }
63
        foreach($lines as $line) {
64
            $this->assertWarning($file, $line, "INI directive '{$iniName}' is deprecated from PHP {$deprecatedIn}.");
65
        }
66
67
        if (isset($forbiddenVersion)){
68
            $file = $this->sniffFile(self::TEST_FILE, $forbiddenVersion);
69
        }
70
        else {
71
            $file = $this->sniffFile(self::TEST_FILE, $forbiddenIn);
72
        }
73
        $this->assertError($file, $lines[0], "INI directive '{$iniName}' is deprecated from PHP {$deprecatedIn} and forbidden from PHP {$forbiddenIn}");
74
        $this->assertWarning($file, $lines[1], "INI directive '{$iniName}' is deprecated from PHP {$deprecatedIn} and forbidden from PHP {$forbiddenIn}");
75
    }
76
77
    /**
78
     * Data provider.
79
     *
80
     * @see testDeprecatedForbiddenDirectives()
81
     *
82
     * @return array
83
     */
84
    public function dataDeprecatedForbiddenDirectives()
85
    {
86
        return array(
87
            array('define_syslog_variables', '5.3', '5.4', array(3, 4), '5.2'),
88
            array('register_globals', '5.3', '5.4', array(6, 7), '5.2'),
89
            array('register_long_arrays', '5.3', '5.4', array(9, 10), '5.2'),
90
            array('magic_quotes_gpc', '5.3', '5.4', array(12, 13), '5.2'),
91
            array('magic_quotes_runtime', '5.3', '5.4', array(15, 16), '5.2'),
92
            array('magic_quotes_sybase', '5.3', '5.4', array(18, 19), '5.2'),
93
            array('allow_call_time_pass_reference', '5.3', '5.4', array(21, 22), '5.2'),
94
            array('highlight.bg', '5.3', '5.4', array(24, 25), '5.2'),
95
            array('session.bug_compat_42', '5.3', '5.4', array(27, 28), '5.2'),
96
            array('session.bug_compat_warn', '5.3', '5.4', array(30, 31), '5.2'),
97
            array('y2k_compliance', '5.3', '5.4', array(33, 34), '5.2'),
98
            array('safe_mode', '5.3', '5.4', array(39, 40), '5.2'),
99
            array('safe_mode_gid', '5.3', '5.4', array(42, 43), '5.2'),
100
            array('safe_mode_include_dir', '5.3', '5.4', array(45, 46), '5.2'),
101
            array('safe_mode_exec_dir', '5.3', '5.4', array(48, 49), '5.2'),
102
            array('safe_mode_allowed_env_vars', '5.3', '5.4', array(51, 52), '5.2'),
103
            array('safe_mode_protected_env_vars', '5.3', '5.4', array(54, 55), '5.2'),
104
105
            array('always_populate_raw_post_data', '5.6', '7.0', array(80, 81), '5.5'),
106
        );
107
    }
108
109
110
    /**
111
     * testDeprecatedDirectives
112
     *
113
     * @dataProvider dataDeprecatedDirectives
114
     *
115
     * @param string $iniName           Name of the ini directive.
116
     * @param string $deprecatedIn      The PHP version in which the ini directive was deprecated.
117
     * @param array  $lines             The line numbers in the test file which apply to this ini directive.
118
     * @param string $okVersion         A PHP version in which the ini directive was still valid.
119
     * @param string $deprecatedVersion Optional PHP version to test deprecation message with -
120
     *                                  if different from the $deprecatedIn version.
121
     *
122
     * @return void
123
     */
124
    public function testDeprecatedDirectives($iniName, $deprecatedIn, $lines, $okVersion, $deprecatedVersion = null)
125
    {
126
        $file = $this->sniffFile(self::TEST_FILE, $okVersion);
127
        foreach($lines as $line) {
128
            $this->assertNoViolation($file, $line);
129
        }
130
131
        if (isset($deprecatedVersion)){
132
            $file = $this->sniffFile(self::TEST_FILE, $deprecatedVersion);
133
        }
134
        else {
135
            $file = $this->sniffFile(self::TEST_FILE, $deprecatedIn);
136
        }
137
        foreach($lines as $line) {
138
            $this->assertWarning($file, $line, "INI directive '{$iniName}' is deprecated from PHP {$deprecatedIn}.");
139
        }
140
    }
141
142
    /**
143
     * Data provider.
144
     *
145
     * @see testDeprecatedDirectives()
146
     *
147
     * @return array
148
     */
149
    public function dataDeprecatedDirectives()
150
    {
151
        return array(
152
            array('safe_mode_protected_env_vars', '5.3', array(54, 55), '5.2'),
153
154
            array('iconv.input_encoding', '5.6', array(62, 63), '5.5'),
155
            array('iconv.output_encoding', '5.6', array(65, 66), '5.5'),
156
            array('iconv.internal_encoding', '5.6', array(68, 69), '5.5'),
157
            array('mbstring.http_input', '5.6', array(71, 72), '5.5'),
158
            array('mbstring.http_output', '5.6', array(74, 75), '5.5'),
159
            array('mbstring.internal_encoding', '5.6', array(77, 78), '5.5'),
160
        );
161
    }
162
163
164
165
    /**
166
     * testForbiddenWithAlternative
167
     *
168
     * @dataProvider dataForbiddenWithAlternative
169
     *
170
     * @param string $iniName           Name of the ini directive.
171
     * @param string $forbiddenIn       The PHP version in which the ini directive was forbidden.
172
     * @param string $alternative       An alternative ini directive for the forbidden directive.
173
     * @param array  $lines             The line numbers in the test file which apply to this ini directive.
174
     * @param string $okVersion         A PHP version in which the ini directive was still valid.
175
     * @param string $forbiddenVersion  Optional PHP version to test forbidden message with -
176
     *                                  if different from the $forbiddenIn version.
177
     *
178
     * @return void
179
     */
180
    public function testForbiddenWithAlternative($iniName, $forbiddenIn, $alternative, $lines, $okVersion, $forbiddenVersion = null)
181
    {
182
        $file = $this->sniffFile(self::TEST_FILE, $okVersion);
183
        foreach($lines as $line) {
184
            $this->assertNoViolation($file, $line);
185
        }
186
187
        if (isset($forbiddenVersion)){
188
            $file = $this->sniffFile(self::TEST_FILE, $forbiddenVersion);
189
        }
190
        else {
191
            $file = $this->sniffFile(self::TEST_FILE, $forbiddenIn);
192
        }
193
        $this->assertError($file, $lines[0], "INI directive '{$iniName}' is forbidden from PHP {$forbiddenIn}. Use '{$alternative}' instead.");
194
        $this->assertWarning($file, $lines[1], "INI directive '{$iniName}' is forbidden from PHP {$forbiddenIn}. Use '{$alternative}' instead.");
195
    }
196
197
    /**
198
     * Data provider.
199
     *
200
     * @see testForbiddenWithAlternative()
201
     *
202
     * @return array
203
     */
204
    public function dataForbiddenWithAlternative()
205
    {
206
        return array(
207
            array('fbsql.batchSize', '5.1', 'fbsql.batchsize', array(89, 90), '5.0'),
208
            array('detect_unicode', '5.4', 'zend.detect_unicode', array(125, 126), '5.3'),
209
            array('mbstring.script_encoding', '5.4', 'zend.script_encoding', array(128, 129), '5.3'),
210
        );
211
    }
212
213
    /**
214
     * testForbiddenDirectives
215
     *
216
     * @dataProvider dataForbiddenDirectives
217
     *
218
     * @param string $iniName           Name of the ini directive.
219
     * @param string $forbiddenIn       The PHP version in which the ini directive was forbidden.
220
     * @param array  $lines             The line numbers in the test file which apply to this ini directive.
221
     * @param string $okVersion         A PHP version in which the ini directive was still valid.
222
     * @param string $forbiddenVersion  Optional PHP version to test forbidden message with -
223
     *                                  if different from the $forbiddenIn version.
224
     *
225
     * @return void
226
     */
227
    public function testForbiddenDirectives($iniName, $forbiddenIn, $lines, $okVersion, $forbiddenVersion = null)
228
    {
229
        $file = $this->sniffFile(self::TEST_FILE, $okVersion);
230
        foreach($lines as $line) {
231
            $this->assertNoViolation($file, $line);
232
        }
233
234
        if (isset($forbiddenVersion)){
235
            $file = $this->sniffFile(self::TEST_FILE, $forbiddenVersion);
236
        }
237
        else {
238
            $file = $this->sniffFile(self::TEST_FILE, $forbiddenIn);
239
        }
240
        $this->assertError($file, $lines[0], "INI directive '{$iniName}' is forbidden from PHP {$forbiddenIn}.");
241
        $this->assertWarning($file, $lines[1], "INI directive '{$iniName}' is forbidden from PHP {$forbiddenIn}.");
242
    }
243
244
    /**
245
     * Data provider.
246
     *
247
     * @see testForbiddenDirectives()
248
     *
249
     * @return array
250
     */
251
    public function dataForbiddenDirectives()
252
    {
253
        return array(
254
            array('ifx.allow_persistent', '5.2.1', array(92, 93), '5.1', '5.3'),
255
            array('ifx.blobinfile', '5.2.1', array(95, 96), '5.1', '5.3'),
256
            array('ifx.byteasvarchar', '5.2.1', array(98, 99), '5.1', '5.3'),
257
            array('ifx.charasvarchar', '5.2.1', array(101, 102), '5.1', '5.3'),
258
            array('ifx.default_host', '5.2.1', array(104, 105), '5.1', '5.3'),
259
            array('ifx.default_password', '5.2.1', array(107, 108), '5.1', '5.3'),
260
            array('ifx.default_user', '5.2.1', array(110, 111), '5.1', '5.3'),
261
            array('ifx.max_links', '5.2.1', array(113, 114), '5.1', '5.3'),
262
            array('ifx.max_persistent', '5.2.1', array(116, 117), '5.1', '5.3'),
263
            array('ifx.nullformat', '5.2.1', array(119, 120), '5.1', '5.3'),
264
            array('ifx.textasvarchar', '5.2.1', array(122, 123), '5.1', '5.3'),
265
266
            array('zend.ze1_compatibility_mode', '5.3', array(36, 37), '5.2'),
267
268
            array('asp_tags', '7.0', array(83, 84), '5.6'),
269
            array('xsl.security_prefs', '7.0', array(86, 87), '5.6'),
270
        );
271
    }
272
273
}
274