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

testUnserializeOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
cc 1
eloc 5
c 2
b 1
f 1
nc 1
nop 0
dl 0
loc 8
rs 9.4285
1
<?php
2
/**
3
 * New Functions Parameter Sniff test file
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * New Functions Parameter Sniff tests
11
 *
12
 * @uses BaseSniffTest
13
 * @package PHPCompatibility
14
 * @author Wim Godden <[email protected]>
15
 */
16
class NewFunctionParameterSniffTest 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_function_parameter.php';
20
21
    /**
22
     * testInvalidParameter
23
     *
24
     * @dataProvider dataInvalidParameter
25
     *
26
     * @param string $functionName      Function name.
27
     * @param string $parameterName     Parameter name.
28
     * @param string $lastVersionBefore The PHP version just *before* the parameter was introduced.
29
     * @param array  $lines             The line numbers in the test file which apply to this class.
30
     * @param string $okVersion         A PHP version in which the parameter was ok to be used.
31
     *
32
     * @return void
33
     */
34 View Code Duplication
    public function testInvalidParameter($functionName, $parameterName, $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...
35
    {
36
        $file = $this->sniffFile(self::TEST_FILE, $lastVersionBefore);
37
        foreach ($lines as $line) {
38
            $this->assertError($file, $line, "The function {$functionName} does not have a parameter {$parameterName} in PHP version {$lastVersionBefore} or earlier");
39
        }
40
41
        $file = $this->sniffFile(self::TEST_FILE, $okVersion);
42
        foreach ($lines as $line) {
43
            $this->assertNoViolation($file, $line);
44
        }
45
    }
46
47
    /**
48
     * Data provider.
49
     *
50
     * @see testInvalidParameter()
51
     *
52
     * @return array
53
     */
54
    public function dataInvalidParameter()
55
    {
56
        return array(
57
            array('dirname', 'depth', '5.6', array(3, 9), '7.0'),
58
            array('unserialize', 'options', '5.6', array(11), '7.0'),
59
            array('session_start', 'options', '5.6', array(13), '7.0'),
60
            array('strstr', 'before_needle', '5.2', array(15), '5.3'),
61
        );
62
    }
63
64
65
    /**
66
     * testValidParameter
67
     *
68
     * @dataProvider dataValidParameter
69
     *
70
     * @param int $line The line number.
71
     *
72
     * @return void
73
     */
74
    public function testValidParameter($line)
75
    {
76
        $file = $this->sniffFile(self::TEST_FILE);
77
        $this->assertNoViolation($file, $line);
78
    }
79
80
    /**
81
     * Data provider.
82
     *
83
     * @see testValidParameter()
84
     *
85
     * @return array
86
     */
87
    public function dataValidParameter()
88
    {
89
        return array(
90
            array(5),
91
            array(7),
92
        );
93
    }
94
}
95