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

NewIniDirectivesSniffTest::testUserIniFilename()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * New ini directives sniff test file
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * New ini directives sniff tests
11
 *
12
 * @uses BaseSniffTest
13
 * @package PHPCompatibility
14
 * @author Jansen Price <[email protected]>
15
 */
16
class NewIniDirectivesSniffTest 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/new_ini_directives.php';
20
21
    /**
22
     * Test functions that shouldnt be flagged by this sniff
23
     *
24
     * @return void
25
     */
26
    public function testFunctionThatShouldntBeFlagged()
27
    {
28
        $file = $this->sniffFile(self::TEST_FILE, '5.1');
29
30
        $this->assertNoViolation($file, 3);
31
        $this->assertNoViolation($file, 4);
32
        $this->assertNoViolation($file, 5);
33
    }
34
35
36
    /**
37
     * testNewIniDirectives
38
     *
39
     * @dataProvider dataNewIniDirectives
40
     *
41
     * @param string $iniName        Name of the ini directive.
42
     * @param string $fromVersion    The PHP version in which the ini directive was introduced.
43
     * @param array  $lines          The line numbers in the test file which apply to this ini directive.
44
     * @param string $warningVersion A PHP version in which the ini directive was not yet present.
45
     * @param string $okVersion      A PHP version in which the ini directive was valid.
46
     *
47
     * @return void
48
     */
49 View Code Duplication
    public function testNewIniDirectives($iniName, $fromVersion, $lines, $warningVersion, $okVersion)
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...
50
    {
51
        $file = $this->sniffFile(self::TEST_FILE, $warningVersion);
52
        foreach($lines as $line) {
53
            $this->assertWarning($file, $line, "INI directive '{$iniName}' is not available before version {$fromVersion}");
54
        }
55
56
        $file = $this->sniffFile(self::TEST_FILE, $okVersion);
57
        foreach( $lines as $line ) {
58
            $this->assertNoViolation($file, $line);
59
        }
60
    }
61
62
    /**
63
     * Data provider.
64
     *
65
     * @see testNewIniDirectives()
66
     *
67
     * @return array
68
     */
69
    public function dataNewIniDirectives()
