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

NewClassesSniffTest::dataNewClass()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 42
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 42
rs 8.8571
cc 1
eloc 39
nc 1
nop 0
1
<?php
2
/**
3
 * New Classes Sniff test file
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * New Classes Sniff tests
11
 *
12
 * @uses BaseSniffTest
13
 * @package PHPCompatibility
14
 * @author Jansen Price <[email protected]>
15
 */
16
class NewClassesSniffTest 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_classes.php';
20
21
    /**
22
     * testNewClass
23
     *
24
     * @dataProvider dataNewClass
25
     *
26
     * @param string $className         Class name.
27
     * @param string $lastVersionBefore The PHP version just *before* the class was introduced.
28
     * @param array  $lines             The line numbers in the test file which apply to this class.
29
     * @param string $okVersion         A PHP version in which the class was ok to be used.
30
     *
31
     * @return void
32
     */
33 View Code Duplication
    public function testNewClass($className, $lastVersionBefore, $lines, $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...
34
    {
35
        $file = $this->sniffFile(self::TEST_FILE, $lastVersionBefore);
36
        foreach ($lines as $line) {
37
            $this->assertError($file, $line, "The built-in class {$className} is not present in PHP version {$lastVersionBefore} or earlier");
38
        }
39
40
        $file = $this->sniffFile(self::TEST_FILE, $okVersion);
41
        foreach ($lines as $line) {
42
            $this->assertNoViolation($file, $line);
43
        }
44
    }
45
46
    /**
47
     * Data provider.
48
     *
49
     * @see testNewClass()
50
     *
51
     * @return array
52
     */
53
    public function dataNewClass()
54
    {
55
        return array(
56
            array('DateTime', '5.1', array(3, 43, 45), '5.2'),
57
            array('DateTimeZone', '5.1', array(4, 46), '5.2'),
58
            array('RegexIterator', '5.1', array(5, 47), '5.2'),
59
            array('RecursiveRegexIterator', '5.1', array(6, 48), '5.2'),
60
            array('DateInterval', '5.2', array(7, 49), '5.3'),
61
            array('DatePeriod', '5.2', array(8, 50), '5.3'),
62
            array('Phar', '5.2', array(9, 51), '5.3'),
63
            array('PharData', '5.2', array(10, 52), '5.3'),
64
            array('PharException', '5.2', array(11, 53), '5.3'),
65
            array('PharFileInfo', '5.2', array(12, 54), '5.3'),
66
            array('FilesystemIterator', '5.2', array(13, 55), '5.3'),
67
            array('GlobIterator', '5.2', array(14, 56), '5.3'),
68
            array('MultipleIterator', '5.2', array(15, 57), '5.3'),
69
            array('RecursiveTreeIterator', '5.2', array(16, 58), '5.3'),
70
            array('SplDoublyLinkedList', '5.2', array(17, 59), '5.3'),
71
            array('SplFixedArray', '5.2', array(18, 60), '5.3'),
72
            array('SplHeap', '5.2', array(19, 61), '5.3'),
73
            array('SplMaxHeap', '5.2', array(20, 62), '5.3'),
74
            array('SplMinHeap', '5.2', array(21, 63), '5.3'),
75
            array('SplPriorityQueue', '5.2', array(22, 64), '5.3'),
76
            array('SplQueue', '5.2', array(23, 65), '5.3'),
77
            array('SplStack', '5.2', array(24, 66), '5.3'),
78
            array('CallbackFilterIterator', '5.3', array(25, 67), '5.4'),
79
            array('RecursiveCallbackFilterIterator', '5.3', array(26, 68), '5.4'),
80
            array('ReflectionZendExtension', '5.3', array(27, 69), '5.4'),
81
            array('JsonSerializable', '5.3', array(28), '5.4'),
82
            array('SessionHandler', '5.3', array(29, 71), '5.4'),
83
            array('SNMP', '5.3', array(30, 72), '5.4'),
84
            array('Transliterator', '5.3', array(31, 73), '5.4'),
85
            array('CURLFile', '5.4', array(32, 74), '5.5'),
86
            array('DateTimeImmutable', '5.4', array(33, 75), '5.5'),
87
            array('IntlCalendar', '5.4', array(34, 76), '5.5'),
88
            array('IntlGregorianCalendar', '5.4', array(35, 77), '5.5'),
89
            array('IntlTimeZone', '5.4', array(36, 78), '5.5'),
90
            array('IntlBreakIterator', '5.4', array(37, 79), '5.5'),
91
            array('IntlRuleBasedBreakIterator', '5.4', array(38, 80), '5.5'),
92
            array('IntlCodePointBreakIterator', '5.4', array(39, 81), '5.5'),
93
        );
94
    }
95
96
}
97