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

RemovedExtensionsSniffTest::dataRemovedExtension()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 30
rs 8.8571
cc 1
eloc 27
nc 1
nop 0
1
<?php
2
/**
3
 * Removed extensions sniff test file
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * Removed extensions sniff tests
11
 *
12
 * @uses BaseSniffTest
13
 * @package PHPCompatibility
14
 * @author Jansen Price <[email protected]>
15
 */
16
class RemovedExtensionsSniffTest 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/removed_extensions.php';
20
21
    /**
22
     * Sniffed file
23
     *
24
     * @var PHP_CodeSniffer_File
25
     */
26
    protected $_sniffFile;
27
28
    /**
29
     * setUp
30
     *
31
     * @return void
32
     */
33
    public function setUp()
34
    {
35
        parent::setUp();
36
37
        $this->_sniffFile = $this->sniffFile(self::TEST_FILE);
38
    }
39
40
41
    /**
42
     * testRemovedExtension
43
     *
44
     * @dataProvider dataRemovedExtension
45
     *
46
     * @param string $extensionName  Name of the PHP extension.
47
     * @param string $removedIn      The PHP version in which the extension was removed.
48
     * @param array  $lines          The line numbers in the test file which apply to this extension.
49
     * @param string $okVersion      A PHP version in which the extension was still present.
50
     * @param string $removedVersion Optional PHP version to test removal message with -
51
     *                               if different from the $removedIn version.
52
     *
53
     * @return void
54
     */