70
    {
71
        return array(
72
            array('auto_globals_jit', '5.0', array(83, 84), '4.4', '5.1'),
73
            array('com.code_page', '5.0', array(86, 87), '4.4', '5.1'),
74
            array('date.default_latitude', '5.0', array(89, 90), '4.4', '5.1'),
75
            array('date.default_longitude', '5.0', array(92, 93), '4.4', '5.1'),
76
            array('date.sunrise_zenith', '5.0', array(95, 96), '4.4', '5.1'),
77
            array('date.sunset_zenith', '5.0', array(98, 99), '4.4', '5.1'),
78
            array('ibase.default_charset', '5.0', array(101, 102), '4.4', '5.1'),
79
            array('ibase.default_db', '5.0', array(104, 105), '4.4', '5.1'),
80
            array('mail.force_extra_parameters', '5.0', array(107, 108), '4.4', '5.1'),
81
            array('mime_magic.debug', '5.0', array(110, 111), '4.4', '5.1'),
82
            array('mysqli.max_links', '5.0', array(113, 114), '4.4', '5.1'),
83
            array('mysqli.default_port', '5.0', array(116, 117), '4.4', '5.1'),
84
            array('mysqli.default_socket', '5.0', array(119, 120), '4.4', '5.1'),
85
            array('mysqli.default_host', '5.0', array(122, 123), '4.4', '5.1'),
86
            array('mysqli.default_user', '5.0', array(125, 126), '4.4', '5.1'),
87
            array('mysqli.default_pw', '5.0', array(128, 129), '4.4', '5.1'),
88
            array('report_zend_debug', '5.0', array(131, 132), '4.4', '5.1'),
89
            array('session.hash_bits_per_character', '5.0', array(134, 135), '4.4', '5.1'),
90
            array('session.hash_function', '5.0', array(137, 138), '4.4', '5.1'),
91
            array('soap.wsdl_cache_dir', '5.0', array(140, 141), '4.4', '5.1'),
92
            array('soap.wsdl_cache_enabled', '5.0', array(143, 144), '4.4', '5.1'),
93
            array('soap.wsdl_cache_ttl', '5.0', array(146, 147), '4.4', '5.1'),
94
            array('sqlite.assoc_case', '5.0', array(149, 150), '4.4', '5.1'),
95
            array('tidy.clean_output', '5.0', array(152, 153), '4.4', '5.1'),
96
            array('tidy.default_config', '5.0', array(155, 156), '4.4', '5.1'),
97
            array('zend.ze1_compatibility_mode', '5.0', array(158, 159), '4.4', '5.1'),
98
99
            array('date.timezone', '5.1', array(161, 162), '5.0', '5.2'),
100
            array('detect_unicode', '5.1', array(164, 165), '5.0', '5.2'),
101
            array('realpath_cache_size', '5.1', array(170, 171), '5.0', '5.2'),
102
            array('realpath_cache_ttl', '5.1', array(173, 174), '5.0', '5.2'),
103
104
            array('mbstring.strict_detection', '5.1.2', array(176, 177), '5.1', '5.2'),
105
            array('mssql.charset', '5.1.2', array(179, 180), '5.1', '5.2'),
106
107
            array('gd.jpeg_ignore_warning', '5.1.3', array(182, 183), '5.1', '5.2'),
108
109
            array('fbsql.show_timestamp_decimals', '5.1.5', array(185, 186), '5.1', '5.2'),
110
            array('soap.wsdl_cache', '5.1.5', array(188, 189), '5.1', '5.2'),
111
            array('soap.wsdl_cache_limit', '5.1.5', array(191, 192), '5.1', '5.2'),
112
113
            array('allow_url_include', '5.2', array(7, 8, 9), '5.1', '5.3'),
114
            array('pcre.backtrack_limit', '5.2', array(11, 12), '5.1', '5.3'),
115
            array('pcre.recursion_limit', '5.2', array(14, 15), '5.1', '5.3'),
116
            array('session.cookie_httponly', '5.2', array(17, 18), '5.1', '5.3'),
117
            array('filter.default', '5.2', array(194, 195), '5.1', '5.3'),
118
            array('filter.default_flags', '5.2', array(197, 198), '5.1', '5.3'),
119
120
            array('cgi.check_shebang_line', '5.2.1', array(200, 201), '5.2', '5.3'),
121
122
            array('max_input_nesting_level', '5.2.3', array(20, 21), '5.2', '5.3'),
123
124
            array('mysqli.allow_local_infile', '5.2.4', array(203, 204), '5.2', '5.3'),
125
126
            array('max_file_uploads', '5.2.12', array(206, 207), '5.2', '5.3'),
127
128
            array('user_ini.filename', '5.3', array(23, 24), '5.2', '5.4'),
129
            array('user_ini.cache_ttl', '5.3', array(26, 27), '5.2', '5.4'),
130
            array('exit_on_timeout', '5.3', array(29, 30), '5.2', '5.4'),
131
            array('mbstring.http_output_conv_mimetype', '5.3', array(32, 33), '5.2', '5.4'),
132
            array('request_order', '5.3', array(35, 36), '5.2', '5.4'),
133
            array('cgi.discard_path', '5.3', array(209, 210), '5.2', '5.4'),
134
            array('intl.default_locale', '5.3', array(212, 213), '5.2', '5.4'),
135
            array('intl.error_level', '5.3', array(215, 216), '5.2', '5.4'),
136
            array('mail.add_x_header', '5.3', array(218, 219), '5.2', '5.4'),
137
            array('mail.log', '5.3', array(221, 222), '5.2', '5.4'),
138
            array('mysqli.allow_persistent', '5.3', array(224, 225), '5.2', '5.4'),
139
            array('mysqli.max_persistent', '5.3', array(227, 228), '5.2', '5.4'),
140
            array('mysqli.cache_size', '5.3', array(230, 231), '5.2', '5.4'),
141
            array('mysqlnd.collect_memory_statistics', '5.3', array(233, 234), '5.2', '5.4'),
142
            array('mysqlnd.collect_statistics', '5.3', array(236, 237), '5.2', '5.4'),
143
            array('mysqlnd.debug', '5.3', array(239, 240), '5.2', '5.4'),
144
            array('mysqlnd.net_read_buffer_size', '5.3', array(242, 243), '5.2', '5.4'),
145
            array('odbc.default_cursortype', '5.3', array(245, 246), '5.2', '5.4'),
146
            array('zend.enable_gc', '5.3', array(248, 249), '5.2', '5.4'),
147
148
            array('curl.cainfo', '5.3.7', array(251, 252), '5.3', '5.4'),
149
150
            array('max_input_vars', '5.3.9', array(47, 48), '5.3', '5.4'),
151
152
            array('sqlite3.extension_dir', '5.3.11', array(254, 255), '5.3', '5.4'),
153
154
            array('cli.pager', '5.4', array(38, 39), '5.3', '5.5'),
155
            array('cli.prompt', '5.4', array(41, 42), '5.3', '5.5'),
156
            array('cli_server.color', '5.4', array(44, 45), '5.3', '5.5'),
157
            array('zend.multibyte', '5.4', array(50, 51), '5.3', '5.5'),
158
            array('zend.script_encoding', '5.4', array(53, 54), '5.3', '5.5'),
159
            array('zend.signal_check', '5.4', array(56, 57), '5.3', '5.5'),
160
            array('session.upload_progress.enabled', '5.4', array(59, 60), '5.3', '5.5'),
161
            array('session.upload_progress.cleanup', '5.4', array(62, 63), '5.3', '5.5'),
162
            array('session.upload_progress.name', '5.4', array(65, 66), '5.3', '5.5'),
163
            array('session.upload_progress.freq', '5.4', array(68, 69), '5.3', '5.5'),
164
            array('enable_post_data_reading', '5.4', array(71, 72), '5.3', '5.5'),
165
            array('windows_show_crt_warning', '5.4', array(74, 75), '5.3', '5.5'),
166
            array('session.upload_progress.prefix', '5.4', array(257, 258), '5.3', '5.5'),
167
            array('mysqlnd.log_mask', '5.4', array(263, 264), '5.3', '5.5'),
168
            array('mysqlnd.mempool_default_size', '5.4', array(266, 267), '5.3', '5.5'),
169
            array('mysqlnd.net_cmd_buffer_size', '5.4', array(269, 270), '5.3', '5.5'),
170
            array('mysqlnd.net_read_timeout', '5.4', array(272, 273), '5.3', '5.5'),
171
            array('phar.cache_list', '5.4', array(275, 276), '5.3', '5.5'),
172
173
            array('intl.use_exceptions', '5.5', array(77, 78), '5.4', '5.6'),
174
            array('mysqlnd.sha256_server_public_key', '5.5', array(80, 81), '5.4', '5.6'),
175
            array('mysqlnd.trace_alloc', '5.5', array(278, 279), '5.4', '5.6'),
176
            array('sys_temp_dir', '5.5', array(281, 282), '5.4', '5.6'),
177
            array('xsl.security_prefs', '5.5', array(284, 285), '5.4', '5.6'),
178
179
            array('session.use_strict_mode', '5.5.2', array(287, 288), '5.5', '5.6'),
180
181
            array('mysqli.rollback_on_cached_plink', '5.6', array(290, 291), '5.5', '7.0'),
182
183
            array('assert.exception', '7.0', array(293, 294), '5.6', '7.1'),
184
            array('pcre.jit', '7.0', array(296, 297), '5.6', '7.1'),
185
            array('session.lazy_write', '7.0', array(299, 300), '5.6', '7.1'),
186
            array('zend.assertions', '7.0', array(302, 303), '5.6', '7.1'),
187
188
        );
189
    }