55 View Code Duplication
    public function testRemovedExtension($extensionName, $removedIn, $lines, $okVersion, $removedVersion = 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...
56
    {
57
        $file = $this->sniffFile(self::TEST_FILE, $okVersion);
58
        foreach($lines as $line) {
59
            $this->assertNoViolation($file, $line);
60
        }
61
62
        if (isset($removedVersion)){
63
            $file = $this->sniffFile(self::TEST_FILE, $removedVersion);
64
        }
65
        else {
66
            $file = $this->sniffFile(self::TEST_FILE, $removedIn);
67
        }
68
        foreach($lines as $line) {
69
            $this->assertError($file, $line, "Extension '{$extensionName}' is removed since PHP {$removedIn}");
70
        }
71
    }
72
73
    /**
74
     * Data provider.
75
     *
76
     * @see testRemovedExtension()
77
     *
78
     * @return array
79
     */
80
    public function dataRemovedExtension()
81
    {
82
        return array(
83
            array('activescript', '5.3', array(3, 4), '5.2'),
84
            array('cpdf', '5.3', array(6, 7, 8), '5.2'),
85
            array('dbase', '5.3', array(10), '5.2'),
86
            array('dbx', '5.1', array(12), '5.0'),
87
            array('dio', '5.1', array(14), '5.0'),
88
            array('fam', '5.1', array(16), '5.0'),
89
            array('fbsql', '5.3', array(18), '5.2'),
90
            array('fdf', '5.3', array(20), '5.2'),
91
            array('filepro', '5.2', array(22), '5.1'),
92
            array('hw_api', '5.2', array(24), '5.1'),
93
            array('ingres', '5.1', array(26), '5.0'),
94
            array('ircg', '5.3', array(28), '5.2'),
95
            array('mcve', '5.1', array(30), '5.0'),
96
            array('ming', '5.3', array(32), '5.2'),
97
            array('mnogosearch', '5.1', array(34), '5.0'),
98
            array('msql', '5.3', array(36), '5.2'),
99
            array('ncurses', '5.3', array(40), '5.2'),
100
            array('oracle', '5.3', array(42), '5.2'),
101
            array('ovrimos', '5.1', array(44), '5.0'),
102
            array('pfpro', '5.3', array(46), '5.2'),
103
            array('sqlite', '5.4', array(48), '5.3'),
104
            array('sybase', '5.3', array(50), '5.2'),
105
            array('w32api', '5.1', array(52), '5.0'),
106
            array('yp', '5.3', array(54), '5.2'),
107
            array('mssql', '7.0', array(63), '5.6'),
108
        );
109
    }
110
111
112
    /**
113
     * testDeprecatedRemovedExtension
114
     *
115
     * @dataProvider dataDeprecatedRemovedExtension
116
     *
117
     * @param string $extensionName     Name of the PHP extension.
118
     * @param string $deprecatedIn      The PHP version in which the extension was deprecated.
119
     * @param string $removedIn         The PHP version in which the extension was removed.
120
     * @param array  $lines             The line numbers in the test file which apply to this extension.
121
     * @param string $okVersion         A PHP version in which the extension was still present.
122
     * @param string $deprecatedVersion Optional PHP version to test deprecation message with -
123
     *                                  if different from the $deprecatedIn version.
124
     * @param string $removedVersion    Optional PHP version to test removal message with -
125
     *                                  if different from the $removedIn version.
126
     *
127
     * @return void
128
     */
129 View Code Duplication
    public function testDeprecatedRemovedExtension($extensionName, $deprecatedIn, $removedIn, $lines, $okVersion, $deprecatedVersion = null, $removedVersion = 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...
130
    {
131
        $file = $this->sniffFile(self::TEST_FILE, $okVersion);
132
        foreach($lines as $line) {
133
            $this->assertNoViolation($file, $line);
134
        }
135
136
        if (isset($deprecatedVersion)){
137
            $file = $this->sniffFile(self::TEST_FILEE, $deprecatedVersion);
138
        }
139
        else {
140
            $file = $this->sniffFile(self::TEST_FILE, $deprecatedIn);
141
        }
142
        foreach($lines as $line) {
143
            $this->assertWarning($file, $line, "Extension '{$extensionName}' is deprecated since PHP {$deprecatedIn}");
144
        }
145
146
        if (isset($removedVersion)){
147
            $file = $this->sniffFile(self::TEST_FILE, $removedVersion);
148
        }
149
        else {
150
            $file = $this->sniffFile(self::TEST_FILE, $removedIn);
151
        }
152
        foreach($lines as $line) {
153
            $this->assertError($file, $line, "Extension '{$extensionName}' is deprecated since PHP {$deprecatedIn} and removed since PHP {$removedIn}");
154
        }
155
    }
156
157
    /**
158
     * Data provider.
159
     *
160
     * @see testDeprecatedRemovedExtension()
161
     *
162
     * @return array
163
     */
164
    public function dataDeprecatedRemovedExtension()
165
    {
166
        return array(
167
            array('ereg', '5.3', '7.0', array(65), '5.2'),
168
            array('mysql_', '5.5', '7.0', array(38), '5.4'),
169
        );
170
    }
171
172
173
    /**
174
     * testNotAFunctionCall
175
     *
176
     * @return void
177
     */
178
    public function testNotAFunctionCall()
179
    {
180
        $this->assertNoViolation($this->_sniffFile, 57);
181
    }
182
183
    /**
184
     * testFunctionDeclaration
185
     *
186
     * @return void
187
     */
188
    public function testFunctionDeclaration()
189
    {
190
        $this->assertNoViolation($this->_sniffFile, 58);
191
    }
192
193
    /**
194
     * testNewClass
195
     *
196
     * @return void
197
     */
198
    public function testNewClass()
199
    {
200
        $this->assertNoViolation($this->_sniffFile, 59);
201
    }
202
203
    /**
204
     * testMethod
205
     *
206
     * @return void
207
     */
208
    public function testMethod()
209
    {
210
        $this->assertNoViolation($this->_sniffFile, 60);
211
    }
212
213
    /**
214
     * testWhiteListing
215
     *
216
     * @return void
217
     */
218
    public function testWhiteListing()
219
    {
220
        $this->assertNoViolation($this->_sniffFile, 68);
221
    }
222
}
223