190
191
192
    /**
193
     * testNewIniDirectivesWithAlternative
194
     *
195
     * @dataProvider dataNewIniDirectivesWithAlternative
196
     *
197
     * @param string $iniName        Name of the ini directive.
198
     * @param string $fromVersion    The PHP version in which the ini directive was introduced.
199
     * @param string $alternative    An alternative ini directive.
200
     * @param array  $lines          The line numbers in the test file which apply to this ini directive.
201
     * @param string $warningVersion A PHP version in which the ini directive was not yet present.
202
     * @param string $okVersion      A PHP version in which the ini directive was valid.
203
     *
204
     * @return void
205
     */
206 View Code Duplication
    public function testNewIniDirectivesWithAlternative($iniName, $fromVersion, $alternative, $lines, $warningVersion, $okVersion)
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...
207
    {
208
        $file = $this->sniffFile(self::TEST_FILE, $warningVersion);
209
        foreach($lines as $line) {
210
            $this->assertWarning($file, $line, "INI directive '{$iniName}' is not available before version {$fromVersion}. This directive was previously called '{$alternative}'.");
211
        }
212
213
        $file = $this->sniffFile(self::TEST_FILE, $okVersion);
214
        foreach($lines as $line) {
215
            $this->assertNoViolation($file, $line);
216
        }
217
    }
218
219
    /**
220
     * Data provider.
221
     *
222
     * @see testNewIniDirectivesWithAlternative()
223
     *
224
     * @return array
225
     */
226
    public function dataNewIniDirectivesWithAlternative()
227
    {
228
        return array(
229
            array('fbsql.batchsize', '5.1', 'fbsql.batchSize', array(167, 168), '5.0', '5.2'),
230
            array('zend.detect_unicode', '5.4', 'detect_unicode', array(260, 261), '5.3', '5.5'),
231
        );
232
    }
233
234
}
235